Drop OP_RETURN test helper parameters that nothing passes
What changed, and why it matters
This commit only cleans up unused parameters in a test helper file. It removes optional arguments that no test was actually using, simplifying the code without changing any real behavior. There is no security issue here.
No action needed. This is a benign test-only refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies tests/psbt_testing_util.py to remove the unused push_opcode parameter from op_return_script() and the unused change_amount and fee_amount parameters from create_op_return_psbt(). The logic is simplified to always use minimal push encoding and a fixed 5,000 sat fee. No runtime code is affected, and no test behavior changes because the removed parameters were never passed.
Changed components
tests/psbt_testing_util.pyInspect captured patch +15 / −26
### tests/psbt_testing_util.py
@@ -258,29 +258,20 @@ def claim_seed_owns_key(scope: InputScope | OutputScope, claimed_derivation_path
scope.bip32_derivations[public_key] = derivation_path
-def op_return_script(payload: bytes, push_opcode: int = None) -> Script:
+def op_return_script(payload: bytes) -> Script:
"""
- Build an OP_RETURN scriptPubKey carrying `payload`.
-
- Defaults to the minimal push encoding, which is what Bitcoin Core emits: a direct
- push for 75 bytes or fewer, OP_PUSHDATA1 up to 255, OP_PUSHDATA2 up to 65535, and
- OP_PUSHDATA4 above that.
-
- `push_opcode` forces a specific OP_PUSHDATA* instead, so a test can build the
- non-minimal encodings that a coordinator is still free to produce.
+ Build an OP_RETURN scriptPubKey carrying `payload`, using the minimal push encoding
+ that Bitcoin Core emits: a direct push for 75 bytes or fewer, OP_PUSHDATA1 up to 255,
+ OP_PUSHDATA2 up to 65535, and OP_PUSHDATA4 above that.
"""
- if push_opcode is None:
- if len(payload) <= OPCODES.OP_PUSHDATA_MAX_DIRECT:
- push = bytes([len(payload)])
- elif len(payload) <= 0xff:
- push = bytes([OPCODES.OP_PUSHDATA1, len(payload)])
- elif len(payload) <= 0xffff:
- push = bytes([OPCODES.OP_PUSHDATA2]) + len(payload).to_bytes(2, "little")
- else:
- push = bytes([OPCODES.OP_PUSHDATA4]) + len(payload).to_bytes(4, "little")
+ if len(payload) <= OPCODES.OP_PUSHDATA_MAX_DIRECT:
+ push = bytes([len(payload)])
+ elif len(payload) <= 0xff:
+ push = bytes([OPCODES.OP_PUSHDATA1, len(payload)])
+ elif len(payload) <= 0xffff:
+ push = bytes([OPCODES.OP_PUSHDATA2]) + len(payload).to_bytes(2, "little")
else:
- length_size = {OPCODES.OP_PUSHDATA1: 1, OPCODES.OP_PUSHDATA2: 2, OPCODES.OP_PUSHDATA4: 4}[push_opcode]
- push = bytes([push_opcode]) + len(payload).to_bytes(length_size, "little")
+ push = bytes([OPCODES.OP_PUSHDATA4]) + len(payload).to_bytes(4, "little")
return Script(bytes([OPCODES.OP_RETURN]) + push + payload)
@@ -303,20 +294,18 @@ def create_op_return_output(payload: bytes, value: int = 0, script_pubkey: Scrip
return output
-def create_op_return_psbt(op_return_outputs: list, change_amount: int = None, fee_amount: int = 5_000) -> PSBT:
+def create_op_return_psbt(op_return_outputs: list) -> PSBT:
"""
A single-sig native segwit psbt with one change output and the given OP_RETURN
OutputScopes (see `create_op_return_output`) appended after it, in order.
- `change_amount` defaults to whatever is left of the input after the OP_RETURN values
- and the fee, so the psbt balances.
+ The change output gets whatever is left of the input after the OP_RETURN values and a
+ 5,000 sat fee.
"""
psbt = PSBT.parse(a2b_base64(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_1_INPUT))
input_amount = sum([inp.utxo.value for inp in psbt.inputs])
op_return_amount = sum([output.value for output in op_return_outputs])
-
- if change_amount is None:
- change_amount = input_amount - op_return_amount - fee_amount
+ change_amount = input_amount - op_return_amount - 5_000
psbt.outputs.clear()
psbt.outputs.append(create_output(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_CHANGE, change_amount))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.