mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-15 06:11:09 +02:00
tests: Test that PSBT_OUT_TAP_TREE is combined correctly
This commit is contained in:
parent
7df6e1bb77
commit
22c051ca70
@ -27,6 +27,7 @@ from test_framework.psbt import (
|
|||||||
PSBT_IN_SHA256,
|
PSBT_IN_SHA256,
|
||||||
PSBT_IN_HASH160,
|
PSBT_IN_HASH160,
|
||||||
PSBT_IN_HASH256,
|
PSBT_IN_HASH256,
|
||||||
|
PSBT_OUT_TAP_TREE,
|
||||||
)
|
)
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
@ -779,9 +780,18 @@ class PSBTTest(BitcoinTestFramework):
|
|||||||
self.generate(self.nodes[0], 1)
|
self.generate(self.nodes[0], 1)
|
||||||
self.nodes[0].importdescriptors([{"desc": descsum_create("tr({})".format(privkey)), "timestamp":"now"}])
|
self.nodes[0].importdescriptors([{"desc": descsum_create("tr({})".format(privkey)), "timestamp":"now"}])
|
||||||
|
|
||||||
psbt = watchonly.sendall([wallet.getnewaddress()])["psbt"]
|
psbt = watchonly.sendall([wallet.getnewaddress(), addr])["psbt"]
|
||||||
psbt = self.nodes[0].walletprocesspsbt(psbt)["psbt"]
|
psbt = self.nodes[0].walletprocesspsbt(psbt)["psbt"]
|
||||||
self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"])
|
txid = self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"])
|
||||||
|
vout = find_vout_for_address(self.nodes[0], txid, addr)
|
||||||
|
|
||||||
|
# Make sure tap tree is in psbt
|
||||||
|
parsed_psbt = PSBT.from_base64(psbt)
|
||||||
|
assert_greater_than(len(parsed_psbt.o[vout].map[PSBT_OUT_TAP_TREE]), 0)
|
||||||
|
assert "taproot_tree" in self.nodes[0].decodepsbt(psbt)["outputs"][vout]
|
||||||
|
parsed_psbt.make_blank()
|
||||||
|
comb_psbt = self.nodes[0].combinepsbt([psbt, parsed_psbt.to_base64()])
|
||||||
|
assert_equal(comb_psbt, psbt)
|
||||||
|
|
||||||
self.log.info("Test that walletprocesspsbt both updates and signs a non-updated psbt containing Taproot inputs")
|
self.log.info("Test that walletprocesspsbt both updates and signs a non-updated psbt containing Taproot inputs")
|
||||||
addr = self.nodes[0].getnewaddress("", "bech32m")
|
addr = self.nodes[0].getnewaddress("", "bech32m")
|
||||||
@ -793,6 +803,14 @@ class PSBTTest(BitcoinTestFramework):
|
|||||||
self.nodes[0].sendrawtransaction(rawtx)
|
self.nodes[0].sendrawtransaction(rawtx)
|
||||||
self.generate(self.nodes[0], 1)
|
self.generate(self.nodes[0], 1)
|
||||||
|
|
||||||
|
# Make sure tap tree is not in psbt
|
||||||
|
parsed_psbt = PSBT.from_base64(psbt)
|
||||||
|
assert PSBT_OUT_TAP_TREE not in parsed_psbt.o[0].map
|
||||||
|
assert "taproot_tree" not in self.nodes[0].decodepsbt(psbt)["outputs"][0]
|
||||||
|
parsed_psbt.make_blank()
|
||||||
|
comb_psbt = self.nodes[0].combinepsbt([psbt, parsed_psbt.to_base64()])
|
||||||
|
assert_equal(comb_psbt, psbt)
|
||||||
|
|
||||||
self.log.info("Test decoding PSBT with per-input preimage types")
|
self.log.info("Test decoding PSBT with per-input preimage types")
|
||||||
# note that the decodepsbt RPC doesn't check whether preimages and hashes match
|
# note that the decodepsbt RPC doesn't check whether preimages and hashes match
|
||||||
hash_ripemd160, preimage_ripemd160 = random_bytes(20), random_bytes(50)
|
hash_ripemd160, preimage_ripemd160 = random_bytes(20), random_bytes(50)
|
||||||
|
@ -123,6 +123,15 @@ class PSBT:
|
|||||||
psbt = [x.serialize() for x in [self.g] + self.i + self.o]
|
psbt = [x.serialize() for x in [self.g] + self.i + self.o]
|
||||||
return b"psbt\xff" + b"".join(psbt)
|
return b"psbt\xff" + b"".join(psbt)
|
||||||
|
|
||||||
|
def make_blank(self):
|
||||||
|
"""
|
||||||
|
Remove all fields except for PSBT_GLOBAL_UNSIGNED_TX
|
||||||
|
"""
|
||||||
|
for m in self.i + self.o:
|
||||||
|
m.map.clear()
|
||||||
|
|
||||||
|
self.g = PSBTMap(map={0: self.g.map[0]})
|
||||||
|
|
||||||
def to_base64(self):
|
def to_base64(self):
|
||||||
return base64.b64encode(self.serialize()).decode("utf8")
|
return base64.b64encode(self.serialize()).decode("utf8")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user