aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/address.py
diff options
context:
space:
mode:
authorW. J. van der Laan <laanwj@protonmail.com>2021-11-10 11:49:33 +0100
committerW. J. van der Laan <laanwj@protonmail.com>2021-11-10 11:55:54 +0100
commit2539980e1d74a637be5bcadb566263f903adffd1 (patch)
tree971daabed42fbc3d2d76c826e17e943ee3b1b943 /test/functional/test_framework/address.py
parent8ae4ba481ce8f7da173bef24432729c87a36cb70 (diff)
parent041abfebe49ae5e3e882c00cc5caea1365a27a49 (diff)
downloadbitcoin-2539980e1d74a637be5bcadb566263f903adffd1.tar.xz
Merge bitcoin/bitcoin#23371: test: MiniWallet: add P2TR support and use it per default
041abfebe49ae5e3e882c00cc5caea1365a27a49 test: MiniWallet: add P2TR support and use it per default (Sebastian Falbesoner) 4a2edf2bf708b6044562995e35f2dbbd2b26c364 test: generate blocks to MiniWallet address in rpc_blockchain.py (Sebastian Falbesoner) Pull request description: Taproot activates in [about 19 days](https://taproot.watch/) (2716 blocks), and it'd be nice if we set a good example and also support it in our MiniWallet. This PR changes the default mode from P2WSH (segwit v0 output, bech32 address) to P2TR (segwit v1 output, bech32m address) transactions type with the _anyone-can-spend_ policy, i.e. a witness script of `OP_TRUE`. The transition is actually quite painless, one only needs one extra piece in the form of a internal public key that is passed in the control block on the witness stack, in order to trigger script-path spending. To keep things simple, the lowest possible valid x-only-public key with the value of 1 was chosen as internal key. Since many tests expect to find outputs for the default scriptPubKey of MiniWallet in the pre-mined chain of the test framework, the generation address is also changed from `ADDRESS_BCRT1_P2WSH_OP_TRUE` to `create_deterministic_address_bcrt1_p2tr_op_true()[0]` accordingly (see method `BitcoinTestFramework._initialize_chain(...)`). Note that the pre-mined chain is cached locally, so you probably have to delete the `./test/cache` folder first for the tests to pass again. In order to avoid unnecessary renames, the import of `ADDRESS_BCRT1_P2WSH_OP_TRUE` is eliminated in rpc_blockchain.py by generating blocks directly to the MiniWallet address by using the `self.generate(self.wallet, ...)` interface (see first commit). ACKs for top commit: laanwj: Code review ACK 041abfebe49ae5e3e882c00cc5caea1365a27a49 Tree-SHA512: 876a5b0595333f9c96c68d5ecf2b4530aee2715aebb75a953f4f75ca12258bd7239210fcfa1ae044bee91489804c9c2f2a6a335bd46c3ac701873d32e3a4f49d
Diffstat (limited to 'test/functional/test_framework/address.py')
-rw-r--r--test/functional/test_framework/address.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py
index fe733e9368..89839c9bab 100644
--- a/test/functional/test_framework/address.py
+++ b/test/functional/test_framework/address.py
@@ -5,12 +5,21 @@
"""Encode and decode Bitcoin addresses.
- base58 P2PKH and P2SH addresses.
-- bech32 segwit v0 P2WPKH and P2WSH addresses."""
+- bech32 segwit v0 P2WPKH and P2WSH addresses.
+- bech32m segwit v1 P2TR addresses."""
import enum
import unittest
-from .script import hash256, hash160, sha256, CScript, OP_0
+from .script import (
+ CScript,
+ OP_0,
+ OP_TRUE,
+ hash160,
+ hash256,
+ sha256,
+ taproot_construct,
+)
from .segwit_addr import encode_segwit_address
from .util import assert_equal
@@ -29,6 +38,21 @@ class AddressType(enum.Enum):
chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
+def create_deterministic_address_bcrt1_p2tr_op_true():
+ """
+ Generates a deterministic bech32m address (segwit v1 output) that
+ can be spent with a witness stack of OP_TRUE and the control block
+ with internal public key (script-path spending).
+
+ Returns a tuple with the generated address and the internal key.
+ """
+ internal_key = (1).to_bytes(32, 'big')
+ scriptPubKey = taproot_construct(internal_key, [(None, CScript([OP_TRUE]))]).scriptPubKey
+ address = encode_segwit_address("bcrt", 1, scriptPubKey[2:])
+ assert_equal(address, 'bcrt1p9yfmy5h72durp7zrhlw9lf7jpwjgvwdg0jr0lqmmjtgg83266lqsekaqka')
+ return (address, internal_key)
+
+
def byte_to_base58(b, version):
result = ''
str = b.hex()