test: add createNewBlock failure helper

Move the IPC createNewBlock failure assertion into ipc_util.py so
later invalid mining option tests can share the same remote exception check.
This commit is contained in:
Sjors Provoost
2026-03-25 18:10:10 +01:00
parent 63ee9cd15b
commit 24750f8b31
2 changed files with 12 additions and 5 deletions

View File

@@ -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()))

View File

@@ -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}")