mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-27 22:34:18 +02:00
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:
@@ -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()))
|
||||
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user