Skip to content

Commit 7774c31

Browse files
committed
test: refactor: return TaprootInfo from P2TR address creation routine
Rather than only returning the internal key from the P2TR anyone-can-spend address creation routine, provide the whole TaprootInfo object, which in turn contains a dictionary of TaprootLeafInfo object for named leaves. This data is used in MiniWallet for the default ADDRESS_OP_TRUE mode, in order to deduplicate the witness script and leaf version of the control block.
1 parent e6e4c18 commit 7774c31

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

test/functional/test_framework/address.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ def create_deterministic_address_bcrt1_p2tr_op_true(explicit_internal_key=None):
5353
can be spent with a witness stack of OP_TRUE and the control block
5454
with internal public key (script-path spending).
5555
56-
Returns a tuple with the generated address and the internal key.
56+
Returns a tuple with the generated address and the TaprootInfo object.
5757
"""
5858
internal_key = explicit_internal_key or (1).to_bytes(32, 'big')
59-
address = output_key_to_p2tr(taproot_construct(internal_key, [(None, CScript([OP_TRUE]))]).output_pubkey)
59+
taproot_info = taproot_construct(internal_key, [("only-path", CScript([OP_TRUE]))])
60+
address = output_key_to_p2tr(taproot_info.output_pubkey)
6061
if explicit_internal_key is None:
6162
assert_equal(address, 'bcrt1p9yfmy5h72durp7zrhlw9lf7jpwjgvwdg0jr0lqmmjtgg83266lqsekaqka')
62-
return (address, internal_key)
63+
return (address, taproot_info)
6364

6465

6566
def byte_to_base58(b, version):

test/functional/test_framework/wallet.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
)
4040
from test_framework.script import (
4141
CScript,
42-
LEAF_VERSION_TAPSCRIPT,
4342
OP_1,
4443
OP_NOP,
4544
OP_RETURN,
@@ -107,7 +106,7 @@ def __init__(self, test_node, *, mode=MiniWalletMode.ADDRESS_OP_TRUE, tag_name=N
107106
self._scriptPubKey = key_to_p2pk_script(pub_key.get_bytes())
108107
elif mode == MiniWalletMode.ADDRESS_OP_TRUE:
109108
internal_key = None if tag_name is None else hash256(tag_name.encode())
110-
self._address, self._internal_key = create_deterministic_address_bcrt1_p2tr_op_true(internal_key)
109+
self._address, self._taproot_info = create_deterministic_address_bcrt1_p2tr_op_true(internal_key)
111110
self._scriptPubKey = address_to_scriptpubkey(self._address)
112111

113112
# When the pre-mined test framework chain is used, it contains coinbase
@@ -195,7 +194,12 @@ def sign_tx(self, tx, fixed_length=True):
195194
elif self._mode == MiniWalletMode.ADDRESS_OP_TRUE:
196195
tx.wit.vtxinwit = [CTxInWitness()] * len(tx.vin)
197196
for i in tx.wit.vtxinwit:
198-
i.scriptWitness.stack = [CScript([OP_TRUE]), bytes([LEAF_VERSION_TAPSCRIPT]) + self._internal_key]
197+
assert_equal(len(self._taproot_info.leaves), 1)
198+
leaf_info = list(self._taproot_info.leaves.values())[0]
199+
i.scriptWitness.stack = [
200+
leaf_info.script,
201+
bytes([leaf_info.version]) + self._taproot_info.internal_pubkey,
202+
]
199203
else:
200204
assert False
201205

0 commit comments

Comments
 (0)