test: Require named arg for create_block ntime arg

The named arg is useful, so that the two integral args (possibly
integral literals) `height` and `ntime` are not confused.
This commit is contained in:
MarcoFalke
2026-04-16 08:00:55 +02:00
parent fab352053d
commit fa16bc53d7
10 changed files with 21 additions and 24 deletions

View File

@@ -91,7 +91,7 @@ class AssumeValidTest(BitcoinTestFramework):
# Create the first block with a coinbase output to our key
height = 1
block = create_block(self.tip, create_coinbase(height, coinbase_pubkey), self.block_time)
block = create_block(self.tip, create_coinbase(height, coinbase_pubkey), ntime=self.block_time)
self.blocks.append(block)
self.block_time += 1
block.solve()

View File

@@ -1374,12 +1374,12 @@ class FullBlockTest(BitcoinTestFramework):
for additional_script in additional_output_scripts:
coinbase.vout.append(CTxOut(0, additional_script))
if spend is None:
block = create_block(base_block_hash, coinbase, block_time, version=version)
block = create_block(base_block_hash, coinbase, ntime=block_time, version=version)
else:
coinbase.vout[0].nValue += spend.vout[0].nValue - 1 # all but one satoshi to fees
tx = self.create_tx(spend, 0, 1, output_script=script) # spend 1 satoshi
self.sign_tx(tx, spend)
block = create_block(base_block_hash, coinbase, block_time, version=version, txlist=[tx])
block = create_block(base_block_hash, coinbase, ntime=block_time, version=version, txlist=[tx])
# Block is created. Find a valid nonce.
block.solve()
self.tip = block

View File

@@ -194,7 +194,7 @@ class CoinStatsIndexTest(BitcoinTestFramework):
# Generate a block that includes previous coinbase
tip = self.nodes[0].getbestblockhash()
block_time = self.nodes[0].getblock(tip)['time'] + 1
block = create_block(int(tip, 16), cb, block_time)
block = create_block(int(tip, 16), cb, ntime=block_time)
block.solve()
self.nodes[0].submitblock(block.serialize().hex())
self.sync_all()

View File

@@ -1425,7 +1425,7 @@ class TaprootTest(BitcoinTestFramework):
extra_output_script = CScript(bytes([OP_CHECKSIG]*((MAX_BLOCK_SIGOPS_WEIGHT - sigops_weight) // WITNESS_SCALE_FACTOR)))
coinbase_tx = create_coinbase(self.lastblockheight + 1, pubkey=cb_pubkey, extra_output_script=extra_output_script, fees=fees)
block = create_block(self.tip, coinbase_tx, self.lastblocktime + 1, txlist=txs)
block = create_block(self.tip, coinbase_tx, ntime=self.lastblocktime + 1, txlist=txs)
witness and add_witness_commitment(block)
block.solve()
block_response = node.submitblock(block.serialize().hex())

View File

@@ -13,7 +13,6 @@ import copy
from test_framework.blocktools import (
create_block,
create_coinbase,
add_witness_commitment,
)
@@ -183,8 +182,8 @@ class MiningTemplateVerificationTest(BitcoinTestFramework):
block_3 = create_block(
int(block_2_hash, 16),
create_coinbase(block_0_height + 3),
block_1["mediantime"] + 1,
height=block_0_height + 3,
ntime=block_1["mediantime"] + 1,
txlist=[tx["hex"]],
)
assert_equal(len(block_3.vtx), 2)
@@ -211,8 +210,8 @@ class MiningTemplateVerificationTest(BitcoinTestFramework):
)
block_3 = create_block(
int(block_2_hash, 16),
create_coinbase(block_0_height + 3),
block_1["mediantime"] + 1,
height=block_0_height + 3,
ntime=block_1["mediantime"] + 1,
txlist=[bad_tx_hex],
)
assert_equal(len(block_3.vtx), 2)
@@ -239,8 +238,8 @@ class MiningTemplateVerificationTest(BitcoinTestFramework):
)
block_3 = create_block(
int(block_2_hash, 16),
create_coinbase(block_0_height + 3),
block_1["mediantime"] + 1,
height=block_0_height + 3,
ntime=block_1["mediantime"] + 1,
txlist=[tx_hex, tx_2_hex],
)
assert_equal(len(block_3.vtx), 3)
@@ -269,8 +268,8 @@ class MiningTemplateVerificationTest(BitcoinTestFramework):
block_1 = node.getblock(node.getbestblockhash())
block_2 = create_block(
int(block_1["hash"], 16),
create_coinbase(block_0_height + 2),
block_1["mediantime"] + 1,
height=block_0_height + 2,
ntime=block_1["mediantime"] + 1,
)
self.valid_block_test(node, block_2)

View File

@@ -10,7 +10,7 @@ the node should pretend that it does not have it to avoid fingerprinting.
import time
from test_framework.blocktools import (create_block, create_coinbase)
from test_framework.blocktools import create_block
from test_framework.messages import CInv, MSG_BLOCK
from test_framework.p2p import (
P2PInterface,
@@ -35,15 +35,13 @@ class P2PFingerprintTest(BitcoinTestFramework):
def build_chain(self, nblocks, prev_hash, prev_height, prev_median_time):
blocks = []
for _ in range(nblocks):
coinbase = create_coinbase(prev_height + 1)
block_time = prev_median_time + 1
block = create_block(int(prev_hash, 16), coinbase, block_time)
block = create_block(int(prev_hash, 16), height=prev_height + 1, ntime=prev_median_time + 1)
block.solve()
blocks.append(block)
prev_hash = block.hash_hex
prev_height += 1
prev_median_time = block_time
prev_median_time += 1
return blocks
# Send a getdata request for a given block hash

View File

@@ -99,7 +99,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
self.log.info("Test very broken block.")
block3 = create_block(tip, create_coinbase(height, nValue=100), block_time)
block3 = create_block(tip, create_coinbase(height, nValue=100), ntime=block_time)
block_time += 1
block3.solve()

View File

@@ -741,7 +741,7 @@ class BlockchainTest(BitcoinTestFramework):
self.log.info("Test getblock when only header is known")
current_height = node.getblock(node.getbestblockhash())['height']
block_time = node.getblock(node.getbestblockhash())['time'] + 1
block = create_block(int(blockhash, 16), create_coinbase(current_height + 1, nValue=100), block_time)
block = create_block(int(blockhash, 16), create_coinbase(current_height + 1, nValue=100), ntime=block_time)
block.solve()
node.submitheader(block.serialize().hex())
assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", lambda: node.getblock(block.hash_hex))
@@ -749,7 +749,7 @@ class BlockchainTest(BitcoinTestFramework):
self.log.info("Test getblock when block data is available but undo data isn't")
# Submits a block building on the header-only block, so it can't be connected and has no undo data
tx = create_tx_with_script(block.vtx[0], 0, script_sig=bytes([OP_TRUE]), amount=50 * COIN)
block_noundo = create_block(block.hash_int, create_coinbase(current_height + 2, nValue=100), block_time + 1, txlist=[tx])
block_noundo = create_block(block.hash_int, create_coinbase(current_height + 2, nValue=100), ntime=block_time + 1, txlist=[tx])
block_noundo.solve()
node.submitblock(block_noundo.serialize().hex())

View File

@@ -69,7 +69,7 @@ class GetChainTipsTest (BitcoinTestFramework):
start_height = self.nodes[0].getblockcount()
# Create invalid block (too high coinbase)
block_time = n0.getblock(n0.getbestblockhash())['time'] + 1
invalid_block = create_block(tip, create_coinbase(start_height+1, nValue=100), block_time)
invalid_block = create_block(tip, create_coinbase(start_height + 1, nValue=100), ntime=block_time)
invalid_block.solve()
block_time += 1

View File

@@ -95,7 +95,7 @@ def nbits_str(nbits):
def target_str(target):
return f"{target:064x}"
def create_block(hashprev=None, coinbase=None, ntime=None, *, height=None, version=None, tmpl=None, txlist=None):
def create_block(hashprev=None, coinbase=None, *, ntime=None, height=None, version=None, tmpl=None, txlist=None):
"""Create a block (with regtest difficulty)."""
block = CBlock()
if tmpl is None: