Skip to content

Commit 22c051c

Browse files
committed
tests: Test that PSBT_OUT_TAP_TREE is combined correctly
1 parent 7df6e1b commit 22c051c

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

test/functional/rpc_psbt.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
PSBT_IN_SHA256,
2828
PSBT_IN_HASH160,
2929
PSBT_IN_HASH256,
30+
PSBT_OUT_TAP_TREE,
3031
)
3132
from test_framework.test_framework import BitcoinTestFramework
3233
from test_framework.util import (
@@ -779,9 +780,18 @@ def test_psbt_input_keys(psbt_input, keys):
779780
self.generate(self.nodes[0], 1)
780781
self.nodes[0].importdescriptors([{"desc": descsum_create("tr({})".format(privkey)), "timestamp":"now"}])
781782

782-
psbt = watchonly.sendall([wallet.getnewaddress()])["psbt"]
783+
psbt = watchonly.sendall([wallet.getnewaddress(), addr])["psbt"]
783784
psbt = self.nodes[0].walletprocesspsbt(psbt)["psbt"]
784-
self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"])
785+
txid = self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"])
786+
vout = find_vout_for_address(self.nodes[0], txid, addr)
787+
788+
# Make sure tap tree is in psbt
789+
parsed_psbt = PSBT.from_base64(psbt)
790+
assert_greater_than(len(parsed_psbt.o[vout].map[PSBT_OUT_TAP_TREE]), 0)
791+
assert "taproot_tree" in self.nodes[0].decodepsbt(psbt)["outputs"][vout]
792+
parsed_psbt.make_blank()
793+
comb_psbt = self.nodes[0].combinepsbt([psbt, parsed_psbt.to_base64()])
794+
assert_equal(comb_psbt, psbt)
785795

786796
self.log.info("Test that walletprocesspsbt both updates and signs a non-updated psbt containing Taproot inputs")
787797
addr = self.nodes[0].getnewaddress("", "bech32m")
@@ -793,6 +803,14 @@ def test_psbt_input_keys(psbt_input, keys):
793803
self.nodes[0].sendrawtransaction(rawtx)
794804
self.generate(self.nodes[0], 1)
795805

806+
# Make sure tap tree is not in psbt
807+
parsed_psbt = PSBT.from_base64(psbt)
808+
assert PSBT_OUT_TAP_TREE not in parsed_psbt.o[0].map
809+
assert "taproot_tree" not in self.nodes[0].decodepsbt(psbt)["outputs"][0]
810+
parsed_psbt.make_blank()
811+
comb_psbt = self.nodes[0].combinepsbt([psbt, parsed_psbt.to_base64()])
812+
assert_equal(comb_psbt, psbt)
813+
796814
self.log.info("Test decoding PSBT with per-input preimage types")
797815
# note that the decodepsbt RPC doesn't check whether preimages and hashes match
798816
hash_ripemd160, preimage_ripemd160 = random_bytes(20), random_bytes(50)

test/functional/test_framework/psbt.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ def serialize(self):
123123
psbt = [x.serialize() for x in [self.g] + self.i + self.o]
124124
return b"psbt\xff" + b"".join(psbt)
125125

126+
def make_blank(self):
127+
"""
128+
Remove all fields except for PSBT_GLOBAL_UNSIGNED_TX
129+
"""
130+
for m in self.i + self.o:
131+
m.map.clear()
132+
133+
self.g = PSBTMap(map={0: self.g.map[0]})
134+
126135
def to_base64(self):
127136
return base64.b64encode(self.serialize()).decode("utf8")
128137

0 commit comments

Comments
 (0)