Skip to content

Commit dcf36fe

Browse files
committed
test: implement 'bech32m' mode for getnewdestination() helper
1 parent 1999dcf commit dcf36fe

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

test/functional/rpc_createmultisig.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_keys(self):
4343
if self.is_bdb_compiled():
4444
self.final = node2.getnewaddress()
4545
else:
46-
self.final = getnewdestination()[2]
46+
self.final = getnewdestination('bech32')[2]
4747

4848
def run_test(self):
4949
node0, node1, node2 = self.nodes
@@ -66,9 +66,7 @@ def run_test(self):
6666

6767
# Test mixed compressed and uncompressed pubkeys
6868
self.log.info('Mixed compressed and uncompressed multisigs are not allowed')
69-
pk0 = getnewdestination()[0].hex()
70-
pk1 = getnewdestination()[0].hex()
71-
pk2 = getnewdestination()[0].hex()
69+
pk0, pk1, pk2 = [getnewdestination('bech32')[0].hex() for _ in range(3)]
7270

7371
# decompress pk2
7472
pk_obj = ECPubKey()

test/functional/test_framework/wallet.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
key_to_p2pkh,
2020
key_to_p2sh_p2wpkh,
2121
key_to_p2wpkh,
22+
output_key_to_p2tr,
2223
)
2324
from test_framework.descriptors import descsum_create
24-
from test_framework.key import ECKey
25+
from test_framework.key import (
26+
ECKey,
27+
compute_xonly_pubkey,
28+
)
2529
from test_framework.messages import (
2630
COIN,
2731
COutPoint,
@@ -38,6 +42,7 @@
3842
OP_NOP,
3943
OP_TRUE,
4044
SIGHASH_ALL,
45+
taproot_construct,
4146
)
4247
from test_framework.script_util import (
4348
key_to_p2pk_script,
@@ -286,10 +291,10 @@ def sendrawtransaction(self, *, from_node, tx_hex, maxfeerate=0, **kwargs):
286291
return txid
287292

288293

289-
def getnewdestination(address_type='bech32'):
294+
def getnewdestination(address_type='bech32m'):
290295
"""Generate a random destination of the specified type and return the
291296
corresponding public key, scriptPubKey and address. Supported types are
292-
'legacy', 'p2sh-segwit' and 'bech32'. Can be used when a random
297+
'legacy', 'p2sh-segwit', 'bech32' and 'bech32m'. Can be used when a random
293298
destination is needed, but no compiled wallet is available (e.g. as
294299
replacement to the getnewaddress/getaddressinfo RPCs)."""
295300
key = ECKey()
@@ -304,7 +309,11 @@ def getnewdestination(address_type='bech32'):
304309
elif address_type == 'bech32':
305310
scriptpubkey = key_to_p2wpkh_script(pubkey)
306311
address = key_to_p2wpkh(pubkey)
307-
# TODO: also support bech32m (need to generate x-only-pubkey)
312+
elif address_type == 'bech32m':
313+
tap = taproot_construct(compute_xonly_pubkey(key.get_bytes())[0])
314+
pubkey = tap.output_pubkey
315+
scriptpubkey = tap.scriptPubKey
316+
address = output_key_to_p2tr(pubkey)
308317
else:
309318
assert False
310319
return pubkey, scriptpubkey, address

0 commit comments

Comments
 (0)