testing: add ability to set nLockTime in fake_{ms,}_txn
What changed, and why it matters
This change only adds a new testing option to two fake transaction builders used in the project's test suite. It lets tests optionally set a Bitcoin transaction's nLockTime field and adjusts the first input's sequence number accordingly so the locktime is actually enforced in test scenarios. There is no change to production firmware code, no fix for a real bug, and no security relevance in the commit itself.
No action required. This is a test-only enhancement. If reviewing, confirm it is only used in tests and that default behavior (lock_time=0) is unchanged.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies testing/test_multisig.py and testing/txn.py, which are test helpers. It adds a lock_time parameter (default 0) to fake_ms_txn and fake_txn, assigns it to CTransaction.nLockTime, and when lock_time is non-zero sets the first input’s nSequence to 0xfffffffd instead of 0xffffffff. This is purely test infrastructure to enable future tests involving timelocked transactions. No COLDCARD firmware code is changed.
Changed components
testing/test_multisig.pytesting/txn.pyInspect captured patch +16 / −4
diff --git a/testing/test_multisig.py b/testing/test_multisig.py
index 9adfb13..8cafd87 100644
--- a/testing/test_multisig.py
+++ b/testing/test_multisig.py
@@ -1284,7 +1284,7 @@ def fake_ms_txn(pytestconfig):
outstyles=['p2pkh'], change_outputs=[], incl_xpubs=False, hack_psbt=None,
hack_change_out=False, input_amount=1E8, psbt_v2=None, bip67=True,
violate_script_key_order=False, path_mapper=None, inp_af=AF_P2WSH,
- force_outstyle=None):
+ force_outstyle=None, lock_time=0):
psbt = BasicPSBT()
if psbt_v2 is None:
@@ -1301,6 +1301,7 @@ def fake_ms_txn(pytestconfig):
txn = CTransaction()
txn.nVersion = 2
+ txn.nLockTime = lock_time
if incl_xpubs:
# add global header with XPUB's
@@ -1370,7 +1371,12 @@ def fake_ms_txn(pytestconfig):
# TODO height timelock
# TODO time timelock
- spendable = CTxIn(COutPoint(supply.sha256, 0), nSequence=0xffffffff)
+ if lock_time and not i:
+ seq = 0xfffffffd
+ else:
+ seq = 0xffffffff
+
+ spendable = CTxIn(COutPoint(supply.sha256, 0), nSequence=seq)
txn.vin.append(spendable)
for i in range(num_outs):
diff --git a/testing/txn.py b/testing/txn.py
index 73f592d..b0a3493 100644
--- a/testing/txn.py
+++ b/testing/txn.py
@@ -24,7 +24,7 @@ def fake_txn(dev, pytestconfig):
invals=None, outvals=None, segwit_in=False, wrapped=False,
outstyles=['p2pkh'], psbt_hacker=None, change_outputs=[],
capture_scripts=None, add_xpub=None, op_return=None, taproot_in=False,
- psbt_v2=None, input_amount=1E8, unknown_out_script=None):
+ psbt_v2=None, input_amount=1E8, unknown_out_script=None, lock_time=0):
psbt = BasicPSBT()
@@ -41,6 +41,7 @@ def fake_txn(dev, pytestconfig):
psbt.output_count = num_outs
txn = CTransaction()
+ txn.nLockTime = lock_time
txn.nVersion = 2
master_xpub = master_xpub or dev.master_xpub or simulator_fixed_tprv
@@ -105,7 +106,12 @@ def fake_txn(dev, pytestconfig):
# TODO height timelock
# TODO time timelock
- spendable = CTxIn(COutPoint(supply.sha256, 0), nSequence=0xffffffff)
+ if lock_time and not i:
+ seq = 0xfffffffd
+ else:
+ seq = 0xffffffff
+
+ spendable = CTxIn(COutPoint(supply.sha256, 0), nSequence=seq)
txn.vin.append(spendable)
for i in range(num_outs):
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.