aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-06-07 01:47:54 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-06-14 13:37:18 +0200
commitdcf36fe8e3e1fc1e865072232281b72889586e40 (patch)
treec21978b1a3c9caaaa623560ec4ae18f05b8d78df /test
parent1999dcfa40ddedb6cf15f9d66b90fa0f537b4842 (diff)
downloadbitcoin-dcf36fe8e3e1fc1e865072232281b72889586e40.tar.xz
test: implement 'bech32m' mode for `getnewdestination()` helper
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/rpc_createmultisig.py6
-rw-r--r--test/functional/test_framework/wallet.py17
2 files changed, 15 insertions, 8 deletions
diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py
index 716ee8f7ef..1ad3fc24c9 100755
--- a/test/functional/rpc_createmultisig.py
+++ b/test/functional/rpc_createmultisig.py
@@ -43,7 +43,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
if self.is_bdb_compiled():
self.final = node2.getnewaddress()
else:
- self.final = getnewdestination()[2]
+ self.final = getnewdestination('bech32')[2]
def run_test(self):
node0, node1, node2 = self.nodes
@@ -66,9 +66,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
# Test mixed compressed and uncompressed pubkeys
self.log.info('Mixed compressed and uncompressed multisigs are not allowed')
- pk0 = getnewdestination()[0].hex()
- pk1 = getnewdestination()[0].hex()
- pk2 = getnewdestination()[0].hex()
+ pk0, pk1, pk2 = [getnewdestination('bech32')[0].hex() for _ in range(3)]
# decompress pk2
pk_obj = ECPubKey()
diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py
index 93f3ea9e81..e192c3b3e9 100644
--- a/test/functional/test_framework/wallet.py
+++ b/test/functional/test_framework/wallet.py
@@ -19,9 +19,13 @@ from test_framework.address import (
key_to_p2pkh,
key_to_p2sh_p2wpkh,
key_to_p2wpkh,
+ output_key_to_p2tr,
)
from test_framework.descriptors import descsum_create
-from test_framework.key import ECKey
+from test_framework.key import (
+ ECKey,
+ compute_xonly_pubkey,
+)
from test_framework.messages import (
COIN,
COutPoint,
@@ -38,6 +42,7 @@ from test_framework.script import (
OP_NOP,
OP_TRUE,
SIGHASH_ALL,
+ taproot_construct,
)
from test_framework.script_util import (
key_to_p2pk_script,
@@ -286,10 +291,10 @@ class MiniWallet:
return txid
-def getnewdestination(address_type='bech32'):
+def getnewdestination(address_type='bech32m'):
"""Generate a random destination of the specified type and return the
corresponding public key, scriptPubKey and address. Supported types are
- 'legacy', 'p2sh-segwit' and 'bech32'. Can be used when a random
+ 'legacy', 'p2sh-segwit', 'bech32' and 'bech32m'. Can be used when a random
destination is needed, but no compiled wallet is available (e.g. as
replacement to the getnewaddress/getaddressinfo RPCs)."""
key = ECKey()
@@ -304,7 +309,11 @@ def getnewdestination(address_type='bech32'):
elif address_type == 'bech32':
scriptpubkey = key_to_p2wpkh_script(pubkey)
address = key_to_p2wpkh(pubkey)
- # TODO: also support bech32m (need to generate x-only-pubkey)
+ elif address_type == 'bech32m':
+ tap = taproot_construct(compute_xonly_pubkey(key.get_bytes())[0])
+ pubkey = tap.output_pubkey
+ scriptpubkey = tap.scriptPubKey
+ address = output_key_to_p2tr(pubkey)
else:
assert False
return pubkey, scriptpubkey, address