test: misc interface_ipc_mining.py improvements
What changed, and why it matters
This is a routine cleanup of a Bitcoin Core functional test file. It moves shared test setup out of individual test methods, fixes a couple of log comments, and replaces a plain Python assert with a proper test-framework assertion. There is no change to production code or to any security-sensitive behavior.
No security action needed. Treat as normal test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors test/functional/interface_ipc_mining.py: a MiniWallet instance and default BlockCreateOptions are now created once in run_test() and reused via self.*. It also corrects two debug log strings that incorrectly said submitBlock() instead of submitSolution(), switches one assert to assert_equal, and fixes a timeout calculation to use the local timeout variable. All changes are confined to test code; no node logic, consensus code, or interfaces are modified.
Changed components
test/functional/interface_ipc_mining.pyInspect captured patch +19 / −22
diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py
index b12dd9c8..20f90490 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()
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.