In fac12f7cf9ebc0b906bbb20ae126cf7e7552fdbb test: fix interface_ipc.py template destruction: await stack.enter_async_context(destroying(( is hard to read, so maybe move it into a helper:
diff --git a/test/functional/interface_ipc.py b/test/functional/interface_ipc.py
index 3d28bba136..e01c753d24 100755
--- a/test/functional/interface_ipc.py
+++ b/test/functional/interface_ipc.py
@@ -96,6 +96,14 @@ class IPCInterfaceTest(BitcoinTestFramework):
tx.deserialize(coinbase_data)
return tx
+ async def create_block_template(self, stack, ctx, mining, opts):
+ # Destroyed when stack exits.
+ return await stack.enter_async_context(destroying((await mining.result.createNewBlock(opts)).result, ctx))
+
+ async def wait_next_template(self, stack, ctx, template, waitoptions):
+ # Destroyed when stack exits.
+ return await stack.enter_async_context(destroying((await template.waitNext(ctx, waitoptions)).result, ctx))
+
def run_echo_test(self):
self.log.info("Running echo test")
async def async_routine():
@@ -148,7 +156,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
opts.useMempool = True
opts.blockReservedWeight = 4000
opts.coinbaseOutputMaxAdditionalSigops = 0
- template = await stack.enter_async_context(destroying((await mining.result.createNewBlock(opts)).result, ctx))
+ template = await self.create_block_template(stack, ctx, mining, opts)
self.log.debug("Test some inspectors of Template")
header = await template.getBlockHeader(ctx)
assert_equal(len(header.result), block_header_size)
@@ -168,7 +176,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
waitoptions.timeout = timeout
waitoptions.feeThreshold = 1
self.generate(self.nodes[0], 1)
- template2 = await stack.enter_async_context(destroying((await template.waitNext(ctx, waitoptions)).result, ctx))
+ template2 = await self.wait_next_template(stack, ctx, template, waitoptions)
block2 = await self.parse_and_deserialize_block(template2, ctx)
assert_equal(len(block2.vtx), 1)
self.log.debug("Wait for another, but time out")
@@ -176,18 +184,18 @@ class IPCInterfaceTest(BitcoinTestFramework):
assert_equal(template3.to_dict(), {})
self.log.debug("Wait for another, get one after increase in fees in the mempool")
miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0])
- template4 = await stack.enter_async_context(destroying((await template2.waitNext(ctx, waitoptions)).result, ctx))
+ template4 = await self.wait_next_template(stack, ctx, template2, waitoptions)
block3 = await self.parse_and_deserialize_block(template4, ctx)
assert_equal(len(block3.vtx), 2)
self.log.debug("Wait again, this should return the same template, since the fee threshold is zero")
waitoptions.feeThreshold = 0
- template5 = await stack.enter_async_context(destroying((await template4.waitNext(ctx, waitoptions)).result, ctx))
+ template5 = await self.wait_next_template(stack, ctx, template4, waitoptions)
block4 = await self.parse_and_deserialize_block(template5, ctx)
assert_equal(len(block4.vtx), 2)
waitoptions.feeThreshold = 1
self.log.debug("Wait for another, get one after increase in fees in the mempool")
miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0])
- template6 = await stack.enter_async_context(destroying((await template5.waitNext(ctx, waitoptions)).result, ctx))
+ template6 = await self.wait_next_template(stack, ctx, template5, waitoptions)
block4 = await self.parse_and_deserialize_block(template6, ctx)
assert_equal(len(block4.vtx), 3)
self.log.debug("Wait for another, but time out, since the fee threshold is set now")