Merge bitcoin/bitcoin#37110: test: fix ineffective checks in rpc_psbt.py
What changed, and why it matters
This commit fixes three mistakes in Bitcoin Core's automated test file rpc_psbt.py. The tests were accidentally written in ways that meant they would always pass, even if the feature they were supposed to check was broken. The fixes correct a typo in a key name, check the right PSBT data after wallet processing, and verify all joined inputs instead of just one. There is no change to the actual Bitcoin node code that users run, only to the test suite, so this cannot directly affect live wallets or the network.
No security action required. Treat as a normal test-quality improvement. Reviewers may optionally verify that the corrected assertions now exercise the intended PSBT behavior.
Security signals we found
test-only change
no production code modified
fixes ineffective assertions in functional tests
no runtime behavior change to Bitcoin Core
Evidence from the diff
The patch is a pure test-only change in test/functional/rpc_psbt.py. It corrects three ineffective assertions: (1) ‘not_witness_utxo’ is changed to the correct PSBT field name ‘non_witness_utxo’; (2) the tap-tree absence check now inspects the walletprocesspsbt result for a bech32m output and asserts both the presence of PSBT_OUT_TAP_INTERNAL_KEY and absence of PSBT_OUT_TAP_TREE; (3) after joinpsbts, the final-script fields are now checked on every joined input because input order is shuffled. No production code is modified.
Changed components
test/functional/rpc_psbt.pyInspect captured patch +16 / −9
### test/functional/rpc_psbt.py
@@ -48,6 +48,7 @@
PSBT_IN_FINAL_SCRIPTWITNESS,
PSBT_OUT_MUSIG2_PARTICIPANT_PUBKEYS,
PSBT_OUT_PROPRIETARY,
+ PSBT_OUT_TAP_INTERNAL_KEY,
PSBT_OUT_TAP_TREE,
PSBT_OUT_SCRIPT,
)
@@ -159,7 +160,7 @@ def test_utxo_conversion(self):
utxos = wonline.listunspent(addresses=[offline_addr])
raw = wonline.createrawtransaction([{"txid":utxos[0]["txid"], "vout":utxos[0]["vout"]}],[{online_addr:0.9999}])
psbt = wonline.walletprocesspsbt(online_node.converttopsbt(raw))["psbt"]
- assert "not_witness_utxo" not in mining_node.decodepsbt(psbt)["inputs"][0]
+ assert "non_witness_utxo" not in mining_node.decodepsbt(psbt)["inputs"][0]
# add non-witness UTXO manually
psbt_new = PSBT.from_base64(psbt)
@@ -1444,8 +1445,10 @@ def test_psbt_input_keys(psbt_input, keys):
joined_decoded = self.nodes[0].decodepsbt(joined)
assert_equal(len(joined_decoded['inputs']), 4)
assert_equal(len(joined_decoded['outputs']), 2)
- assert "final_scriptwitness" not in joined_decoded['inputs'][3]
- assert "final_scriptSig" not in joined_decoded['inputs'][3]
+ # joining must drop the final scripts of psbt2's input; inputs are shuffled, so check all
+ for joined_input in joined_decoded['inputs']:
+ assert "final_scriptwitness" not in joined_input
+ assert "final_scriptSig" not in joined_input
# Check that joining shuffles the inputs and outputs
# 10 attempts should be enough to get a shuffled join
@@ -1695,19 +1698,23 @@ def global_xpub_key(extended_pubkey):
self.log.info("Test that walletprocesspsbt both updates and signs a non-updated psbt containing Taproot inputs")
addr = self.nodes[0].getnewaddress("", "bech32m")
utxo = self.create_outpoints(self.nodes[0], outputs=[{addr: 1}])[0]
- psbt = self.nodes[0].createpsbt([utxo], [{self.nodes[0].getnewaddress(): 0.9999}])
+ psbt = self.nodes[0].createpsbt([utxo], [{self.nodes[0].getnewaddress("", "bech32m"): 0.9999}])
signed = self.nodes[0].walletprocesspsbt(psbt)
rawtx = signed["hex"]
self.nodes[0].sendrawtransaction(rawtx)
self.generate(self.nodes[0], 1)
- # Make sure tap tree is not in psbt
- parsed_psbt = PSBT.from_base64(psbt)
+ # Make sure tap tree is not in psbt for a key-path-only taproot output
+ signed_psbt = signed["psbt"]
+ parsed_psbt = PSBT.from_base64(signed_psbt)
+ assert PSBT_OUT_TAP_INTERNAL_KEY in parsed_psbt.o[0].map
assert PSBT_OUT_TAP_TREE not in parsed_psbt.o[0].map
- assert "taproot_tree" not in self.nodes[0].decodepsbt(psbt)["outputs"][0]
+ decoded_output = self.nodes[0].decodepsbt(signed_psbt)["outputs"][0]
+ assert "taproot_internal_key" in decoded_output
+ assert "taproot_tree" not in decoded_output
parsed_psbt.make_blank()
- comb_psbt = self.nodes[0].combinepsbt([psbt, parsed_psbt.to_base64()])
- assert_equal(comb_psbt, psbt)
+ comb_psbt = self.nodes[0].combinepsbt([signed_psbt, parsed_psbt.to_base64()])
+ assert_equal(comb_psbt, signed_psbt)
self.log.info("Test walletprocesspsbt raises if an invalid sighashtype is passed")
assert_raises_rpc_error(-8, "'all' is not a valid sighash parameter.", self.nodes[0].walletprocesspsbt, psbt=psbt, sighashtype="all")Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.