test: refactor IPC mining test to use script_BIP34_coinbase_height
What changed, and why it matters
This is a test-only code cleanup. It changes how a test helper builds the special coinbase script prefix for low block heights, adding an option to skip a padding byte. No production Bitcoin Core code is modified, so it cannot affect real users, funds, or network consensus.
No security action needed. Review as normal test refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the test helper script_BIP34_coinbase_height() in test_framework/blocktools.py to accept a padding parameter. When padding=True (default), behavior is unchanged: for heights <=16 it returns CScript([encode_op_n(height), OP_0]) to satisfy the minimum coinbase scriptSig length rule. When padding=False, it omits the OP_0 dummy. The interface_ipc_mining.py test is updated to use the helper with padding=False so its assertion matches the actual scriptSig prefix returned by the IPC mining interface. This is purely preparatory for a later commit and touches no consensus, P2P, wallet, or mempool code.
Changed components
test/functional/interface_ipc_mining.pytest/functional/test_framework/blocktools.pyInspect captured patch +8 / −10
diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py
index 31ccec63..1400a914 100755
--- a/test/functional/interface_ipc_mining.py
+++ b/test/functional/interface_ipc_mining.py
@@ -7,7 +7,7 @@ import asyncio
import time
from contextlib import AsyncExitStack
from io import BytesIO
-from test_framework.blocktools import NULL_OUTPOINT
+from test_framework.blocktools import NULL_OUTPOINT, script_BIP34_coinbase_height
from test_framework.messages import (
MAX_BLOCK_WEIGHT,
CBlockHeader,
@@ -20,10 +20,6 @@ from test_framework.messages import (
from_hex,
msg_headers,
)
-from test_framework.script import (
- CScript,
- CScriptNum,
-)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
@@ -79,8 +75,8 @@ class IPCMiningTest(BitcoinTestFramework):
# Verify there's no dummy extraNonce in the coinbase scriptSig
current_block_height = self.nodes[0].getchaintips()[0]["height"]
- expected_scriptsig = CScript([CScriptNum(current_block_height + 1)])
- assert_equal(coinbase_res.scriptSigPrefix.hex(), expected_scriptsig.hex())
+ bip34_prefix = script_BIP34_coinbase_height(current_block_height + 1, padding=False)
+ assert_equal(coinbase_res.scriptSigPrefix, bip34_prefix)
# Typically a mining pool appends its name and an extraNonce
coinbase_tx.vin[0].scriptSig = coinbase_res.scriptSigPrefix
diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py
index 0a393d89..529f07cd 100644
--- a/test/functional/test_framework/blocktools.py
+++ b/test/functional/test_framework/blocktools.py
@@ -161,11 +161,13 @@ def add_witness_commitment(block, nonce=0):
block.hashMerkleRoot = block.calc_merkle_root()
-def script_BIP34_coinbase_height(height):
+def script_BIP34_coinbase_height(height, *, padding=True):
if height <= 16:
res = CScriptOp.encode_op_n(height)
- # Append dummy extraNonce to increase scriptSig size to 2 (see bad-cb-length consensus rule)
- return CScript([res, OP_0])
+ if padding:
+ # Append dummy extraNonce to increase scriptSig size to 2 (see bad-cb-length consensus rule)
+ return CScript([res, OP_0])
+ return CScript([res])
return CScript([CScriptNum(height)])
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.