38
38
assert_greater_than ,
39
39
assert_greater_than_or_equal ,
40
40
assert_raises_rpc_error ,
41
- find_output ,
42
41
find_vout_for_address ,
43
42
random_bytes ,
44
43
)
@@ -417,16 +416,17 @@ def run_test(self):
417
416
self .nodes [0 ].converttopsbt (hexstring = signedtx ['hex' ], permitsigdata = True )
418
417
419
418
# Create outputs to nodes 1 and 2
419
+ # (note that we intentionally create two different txs here, as we want
420
+ # to check that each node is missing prevout data for one of the two
421
+ # utxos, see "should only have data for one input" test below)
420
422
node1_addr = self .nodes [1 ].getnewaddress ()
421
423
node2_addr = self .nodes [2 ].getnewaddress ()
422
- txid1 = self .nodes [0 ].sendtoaddress (node1_addr , 13 )
423
- txid2 = self .nodes [0 ].sendtoaddress (node2_addr , 13 )
424
- blockhash = self .generate (self .nodes [0 ], 6 )[0 ]
425
- vout1 = find_output (self .nodes [1 ], txid1 , 13 , blockhash = blockhash )
426
- vout2 = find_output (self .nodes [2 ], txid2 , 13 , blockhash = blockhash )
424
+ utxo1 = self .create_outpoints (self .nodes [0 ], outputs = [{node1_addr : 13 }])[0 ]
425
+ utxo2 = self .create_outpoints (self .nodes [0 ], outputs = [{node2_addr : 13 }])[0 ]
426
+ self .generate (self .nodes [0 ], 6 )[0 ]
427
427
428
428
# Create a psbt spending outputs from nodes 1 and 2
429
- psbt_orig = self .nodes [0 ].createpsbt ([{ "txid" : txid1 , "vout" : vout1 }, { "txid" : txid2 , "vout" : vout2 } ], {self .nodes [0 ].getnewaddress ():25.999 })
429
+ psbt_orig = self .nodes [0 ].createpsbt ([utxo1 , utxo2 ], {self .nodes [0 ].getnewaddress ():25.999 })
430
430
431
431
# Update psbts, should only have data for one input and not the other
432
432
psbt1 = self .nodes [1 ].walletprocesspsbt (psbt_orig , False , "ALL" )['psbt' ]
@@ -603,22 +603,17 @@ def run_test(self):
603
603
604
604
# Send to all types of addresses
605
605
addr1 = self .nodes [1 ].getnewaddress ("" , "bech32" )
606
- txid1 = self .nodes [0 ].sendtoaddress (addr1 , 11 )
607
- vout1 = find_output (self .nodes [0 ], txid1 , 11 )
608
606
addr2 = self .nodes [1 ].getnewaddress ("" , "legacy" )
609
- txid2 = self .nodes [0 ].sendtoaddress (addr2 , 11 )
610
- vout2 = find_output (self .nodes [0 ], txid2 , 11 )
611
607
addr3 = self .nodes [1 ].getnewaddress ("" , "p2sh-segwit" )
612
- txid3 = self .nodes [0 ].sendtoaddress (addr3 , 11 )
613
- vout3 = find_output (self .nodes [0 ], txid3 , 11 )
608
+ utxo1 , utxo2 , utxo3 = self .create_outpoints (self .nodes [1 ], outputs = [{addr1 : 11 }, {addr2 : 11 }, {addr3 : 11 }])
614
609
self .sync_all ()
615
610
616
611
def test_psbt_input_keys (psbt_input , keys ):
617
612
"""Check that the psbt input has only the expected keys."""
618
613
assert_equal (set (keys ), set (psbt_input .keys ()))
619
614
620
615
# Create a PSBT. None of the inputs are filled initially
621
- psbt = self .nodes [1 ].createpsbt ([{ "txid" : txid1 , "vout" : vout1 },{ "txid" : txid2 , "vout" : vout2 },{ "txid" : txid3 , "vout" : vout3 } ], {self .nodes [0 ].getnewaddress ():32.999 })
616
+ psbt = self .nodes [1 ].createpsbt ([utxo1 , utxo2 , utxo3 ], {self .nodes [0 ].getnewaddress ():32.999 })
622
617
decoded = self .nodes [1 ].decodepsbt (psbt )
623
618
test_psbt_input_keys (decoded ['inputs' ][0 ], [])
624
619
test_psbt_input_keys (decoded ['inputs' ][1 ], [])
@@ -641,15 +636,14 @@ def test_psbt_input_keys(psbt_input, keys):
641
636
test_psbt_input_keys (decoded ['inputs' ][2 ], ['non_witness_utxo' ,'witness_utxo' , 'bip32_derivs' , 'redeem_script' ])
642
637
643
638
# Two PSBTs with a common input should not be joinable
644
- psbt1 = self .nodes [1 ].createpsbt ([{ "txid" : txid1 , "vout" : vout1 } ], {self .nodes [0 ].getnewaddress ():Decimal ('10.999' )})
639
+ psbt1 = self .nodes [1 ].createpsbt ([utxo1 ], {self .nodes [0 ].getnewaddress ():Decimal ('10.999' )})
645
640
assert_raises_rpc_error (- 8 , "exists in multiple PSBTs" , self .nodes [1 ].joinpsbts , [psbt1 , updated ])
646
641
647
642
# Join two distinct PSBTs
648
643
addr4 = self .nodes [1 ].getnewaddress ("" , "p2sh-segwit" )
649
- txid4 = self .nodes [0 ].sendtoaddress (addr4 , 5 )
650
- vout4 = find_output (self .nodes [0 ], txid4 , 5 )
644
+ utxo4 = self .create_outpoints (self .nodes [0 ], outputs = [{addr4 : 5 }])[0 ]
651
645
self .generate (self .nodes [0 ], 6 )
652
- psbt2 = self .nodes [1 ].createpsbt ([{ "txid" : txid4 , "vout" : vout4 } ], {self .nodes [0 ].getnewaddress ():Decimal ('4.999' )})
646
+ psbt2 = self .nodes [1 ].createpsbt ([utxo4 ], {self .nodes [0 ].getnewaddress ():Decimal ('4.999' )})
653
647
psbt2 = self .nodes [1 ].walletprocesspsbt (psbt2 )['psbt' ]
654
648
psbt2_decoded = self .nodes [0 ].decodepsbt (psbt2 )
655
649
assert "final_scriptwitness" in psbt2_decoded ['inputs' ][0 ] and "final_scriptSig" in psbt2_decoded ['inputs' ][0 ]
@@ -669,11 +663,10 @@ def test_psbt_input_keys(psbt_input, keys):
669
663
670
664
# Newly created PSBT needs UTXOs and updating
671
665
addr = self .nodes [1 ].getnewaddress ("" , "p2sh-segwit" )
672
- txid = self .nodes [0 ]. sendtoaddress ( addr , 7 )
666
+ utxo = self .create_outpoints ( self . nodes [0 ], outputs = [{ addr : 7 }])[ 0 ]
673
667
addrinfo = self .nodes [1 ].getaddressinfo (addr )
674
- blockhash = self .generate (self .nodes [0 ], 6 )[0 ]
675
- vout = find_output (self .nodes [0 ], txid , 7 , blockhash = blockhash )
676
- psbt = self .nodes [1 ].createpsbt ([{"txid" :txid , "vout" :vout }], {self .nodes [0 ].getnewaddress ("" , "p2sh-segwit" ):Decimal ('6.999' )})
668
+ self .generate (self .nodes [0 ], 6 )[0 ]
669
+ psbt = self .nodes [1 ].createpsbt ([utxo ], {self .nodes [0 ].getnewaddress ("" , "p2sh-segwit" ):Decimal ('6.999' )})
677
670
analyzed = self .nodes [0 ].analyzepsbt (psbt )
678
671
assert not analyzed ['inputs' ][0 ]['has_utxo' ] and not analyzed ['inputs' ][0 ]['is_final' ] and analyzed ['inputs' ][0 ]['next' ] == 'updater' and analyzed ['next' ] == 'updater'
679
672
@@ -872,9 +865,8 @@ def test_psbt_input_keys(psbt_input, keys):
872
865
873
866
self .log .info ("Test that walletprocesspsbt both updates and signs a non-updated psbt containing Taproot inputs" )
874
867
addr = self .nodes [0 ].getnewaddress ("" , "bech32m" )
875
- txid = self .nodes [0 ].sendtoaddress (addr , 1 )
876
- vout = find_vout_for_address (self .nodes [0 ], txid , addr )
877
- psbt = self .nodes [0 ].createpsbt ([{"txid" : txid , "vout" : vout }], [{self .nodes [0 ].getnewaddress (): 0.9999 }])
868
+ utxo = self .create_outpoints (self .nodes [0 ], outputs = [{addr : 1 }])[0 ]
869
+ psbt = self .nodes [0 ].createpsbt ([utxo ], [{self .nodes [0 ].getnewaddress (): 0.9999 }])
878
870
signed = self .nodes [0 ].walletprocesspsbt (psbt )
879
871
rawtx = signed ["hex" ]
880
872
self .nodes [0 ].sendrawtransaction (rawtx )
@@ -962,11 +954,10 @@ def test_psbt_input_keys(psbt_input, keys):
962
954
963
955
descriptor = descsum_create (f"wpkh({ key } )" )
964
956
965
- txid = self .nodes [0 ]. sendtoaddress ( address , 1 )
957
+ utxo = self .create_outpoints ( self . nodes [0 ], outputs = [{ address : 1 }])[ 0 ]
966
958
self .sync_all ()
967
- vout = find_output (self .nodes [0 ], txid , 1 )
968
959
969
- psbt = self .nodes [2 ].createpsbt ([{ "txid" : txid , "vout" : vout } ], {self .nodes [0 ].getnewaddress (): 0.99999 })
960
+ psbt = self .nodes [2 ].createpsbt ([utxo ], {self .nodes [0 ].getnewaddress (): 0.99999 })
970
961
decoded = self .nodes [2 ].decodepsbt (psbt )
971
962
test_psbt_input_keys (decoded ['inputs' ][0 ], [])
972
963
0 commit comments