Skip to content

Commit 3dd2f64

Browse files
committed
test: psbt: check non-witness UTXO removal for segwit v1 input
1 parent dd78e3f commit 3dd2f64

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

test/functional/rpc_psbt.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the Partially Signed Transaction RPCs.
66
"""
7-
87
from decimal import Decimal
98
from itertools import product
109

@@ -27,6 +26,7 @@
2726
PSBT_IN_SHA256,
2827
PSBT_IN_HASH160,
2928
PSBT_IN_HASH256,
29+
PSBT_IN_NON_WITNESS_UTXO,
3030
PSBT_IN_WITNESS_UTXO,
3131
PSBT_OUT_TAP_TREE,
3232
)
@@ -67,8 +67,8 @@ def set_test_params(self):
6767
def skip_test_if_missing_module(self):
6868
self.skip_if_no_wallet()
6969

70-
# TODO: Re-enable this test with segwit v1
7170
def test_utxo_conversion(self):
71+
self.log.info("Check that non-witness UTXOs are removed for segwit v1+ inputs")
7272
mining_node = self.nodes[2]
7373
offline_node = self.nodes[0]
7474
online_node = self.nodes[1]
@@ -80,34 +80,41 @@ def test_utxo_conversion(self):
8080
# Create watchonly on online_node
8181
online_node.createwallet(wallet_name='wonline', disable_private_keys=True)
8282
wonline = online_node.get_wallet_rpc('wonline')
83-
w2 = online_node.get_wallet_rpc('')
83+
w2 = online_node.get_wallet_rpc(self.default_wallet_name)
8484

8585
# Mine a transaction that credits the offline address
86-
offline_addr = offline_node.getnewaddress(address_type="p2sh-segwit")
87-
online_addr = w2.getnewaddress(address_type="p2sh-segwit")
86+
offline_addr = offline_node.getnewaddress(address_type="bech32m")
87+
online_addr = w2.getnewaddress(address_type="bech32m")
8888
wonline.importaddress(offline_addr, "", False)
89-
mining_node.sendtoaddress(address=offline_addr, amount=1.0)
90-
self.generate(mining_node, nblocks=1)
89+
mining_wallet = mining_node.get_wallet_rpc(self.default_wallet_name)
90+
mining_wallet.sendtoaddress(address=offline_addr, amount=1.0)
91+
self.generate(mining_node, nblocks=1, sync_fun=lambda: self.sync_all([online_node, mining_node]))
9192

92-
# Construct an unsigned PSBT on the online node (who doesn't know the output is Segwit, so will include a non-witness UTXO)
93+
# Construct an unsigned PSBT on the online node
9394
utxos = wonline.listunspent(addresses=[offline_addr])
9495
raw = wonline.createrawtransaction([{"txid":utxos[0]["txid"], "vout":utxos[0]["vout"]}],[{online_addr:0.9999}])
9596
psbt = wonline.walletprocesspsbt(online_node.converttopsbt(raw))["psbt"]
96-
assert "non_witness_utxo" in mining_node.decodepsbt(psbt)["inputs"][0]
97+
assert not "not_witness_utxo" in mining_node.decodepsbt(psbt)["inputs"][0]
98+
99+
# add non-witness UTXO manually
100+
psbt_new = PSBT.from_base64(psbt)
101+
prev_tx = wonline.gettransaction(utxos[0]["txid"])["hex"]
102+
psbt_new.i[0].map[PSBT_IN_NON_WITNESS_UTXO] = bytes.fromhex(prev_tx)
103+
assert "non_witness_utxo" in mining_node.decodepsbt(psbt_new.to_base64())["inputs"][0]
97104

98-
# Have the offline node sign the PSBT (which will update the UTXO to segwit)
99-
signed_psbt = offline_node.walletprocesspsbt(psbt)["psbt"]
100-
assert "witness_utxo" in mining_node.decodepsbt(signed_psbt)["inputs"][0]
105+
# Have the offline node sign the PSBT (which will remove the non-witness UTXO)
106+
signed_psbt = offline_node.walletprocesspsbt(psbt_new.to_base64())["psbt"]
107+
assert not "non_witness_utxo" in mining_node.decodepsbt(signed_psbt)["inputs"][0]
101108

102109
# Make sure we can mine the resulting transaction
103110
txid = mining_node.sendrawtransaction(mining_node.finalizepsbt(signed_psbt)["hex"])
104-
self.generate(mining_node, 1)
111+
self.generate(mining_node, nblocks=1, sync_fun=lambda: self.sync_all([online_node, mining_node]))
105112
assert_equal(online_node.gettxout(txid,0)["confirmations"], 1)
106113

107114
wonline.unloadwallet()
108115

109116
# Reconnect
110-
self.connect_nodes(0, 1)
117+
self.connect_nodes(1, 0)
111118
self.connect_nodes(0, 2)
112119

113120
def test_input_confs_control(self):
@@ -574,8 +581,8 @@ def run_test(self):
574581
for i, signer in enumerate(signers):
575582
self.nodes[2].unloadwallet("wallet{}".format(i))
576583

577-
# TODO: Re-enable this for segwit v1
578-
# self.test_utxo_conversion()
584+
if self.options.descriptors:
585+
self.test_utxo_conversion()
579586

580587
self.test_input_confs_control()
581588

0 commit comments

Comments
 (0)