diff --git a/test/functional/interface_zmq.py b/test/functional/interface_zmq.py index f8a6bfc69bc..c9baad338c0 100755 --- a/test/functional/interface_zmq.py +++ b/test/functional/interface_zmq.py @@ -15,7 +15,6 @@ from test_framework.address import ( from test_framework.blocktools import ( add_witness_commitment, create_block, - create_coinbase, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.messages import ( @@ -419,7 +418,7 @@ class ZMQTest (BitcoinTestFramework): bump_txid = self.nodes[0].sendrawtransaction(orig_tx['tx'].serialize().hex()) # Mine the pre-bump tx txs_to_add = [orig_tx['hex']] + [tx['hex'] for tx in more_tx] - block = create_block(int(self.nodes[0].getbestblockhash(), 16), create_coinbase(self.nodes[0].getblockcount()+1), txlist=txs_to_add) + block = create_block(int(self.nodes[0].getbestblockhash(), 16), height=self.nodes[0].getblockcount() + 1, txlist=txs_to_add) add_witness_commitment(block) block.solve() assert_equal(self.nodes[0].submitblock(block.serialize().hex()), None) diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py index cd2caa18ae4..eb1baadfa41 100644 --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -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, *, 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: @@ -108,7 +108,7 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl else: block.nBits = REGTEST_N_BITS if coinbase is None: - coinbase = create_coinbase(height=tmpl['height']) + coinbase = create_coinbase(height=height or tmpl["height"]) block.vtx.append(coinbase) if txlist: for tx in txlist: @@ -278,6 +278,14 @@ def send_to_witness(use_p2wsh, node, utxo, pubkey, encode_p2sh, amount, sign=Tru return node.sendrawtransaction(tx_to_witness) class TestFrameworkBlockTools(unittest.TestCase): + def test_create_block_prefers_explicit_height(self): + block = create_block( + hashprev=1, + tmpl={"height": 100}, + height=200, + ) + assert_equal(CScriptNum.decode(block.vtx[0].vin[0].scriptSig), 200) + def test_create_coinbase(self): height = 20 coinbase_tx = create_coinbase(height=height)