3838 assert_greater_than ,
3939 assert_greater_than_or_equal ,
4040 assert_raises_rpc_error ,
41- find_output ,
4241 find_vout_for_address ,
4342 random_bytes ,
4443)
@@ -417,16 +416,17 @@ def run_test(self):
417416 self .nodes [0 ].converttopsbt (hexstring = signedtx ['hex' ], permitsigdata = True )
418417
419418 # 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)
420422 node1_addr = self .nodes [1 ].getnewaddress ()
421423 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 ]
427427
428428 # 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 })
430430
431431 # Update psbts, should only have data for one input and not the other
432432 psbt1 = self .nodes [1 ].walletprocesspsbt (psbt_orig , False , "ALL" )['psbt' ]
@@ -603,22 +603,17 @@ def run_test(self):
603603
604604 # Send to all types of addresses
605605 addr1 = self .nodes [1 ].getnewaddress ("" , "bech32" )
606- txid1 = self .nodes [0 ].sendtoaddress (addr1 , 11 )
607- vout1 = find_output (self .nodes [0 ], txid1 , 11 )
608606 addr2 = self .nodes [1 ].getnewaddress ("" , "legacy" )
609- txid2 = self .nodes [0 ].sendtoaddress (addr2 , 11 )
610- vout2 = find_output (self .nodes [0 ], txid2 , 11 )
611607 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 }])
614609 self .sync_all ()
615610
616611 def test_psbt_input_keys (psbt_input , keys ):
617612 """Check that the psbt input has only the expected keys."""
618613 assert_equal (set (keys ), set (psbt_input .keys ()))
619614
620615 # 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 })
622617 decoded = self .nodes [1 ].decodepsbt (psbt )
623618 test_psbt_input_keys (decoded ['inputs' ][0 ], [])
624619 test_psbt_input_keys (decoded ['inputs' ][1 ], [])
@@ -641,15 +636,14 @@ def test_psbt_input_keys(psbt_input, keys):
641636 test_psbt_input_keys (decoded ['inputs' ][2 ], ['non_witness_utxo' ,'witness_utxo' , 'bip32_derivs' , 'redeem_script' ])
642637
643638 # 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' )})
645640 assert_raises_rpc_error (- 8 , "exists in multiple PSBTs" , self .nodes [1 ].joinpsbts , [psbt1 , updated ])
646641
647642 # Join two distinct PSBTs
648643 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 ]
651645 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' )})
653647 psbt2 = self .nodes [1 ].walletprocesspsbt (psbt2 )['psbt' ]
654648 psbt2_decoded = self .nodes [0 ].decodepsbt (psbt2 )
655649 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):
669663
670664 # Newly created PSBT needs UTXOs and updating
671665 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 ]
673667 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' )})
677670 analyzed = self .nodes [0 ].analyzepsbt (psbt )
678671 assert not analyzed ['inputs' ][0 ]['has_utxo' ] and not analyzed ['inputs' ][0 ]['is_final' ] and analyzed ['inputs' ][0 ]['next' ] == 'updater' and analyzed ['next' ] == 'updater'
679672
@@ -872,9 +865,8 @@ def test_psbt_input_keys(psbt_input, keys):
872865
873866 self .log .info ("Test that walletprocesspsbt both updates and signs a non-updated psbt containing Taproot inputs" )
874867 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 }])
878870 signed = self .nodes [0 ].walletprocesspsbt (psbt )
879871 rawtx = signed ["hex" ]
880872 self .nodes [0 ].sendrawtransaction (rawtx )
@@ -962,11 +954,10 @@ def test_psbt_input_keys(psbt_input, keys):
962954
963955 descriptor = descsum_create (f"wpkh({ key } )" )
964956
965- txid = self .nodes [0 ]. sendtoaddress ( address , 1 )
957+ utxo = self .create_outpoints ( self . nodes [0 ], outputs = [{ address : 1 }])[ 0 ]
966958 self .sync_all ()
967- vout = find_output (self .nodes [0 ], txid , 1 )
968959
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 })
970961 decoded = self .nodes [2 ].decodepsbt (psbt )
971962 test_psbt_input_keys (decoded ['inputs' ][0 ], [])
972963
0 commit comments