Replace the parse() test helper with direct PSBTParser calls
What changed, and why it matters
This commit only changes a test file. It removes a small helper method called parse() and replaces its calls with the same one-line PSBTParser constructor call written out directly. There is no change to the actual wallet/security code that users run, so this cannot affect real-world security.
No security action needed; this is a routine test refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In tests/test_psbt_parser.py, the private helper parse(self, psbt) is deleted and all call sites are inlined to PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST). One assertion is split into two lines and a clarifying comment is added. The diff is purely a test-code refactoring with no functional change to PSBTParser or any runtime behavior.
Changed components
tests/test_psbt_parser.pyInspect captured patch +11 / −13
### tests/test_psbt_parser.py
@@ -509,10 +509,6 @@ def build_psbt(self, psbt_base64: str) -> PSBT:
return psbt
- def parse(self, psbt: PSBT) -> PSBTParser:
- return PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
-
-
@pytest.mark.parametrize("psbt_base64", PSBTTestData.ALL_INPUTS)
def test_untampered_psbts_verify(self, psbt_base64: str):
"""
@@ -527,7 +523,7 @@ def test_untampered_psbts_verify(self, psbt_base64: str):
psbt = self.build_psbt(psbt_base64)
assert all(inp.is_verified == False for inp in psbt.inputs) # not verified until we do it
- psbt_parser = self.parse(psbt)
+ psbt_parser = PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
assert all(inp.is_verified for inp in psbt.inputs)
assert psbt_parser.verified_input_amount == sum([inp.utxo.value for inp in psbt.inputs])
@@ -543,7 +539,7 @@ def test_tampered_non_witness_utxo_raises(self, psbt_base64: str):
psbt.inputs[0].non_witness_utxo.vout[0].value += 100_000
with pytest.raises(PSBTInputAmountVerificationError):
- self.parse(psbt)
+ PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
@pytest.mark.parametrize("psbt_base64", WITNESS_UTXO_INPUTS)
@@ -560,7 +556,7 @@ def test_witness_utxo_value_disagreeing_with_non_witness_utxo_raises(self, psbt_
assert psbt.inputs[0].verify() == True
with pytest.raises(PSBTInputAmountVerificationError):
- self.parse(psbt)
+ PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
@pytest.mark.parametrize("psbt_base64", WITNESS_UTXO_INPUTS)
@@ -583,7 +579,7 @@ def test_witness_utxo_script_pubkey_disagreeing_with_non_witness_utxo_raises(sel
assert psbt.inputs[0].verify() == True
with pytest.raises(PSBTInputAmountVerificationError):
- self.parse(psbt)
+ PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
@pytest.mark.parametrize("psbt_base64", LEGACY_INPUTS)
@@ -602,7 +598,7 @@ def test_legacy_input_without_non_witness_utxo_raises(self, psbt_base64: str):
inp.non_witness_utxo = None
with pytest.raises(PSBTInputAmountVerificationError):
- self.parse(psbt)
+ PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
def test_unrecognized_script_type_without_non_witness_utxo_raises(self):
@@ -626,7 +622,7 @@ def test_unrecognized_script_type_without_non_witness_utxo_raises(self):
assert inp.witness_utxo.script_pubkey.script_type() is None
with pytest.raises(PSBTInputAmountVerificationError):
- self.parse(psbt)
+ PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
@pytest.mark.parametrize("psbt_base64", WITNESS_UTXO_INPUTS)
@@ -639,7 +635,9 @@ def test_segwit_input_without_non_witness_utxo_is_allowed(self, psbt_base64: str
psbt = self.build_psbt(psbt_base64)
psbt.inputs[0].non_witness_utxo = None
- assert self.parse(psbt).verified_input_amount == psbt.inputs[0].witness_utxo.value
+ # Parses without raising an exception
+ psbt_parser = PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
+ assert psbt_parser.verified_input_amount == psbt.inputs[0].witness_utxo.value
def test_input_with_no_utxo_data_raises(self):
@@ -656,7 +654,7 @@ def test_input_with_no_utxo_data_raises(self):
psbt.inputs[0].non_witness_utxo = None
with pytest.raises(PSBTMissingInputUtxoError):
- self.parse(psbt)
+ PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
def test_outpoint_index_past_end_of_non_witness_utxo_raises(self):
@@ -674,7 +672,7 @@ def test_outpoint_index_past_end_of_non_witness_utxo_raises(self):
inp.vout = len(inp.non_witness_utxo.vout)
with pytest.raises(PSBTMissingInputUtxoError):
- self.parse(psbt)
+ PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
def test_every_input_is_checked_not_just_the_first(self):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.