test: move make_mining_ctx to ipc_util.py

The async routines in both interface_ipc.py and interface_ipc_mining.py
contain redundant code to initialize the mining proxy object.

Move the make_mining_ctx helper into test_framework/ipc_util.py and
update both test files to use it. This removes the boilerplate and
prevents code duplication across the IPC test suite.
This commit is contained in:
Enoch Azariah
2026-03-04 00:41:08 +01:00
parent 4ada575d6c
commit 63684d6922
3 changed files with 17 additions and 24 deletions

View File

@@ -11,6 +11,7 @@ from test_framework.util import assert_equal
from test_framework.ipc_util import (
load_capnp_modules,
make_capnp_init_ctx,
make_mining_ctx,
)
# Test may be skipped and not have capnp installed
@@ -55,9 +56,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
block_hash_size = 32
async def async_routine():
ctx, init = await make_capnp_init_ctx(self)
self.log.debug("Create Mining proxy object")
mining = init.makeMining(ctx).result
ctx, mining = await make_mining_ctx(self)
self.log.debug("Test simple inspectors")
assert (await mining.isTestChain(ctx)).result
assert not (await mining.isInitialBlockDownload(ctx)).result
@@ -93,10 +92,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
disconnected_log_check = ExitStack()
async def async_routine():
ctx, init = await make_capnp_init_ctx(self)
self.log.debug("Create Mining proxy object")
mining = init.makeMining(ctx).result
ctx, mining = await make_mining_ctx(self)
self.log.debug("Create a template")
opts = self.capnp_modules['mining'].BlockCreateOptions()
template = (await mining.createNewBlock(ctx, opts)).result
@@ -129,10 +125,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
timeout = self.rpc_timeout * 1000.0
async def async_routine():
ctx, init = await make_capnp_init_ctx(self)
self.log.debug("Create Mining proxy object")
mining = init.makeMining(ctx).result
ctx, mining = await make_mining_ctx(self)
self.log.debug("Create a template")
opts = self.capnp_modules['mining'].BlockCreateOptions()
template = (await mining.createNewBlock(ctx, opts)).result