Tighten the input-amount test asserts and run the no-utxo test over every fixture
What changed, and why it matters
This commit only changes test code. It tightens some Python assertions (using 'is False' instead of '== False') and expands one test to run across more test fixtures. There is no change to the actual wallet or PSBT parsing logic that users rely on, so it does not fix or introduce a security issue in the product itself.
No security action needed. Treat as a normal test-quality improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/test_psbt_parser.py. It replaces boolean equality comparisons with identity comparisons in asserts, adds an explicit scriptPubKey mismatch check, replaces magic bytes with named opcode constants in a bare-multisig test fixture, and parametrizes test_input_with_no_utxo_data_raises over PSBTTestData.ALL_INPUTS instead of a single fixture. No production code in seedsigner is altered.
Changed components
tests/test_psbt_parser.pyInspect captured patch +12 / −9
### tests/test_psbt_parser.py
@@ -521,7 +521,7 @@ def test_untampered_psbts_verify(self, psbt_base64: str):
accepted with no non_witness_utxo to hash.
"""
psbt = self.build_psbt(psbt_base64)
- assert all(inp.is_verified == False for inp in psbt.inputs) # not verified until we do it
+ assert all(inp.is_verified is False for inp in psbt.inputs) # not verified until we do it
psbt_parser = PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
@@ -553,7 +553,7 @@ def test_witness_utxo_value_disagreeing_with_non_witness_utxo_raises(self, psbt_
psbt.inputs[0].witness_utxo.value += 100_000
# Confirm the premise: the non_witness_utxo is untouched and still verifies
- assert psbt.inputs[0].verify() == True
+ assert psbt.inputs[0].verify() is True
with pytest.raises(PSBTInputAmountVerificationError):
PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
@@ -575,8 +575,10 @@ def test_witness_utxo_script_pubkey_disagreeing_with_non_witness_utxo_raises(sel
witness_utxo.script_pubkey = Script(b"\x00\x14" + b"\x11" * 20)
# Confirm the premise: only the scriptPubKey moved, and the non_witness_utxo still verifies
+ prevout = psbt.inputs[0].non_witness_utxo.vout[psbt.inputs[0].vout]
assert witness_utxo.value == original_value
- assert psbt.inputs[0].verify() == True
+ assert witness_utxo.script_pubkey.data != prevout.script_pubkey.data
+ assert psbt.inputs[0].verify() is True
with pytest.raises(PSBTInputAmountVerificationError):
PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
@@ -613,9 +615,12 @@ def test_unrecognized_script_type_without_non_witness_utxo_raises(self):
# Bare multisig: a real scriptPubKey form that embit doesn't recognize, since it only
# knows the p2sh- and p2wsh-wrapped forms.
+ OP_1 = b"\x51"
+ OP_PUSHBYTES_33 = b"\x21"
+ OP_CHECKMULTISIG = b"\xae"
pubkey = list(inp.bip32_derivations.keys())[0].sec()
inp.witness_utxo = inp.non_witness_utxo.vout[inp.vout]
- inp.witness_utxo.script_pubkey = Script(b"\x51\x21" + pubkey + b"\x51\xae")
+ inp.witness_utxo.script_pubkey = Script(OP_1 + OP_PUSHBYTES_33 + pubkey + OP_1 + OP_CHECKMULTISIG)
inp.non_witness_utxo = None
# Confirm the premise: this really is an unrecognized script type
@@ -640,16 +645,14 @@ def test_segwit_input_without_non_witness_utxo_is_allowed(self, psbt_base64: str
assert psbt_parser.verified_input_amount == psbt.inputs[0].witness_utxo.value
- def test_input_with_no_utxo_data_raises(self):
+ @pytest.mark.parametrize("psbt_base64", PSBTTestData.ALL_INPUTS)
+ def test_input_with_no_utxo_data_raises(self, psbt_base64: str):
"""
Nothing to verify against and nothing to sum; refuse rather than guess. Without this
guard _get_policy() is handed a None script_pubkey and dies with an AttributeError
instead of an error the caller can route on.
-
- One fixture is enough: this is the first check in the loop, and once utxo is None the
- input's script_pubkey is None too, so no script type can reach it differently.
"""
- psbt = self.build_psbt(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_1_INPUT)
+ psbt = self.build_psbt(psbt_base64)
psbt.inputs[0].witness_utxo = None
psbt.inputs[0].non_witness_utxo = None
Why this scored 12/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.