test: add createNewBlock failure helper
What changed, and why it matters
This commit only moves a test helper function from one test file into a shared utility file. It does not change Bitcoin Core's actual code, network behavior, or security properties. It is a pure test-code refactoring with no security relevance.
No action needed; this is a non-security test refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extracts the createNewBlock failure assertion pattern into a reusable helper, assert_create_new_block_fails, in test_framework/ipc_util.py, and updates interface_ipc_mining.py to use it. The logic, error messages, and assertions remain identical. No production code is modified.
Changed components
test/functional/interface_ipc_mining.pytest/functional/test_framework/ipc_util.pyInspect captured patch +12 / −5
diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py
index 389b7f13..e78a21f7 100755
--- a/test/functional/interface_ipc_mining.py
+++ b/test/functional/interface_ipc_mining.py
@@ -30,6 +30,7 @@ from test_framework.wallet import MiniWallet
from test_framework.p2p import P2PInterface
from test_framework.ipc_util import (
assert_capnp_failed,
+ assert_create_new_block_fails,
destroying,
load_capnp_modules,
make_mining_ctx,
@@ -318,11 +319,8 @@ class IPCMiningTest(BitcoinTestFramework):
self.log.debug("Enforce minimum reserved weight for IPC clients too")
opts.blockReservedWeight = 0
- try:
- await mining.createNewBlock(ctx, opts)
- raise AssertionError("createNewBlock unexpectedly succeeded")
- except capnp.lib.capnp.KjException as e:
- assert_capnp_failed(e, "remote exception: std::exception: block_reserved_weight (0) must be at least 2000 weight units")
+ await assert_create_new_block_fails(ctx, mining, opts,
+ "block_reserved_weight (0) must be at least 2000 weight units")
asyncio.run(capnp.run(async_routine()))
diff --git a/test/functional/test_framework/ipc_util.py b/test/functional/test_framework/ipc_util.py
index 340cd15c..5ce58237 100644
--- a/test/functional/test_framework/ipc_util.py
+++ b/test/functional/test_framework/ipc_util.py
@@ -162,3 +162,12 @@ async def make_mining_ctx(self):
def assert_capnp_failed(e, description_prefix):
assert e.description.startswith(description_prefix), f"Expected description starting with '{description_prefix}', got '{e.description}'"
assert_equal(e.type, "FAILED")
+
+
+async def assert_create_new_block_fails(ctx, mining, opts, expected_msg):
+ """Assert that mining.createNewBlock fails with the expected remote exception."""
+ try:
+ await mining.createNewBlock(ctx, opts)
+ raise AssertionError("createNewBlock unexpectedly succeeded")
+ except capnp.lib.capnp.KjException as e:
+ assert_capnp_failed(e, f"remote exception: std::exception: {expected_msg}")
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.