4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Test the Partially Signed Transaction RPCs.
6
6
"""
7
-
8
7
from decimal import Decimal
9
8
from itertools import product
10
9
27
26
PSBT_IN_SHA256 ,
28
27
PSBT_IN_HASH160 ,
29
28
PSBT_IN_HASH256 ,
29
+ PSBT_IN_NON_WITNESS_UTXO ,
30
30
PSBT_IN_WITNESS_UTXO ,
31
31
PSBT_OUT_TAP_TREE ,
32
32
)
@@ -67,8 +67,8 @@ def set_test_params(self):
67
67
def skip_test_if_missing_module (self ):
68
68
self .skip_if_no_wallet ()
69
69
70
- # TODO: Re-enable this test with segwit v1
71
70
def test_utxo_conversion (self ):
71
+ self .log .info ("Check that non-witness UTXOs are removed for segwit v1+ inputs" )
72
72
mining_node = self .nodes [2 ]
73
73
offline_node = self .nodes [0 ]
74
74
online_node = self .nodes [1 ]
@@ -80,34 +80,41 @@ def test_utxo_conversion(self):
80
80
# Create watchonly on online_node
81
81
online_node .createwallet (wallet_name = 'wonline' , disable_private_keys = True )
82
82
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 )
84
84
85
85
# 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 " )
88
88
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 ]))
91
92
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
93
94
utxos = wonline .listunspent (addresses = [offline_addr ])
94
95
raw = wonline .createrawtransaction ([{"txid" :utxos [0 ]["txid" ], "vout" :utxos [0 ]["vout" ]}],[{online_addr :0.9999 }])
95
96
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 ]
97
104
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 ]
101
108
102
109
# Make sure we can mine the resulting transaction
103
110
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 ]) )
105
112
assert_equal (online_node .gettxout (txid ,0 )["confirmations" ], 1 )
106
113
107
114
wonline .unloadwallet ()
108
115
109
116
# Reconnect
110
- self .connect_nodes (0 , 1 )
117
+ self .connect_nodes (1 , 0 )
111
118
self .connect_nodes (0 , 2 )
112
119
113
120
def test_input_confs_control (self ):
@@ -574,8 +581,8 @@ def run_test(self):
574
581
for i , signer in enumerate (signers ):
575
582
self .nodes [2 ].unloadwallet ("wallet{}" .format (i ))
576
583
577
- # TODO: Re-enable this for segwit v1
578
- # self.test_utxo_conversion()
584
+ if self . options . descriptors :
585
+ self .test_utxo_conversion ()
579
586
580
587
self .test_input_confs_control ()
581
588
0 commit comments