From 633d1831199a2ca6ca31b97312130419328d5479 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Fri, 6 Feb 2026 14:10:27 +0100 Subject: [PATCH] test: misc interface_ipc_mining.py improvements - share miniwallet and block create options between tests - documentation fixes - use assert_equal instead of assert == --- test/functional/interface_ipc_mining.py | 41 ++++++++++++------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py index b12dd9c8619..20f90490514 100755 --- a/test/functional/interface_ipc_mining.py +++ b/test/functional/interface_ipc_mining.py @@ -131,7 +131,7 @@ class IPCMiningTest(BitcoinTestFramework): ctx, mining = await self.make_mining_ctx() blockref = await mining.getTip(ctx) current_block_height = self.nodes[0].getchaintips()[0]["height"] - assert blockref.result.height == current_block_height + assert_equal(blockref.result.height, current_block_height) self.log.debug("Mine a block") newblockref = (await wait_and_do( @@ -152,7 +152,6 @@ class IPCMiningTest(BitcoinTestFramework): self.log.info("Running BlockTemplate interface test") block_header_size = 80 timeout = 1000.0 # 1000 milliseconds - miniwallet = MiniWallet(self.nodes[0]) async def async_routine(): ctx, mining = await self.make_mining_ctx() @@ -160,11 +159,7 @@ class IPCMiningTest(BitcoinTestFramework): async with AsyncExitStack() as stack: self.log.debug("Create a template") - opts = self.capnp_modules['mining'].BlockCreateOptions() - opts.useMempool = True - opts.blockReservedWeight = 4000 - opts.coinbaseOutputMaxAdditionalSigops = 0 - template = await mining_create_block_template(mining, stack, ctx, opts) + template = await mining_create_block_template(mining, stack, ctx, self.default_block_create_options) self.log.debug("Test some inspectors of Template") header = (await template.getBlockHeader(ctx)).result @@ -194,7 +189,7 @@ class IPCMiningTest(BitcoinTestFramework): self.log.debug("Wait for another, get one after increase in fees in the mempool") template4 = await wait_and_do( mining_wait_next_template(template2, stack, ctx, waitoptions), - lambda: miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0])) + lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0])) block3 = await mining_get_block(template4, ctx) assert_equal(len(block3.vtx), 2) @@ -208,7 +203,7 @@ class IPCMiningTest(BitcoinTestFramework): self.log.debug("Wait for another, get one after increase in fees in the mempool") template6 = await wait_and_do( mining_wait_next_template(template5, stack, ctx, waitoptions), - lambda: miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0])) + lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0])) block4 = await mining_get_block(template6, ctx) assert_equal(len(block4.vtx), 3) @@ -219,7 +214,7 @@ class IPCMiningTest(BitcoinTestFramework): self.log.debug("interruptWait should abort the current wait") async def wait_for_block(): new_waitoptions = self.capnp_modules['mining'].BlockWaitOptions() - new_waitoptions.timeout = waitoptions.timeout * 60 # 1 minute wait + new_waitoptions.timeout = timeout * 60 # 1 minute wait new_waitoptions.feeThreshold = 1 template7 = await template6.waitNext(ctx, new_waitoptions) assert_equal(template7._has("result"), False) @@ -235,17 +230,12 @@ class IPCMiningTest(BitcoinTestFramework): ctx, mining = await self.make_mining_ctx() current_block_height = self.nodes[0].getchaintips()[0]["height"] - miniwallet = MiniWallet(self.nodes[0]) - opts = self.capnp_modules['mining'].BlockCreateOptions() - opts.useMempool = True - opts.blockReservedWeight = 4000 - opts.coinbaseOutputMaxAdditionalSigops = 0 check_opts = self.capnp_modules['mining'].BlockCheckOptions() - async with destroying((await mining.createNewBlock(opts)).result, ctx) as template: + async with destroying((await mining.createNewBlock(self.default_block_create_options)).result, ctx) as template: block = await mining_get_block(template, ctx) - balance = miniwallet.get_balance() - coinbase = await self.build_coinbase_test(template, ctx, miniwallet) + balance = self.miniwallet.get_balance() + coinbase = await self.build_coinbase_test(template, ctx, self.miniwallet) # Reduce payout for balance comparison simplicity coinbase.vout[0].nValue = COIN block.vtx[0] = coinbase @@ -276,7 +266,7 @@ class IPCMiningTest(BitcoinTestFramework): submitted = (await template.submitSolution(ctx, block.nVersion, block.nTime, block.nNonce, coinbase.serialize_without_witness())).result assert_equal(submitted, False) - self.log.debug("Even a rejected submitBlock() mutates the template's block") + self.log.debug("Even a rejected submitSolution() mutates the template's block") # Can be used by clients to download and inspect the (rejected) # reconstructed block. remote_block_after = await mining_get_block(template, ctx) @@ -289,13 +279,13 @@ class IPCMiningTest(BitcoinTestFramework): self.log.debug("Block should propagate") # Check that the IPC node actually updates its own chain assert_equal(self.nodes[0].getchaintips()[0]["height"], current_block_height + 1) - # Stalls if a regression causes submitBlock() to accept an invalid block: + # Stalls if a regression causes submitSolution() to accept an invalid block: self.sync_all() # Check that the other node accepts the block assert_equal(self.nodes[0].getchaintips()[0], self.nodes[1].getchaintips()[0]) - miniwallet.rescan_utxos() - assert_equal(miniwallet.get_balance(), balance + 1) + self.miniwallet.rescan_utxos() + assert_equal(self.miniwallet.get_balance(), balance + 1) self.log.debug("Check block should fail now, since it is a duplicate") check = await mining.checkBlock(block.serialize(), check_opts) assert_equal(check.result, False) @@ -304,6 +294,13 @@ class IPCMiningTest(BitcoinTestFramework): asyncio.run(capnp.run(async_routine())) def run_test(self): + self.miniwallet = MiniWallet(self.nodes[0]) + self.default_block_create_options = self.capnp_modules['mining'].BlockCreateOptions( + useMempool=True, + blockReservedWeight=4000, + coinbaseOutputMaxAdditionalSigops=0 + ) + self.run_mining_interface_test() self.run_block_template_test() self.run_coinbase_and_submission_test()