0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

test: check descriptorprocesspsbt return hex encoded tx

Test that if the processed psbt is complete the hex encoded tx
is returned and remove unneccessary rpc call to finalize the
psbt.
This commit is contained in:
ismaelsadeeq 2023-09-15 16:48:36 +01:00
parent c405207a18
commit 2b4edf889a

View file

@ -978,17 +978,22 @@ class PSBTTest(BitcoinTestFramework):
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo']) test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo'])
# Test that the psbt is not finalized and does not have bip32_derivs unless specified # Test that the psbt is not finalized and does not have bip32_derivs unless specified
psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=True, finalize=False)["psbt"] processed_psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=True, finalize=False)
decoded = self.nodes[2].decodepsbt(psbt) decoded = self.nodes[2].decodepsbt(processed_psbt['psbt'])
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'partial_signatures', 'bip32_derivs']) test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'partial_signatures', 'bip32_derivs'])
psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=False, finalize=True)["psbt"] # If psbt not finalized, test that result does not have hex
decoded = self.nodes[2].decodepsbt(psbt) assert "hex" not in processed_psbt
processed_psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=False, finalize=True)
decoded = self.nodes[2].decodepsbt(processed_psbt['psbt'])
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'final_scriptwitness']) test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'final_scriptwitness'])
# Test psbt is complete
assert_equal(processed_psbt['complete'], True)
# Broadcast transaction # Broadcast transaction
rawtx = self.nodes[2].finalizepsbt(psbt)["hex"] self.nodes[2].sendrawtransaction(processed_psbt['hex'])
self.nodes[2].sendrawtransaction(rawtx)
self.log.info("Test descriptorprocesspsbt raises if an invalid sighashtype is passed") self.log.info("Test descriptorprocesspsbt raises if an invalid sighashtype is passed")
assert_raises_rpc_error(-8, "all is not a valid sighash parameter.", self.nodes[2].descriptorprocesspsbt, psbt, [descriptor], sighashtype="all") assert_raises_rpc_error(-8, "all is not a valid sighash parameter.", self.nodes[2].descriptorprocesspsbt, psbt, [descriptor], sighashtype="all")