mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-16 17:48:59 +02:00
test: refactor IPC mining test to use script_BIP34_coinbase_height
Needed in a later commit to correctly derive the BIP34 prefix for heights <= 16. Add a padding parameter to script_BIP34_coinbase_height() that controls whether the OP_0 dummy extranonce is appended for heights <= 16. Use this helper with padding=False in the IPC mining test's build_coinbase_test().
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user