6
6
"""
7
7
8
8
from test_framework .test_framework import BitcoinTestFramework
9
- from test_framework .util import assert_equal , assert_raises_rpc_error , find_output
9
+ from test_framework .util import assert_equal , assert_raises_rpc_error , find_output , disconnect_nodes , connect_nodes_bi , sync_blocks
10
10
11
11
import json
12
12
import os
@@ -23,6 +23,45 @@ def set_test_params(self):
23
23
def skip_test_if_missing_module (self ):
24
24
self .skip_if_no_wallet ()
25
25
26
+ def test_utxo_conversion (self ):
27
+ mining_node = self .nodes [2 ]
28
+ offline_node = self .nodes [0 ]
29
+ online_node = self .nodes [1 ]
30
+
31
+ # Disconnect offline node from others
32
+ disconnect_nodes (offline_node , 1 )
33
+ disconnect_nodes (online_node , 0 )
34
+ disconnect_nodes (offline_node , 2 )
35
+ disconnect_nodes (mining_node , 0 )
36
+
37
+ # Mine a transaction that credits the offline address
38
+ offline_addr = offline_node .getnewaddress (address_type = "p2sh-segwit" )
39
+ online_addr = online_node .getnewaddress (address_type = "p2sh-segwit" )
40
+ online_node .importaddress (offline_addr , "" , False )
41
+ mining_node .sendtoaddress (address = offline_addr , amount = 1.0 )
42
+ mining_node .generate (nblocks = 1 )
43
+ sync_blocks ([mining_node , online_node ])
44
+
45
+ # Construct an unsigned PSBT on the online node (who doesn't know the output is Segwit, so will include a non-witness UTXO)
46
+ utxos = online_node .listunspent (addresses = [offline_addr ])
47
+ raw = online_node .createrawtransaction ([{"txid" :utxos [0 ]["txid" ], "vout" :utxos [0 ]["vout" ]}],[{online_addr :0.9999 }])
48
+ psbt = online_node .walletprocesspsbt (online_node .converttopsbt (raw ))["psbt" ]
49
+ assert ("non_witness_utxo" in mining_node .decodepsbt (psbt )["inputs" ][0 ])
50
+
51
+ # Have the offline node sign the PSBT (which will update the UTXO to segwit)
52
+ signed_psbt = offline_node .walletprocesspsbt (psbt )["psbt" ]
53
+ assert ("witness_utxo" in mining_node .decodepsbt (signed_psbt )["inputs" ][0 ])
54
+
55
+ # Make sure we can mine the resulting transaction
56
+ txid = mining_node .sendrawtransaction (mining_node .finalizepsbt (signed_psbt )["hex" ])
57
+ mining_node .generate (1 )
58
+ sync_blocks ([mining_node , online_node ])
59
+ assert_equal (online_node .gettxout (txid ,0 )["confirmations" ], 1 )
60
+
61
+ # Reconnect
62
+ connect_nodes_bi (self .nodes , 0 , 1 )
63
+ connect_nodes_bi (self .nodes , 0 , 2 )
64
+
26
65
def run_test (self ):
27
66
# Create and fund a raw tx for sending 10 BTC
28
67
psbtx1 = self .nodes [0 ].walletcreatefundedpsbt ([], {self .nodes [2 ].getnewaddress ():10 })['psbt' ]
@@ -224,6 +263,12 @@ def run_test(self):
224
263
extracted = self .nodes [2 ].finalizepsbt (extractor ['extract' ], True )['hex' ]
225
264
assert_equal (extracted , extractor ['result' ])
226
265
266
+ # Unload extra wallets
267
+ for i , signer in enumerate (signers ):
268
+ self .nodes [2 ].unloadwallet ("wallet{}" .format (i ))
269
+
270
+ self .test_utxo_conversion ()
271
+
227
272
228
273
if __name__ == '__main__' :
229
274
PSBTTest ().main ()
0 commit comments