Skip to content

Commit 2b4edf8

Browse files
committed
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.
1 parent c405207 commit 2b4edf8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

test/functional/rpc_psbt.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,17 +978,22 @@ def test_psbt_input_keys(psbt_input, keys):
978978
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo'])
979979

980980
# Test that the psbt is not finalized and does not have bip32_derivs unless specified
981-
psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=True, finalize=False)["psbt"]
982-
decoded = self.nodes[2].decodepsbt(psbt)
981+
processed_psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=True, finalize=False)
982+
decoded = self.nodes[2].decodepsbt(processed_psbt['psbt'])
983983
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'partial_signatures', 'bip32_derivs'])
984984

985-
psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=False, finalize=True)["psbt"]
986-
decoded = self.nodes[2].decodepsbt(psbt)
985+
# If psbt not finalized, test that result does not have hex
986+
assert "hex" not in processed_psbt
987+
988+
processed_psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=False, finalize=True)
989+
decoded = self.nodes[2].decodepsbt(processed_psbt['psbt'])
987990
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'final_scriptwitness'])
988991

992+
# Test psbt is complete
993+
assert_equal(processed_psbt['complete'], True)
994+
989995
# Broadcast transaction
990-
rawtx = self.nodes[2].finalizepsbt(psbt)["hex"]
991-
self.nodes[2].sendrawtransaction(rawtx)
996+
self.nodes[2].sendrawtransaction(processed_psbt['hex'])
992997

993998
self.log.info("Test descriptorprocesspsbt raises if an invalid sighashtype is passed")
994999
assert_raises_rpc_error(-8, "all is not a valid sighash parameter.", self.nodes[2].descriptorprocesspsbt, psbt, [descriptor], sighashtype="all")

0 commit comments

Comments
 (0)