test: misc interface_ipc_mining.py improvements
- share miniwallet and block create options between tests - documentation fixes - use assert_equal instead of assert ==
This commit is contained in:
1 file changed
+19
-22
@@ -131,7 +131,7 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
ctx, mining = await self.make_mining_ctx()
|
ctx, mining = await self.make_mining_ctx()
|
||||||
blockref = await mining.getTip(ctx)
|
blockref = await mining.getTip(ctx)
|
||||||
current_block_height = self.nodes[0].getchaintips()[0]["height"]
|
current_block_height = self.nodes[0].getchaintips()[0]["height"]
|
||||||
assert blockref.result.height == current_block_height
|
assert_equal(blockref.result.height, current_block_height)
|
||||||
|
|
||||||
self.log.debug("Mine a block")
|
self.log.debug("Mine a block")
|
||||||
newblockref = (await wait_and_do(
|
newblockref = (await wait_and_do(
|
||||||
@@ -152,7 +152,6 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
self.log.info("Running BlockTemplate interface test")
|
self.log.info("Running BlockTemplate interface test")
|
||||||
block_header_size = 80
|
block_header_size = 80
|
||||||
timeout = 1000.0 # 1000 milliseconds
|
timeout = 1000.0 # 1000 milliseconds
|
||||||
miniwallet = MiniWallet(self.nodes[0])
|
|
||||||
|
|
||||||
async def async_routine():
|
async def async_routine():
|
||||||
ctx, mining = await self.make_mining_ctx()
|
ctx, mining = await self.make_mining_ctx()
|
||||||
@@ -160,11 +159,7 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
async with AsyncExitStack() as stack:
|
async with AsyncExitStack() as stack:
|
||||||
self.log.debug("Create a template")
|
self.log.debug("Create a template")
|
||||||
opts = self.capnp_modules['mining'].BlockCreateOptions()
|
template = await mining_create_block_template(mining, stack, ctx, self.default_block_create_options)
|
||||||
opts.useMempool = True
|
|
||||||
opts.blockReservedWeight = 4000
|
|
||||||
opts.coinbaseOutputMaxAdditionalSigops = 0
|
|
||||||
template = await mining_create_block_template(mining, stack, ctx, opts)
|
|
||||||
|
|
||||||
self.log.debug("Test some inspectors of Template")
|
self.log.debug("Test some inspectors of Template")
|
||||||
header = (await template.getBlockHeader(ctx)).result
|
header = (await template.getBlockHeader(ctx)).result
|
||||||
@@ -194,7 +189,7 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
self.log.debug("Wait for another, get one after increase in fees in the mempool")
|
self.log.debug("Wait for another, get one after increase in fees in the mempool")
|
||||||
template4 = await wait_and_do(
|
template4 = await wait_and_do(
|
||||||
mining_wait_next_template(template2, stack, ctx, waitoptions),
|
mining_wait_next_template(template2, stack, ctx, waitoptions),
|
||||||
lambda: miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
|
lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
|
||||||
block3 = await mining_get_block(template4, ctx)
|
block3 = await mining_get_block(template4, ctx)
|
||||||
assert_equal(len(block3.vtx), 2)
|
assert_equal(len(block3.vtx), 2)
|
||||||
|
|
||||||
@@ -208,7 +203,7 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
self.log.debug("Wait for another, get one after increase in fees in the mempool")
|
self.log.debug("Wait for another, get one after increase in fees in the mempool")
|
||||||
template6 = await wait_and_do(
|
template6 = await wait_and_do(
|
||||||
mining_wait_next_template(template5, stack, ctx, waitoptions),
|
mining_wait_next_template(template5, stack, ctx, waitoptions),
|
||||||
lambda: miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
|
lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
|
||||||
block4 = await mining_get_block(template6, ctx)
|
block4 = await mining_get_block(template6, ctx)
|
||||||
assert_equal(len(block4.vtx), 3)
|
assert_equal(len(block4.vtx), 3)
|
||||||
|
|
||||||
@@ -219,7 +214,7 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
self.log.debug("interruptWait should abort the current wait")
|
self.log.debug("interruptWait should abort the current wait")
|
||||||
async def wait_for_block():
|
async def wait_for_block():
|
||||||
new_waitoptions = self.capnp_modules['mining'].BlockWaitOptions()
|
new_waitoptions = self.capnp_modules['mining'].BlockWaitOptions()
|
||||||
new_waitoptions.timeout = waitoptions.timeout * 60 # 1 minute wait
|
new_waitoptions.timeout = timeout * 60 # 1 minute wait
|
||||||
new_waitoptions.feeThreshold = 1
|
new_waitoptions.feeThreshold = 1
|
||||||
template7 = await template6.waitNext(ctx, new_waitoptions)
|
template7 = await template6.waitNext(ctx, new_waitoptions)
|
||||||
assert_equal(template7._has("result"), False)
|
assert_equal(template7._has("result"), False)
|
||||||
@@ -235,17 +230,12 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
ctx, mining = await self.make_mining_ctx()
|
ctx, mining = await self.make_mining_ctx()
|
||||||
|
|
||||||
current_block_height = self.nodes[0].getchaintips()[0]["height"]
|
current_block_height = self.nodes[0].getchaintips()[0]["height"]
|
||||||
miniwallet = MiniWallet(self.nodes[0])
|
|
||||||
opts = self.capnp_modules['mining'].BlockCreateOptions()
|
|
||||||
opts.useMempool = True
|
|
||||||
opts.blockReservedWeight = 4000
|
|
||||||
opts.coinbaseOutputMaxAdditionalSigops = 0
|
|
||||||
check_opts = self.capnp_modules['mining'].BlockCheckOptions()
|
check_opts = self.capnp_modules['mining'].BlockCheckOptions()
|
||||||
|
|
||||||
async with destroying((await mining.createNewBlock(opts)).result, ctx) as template:
|
async with destroying((await mining.createNewBlock(self.default_block_create_options)).result, ctx) as template:
|
||||||
block = await mining_get_block(template, ctx)
|
block = await mining_get_block(template, ctx)
|
||||||
balance = miniwallet.get_balance()
|
balance = self.miniwallet.get_balance()
|
||||||
coinbase = await self.build_coinbase_test(template, ctx, miniwallet)
|
coinbase = await self.build_coinbase_test(template, ctx, self.miniwallet)
|
||||||
# Reduce payout for balance comparison simplicity
|
# Reduce payout for balance comparison simplicity
|
||||||
coinbase.vout[0].nValue = COIN
|
coinbase.vout[0].nValue = COIN
|
||||||
block.vtx[0] = coinbase
|
block.vtx[0] = coinbase
|
||||||
@@ -276,7 +266,7 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
submitted = (await template.submitSolution(ctx, block.nVersion, block.nTime, block.nNonce, coinbase.serialize_without_witness())).result
|
submitted = (await template.submitSolution(ctx, block.nVersion, block.nTime, block.nNonce, coinbase.serialize_without_witness())).result
|
||||||
assert_equal(submitted, False)
|
assert_equal(submitted, False)
|
||||||
|
|
||||||
self.log.debug("Even a rejected submitBlock() mutates the template's block")
|
self.log.debug("Even a rejected submitSolution() mutates the template's block")
|
||||||
# Can be used by clients to download and inspect the (rejected)
|
# Can be used by clients to download and inspect the (rejected)
|
||||||
# reconstructed block.
|
# reconstructed block.
|
||||||
remote_block_after = await mining_get_block(template, ctx)
|
remote_block_after = await mining_get_block(template, ctx)
|
||||||
@@ -289,13 +279,13 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
self.log.debug("Block should propagate")
|
self.log.debug("Block should propagate")
|
||||||
# Check that the IPC node actually updates its own chain
|
# Check that the IPC node actually updates its own chain
|
||||||
assert_equal(self.nodes[0].getchaintips()[0]["height"], current_block_height + 1)
|
assert_equal(self.nodes[0].getchaintips()[0]["height"], current_block_height + 1)
|
||||||
# Stalls if a regression causes submitBlock() to accept an invalid block:
|
# Stalls if a regression causes submitSolution() to accept an invalid block:
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
# Check that the other node accepts the block
|
# Check that the other node accepts the block
|
||||||
assert_equal(self.nodes[0].getchaintips()[0], self.nodes[1].getchaintips()[0])
|
assert_equal(self.nodes[0].getchaintips()[0], self.nodes[1].getchaintips()[0])
|
||||||
|
|
||||||
miniwallet.rescan_utxos()
|
self.miniwallet.rescan_utxos()
|
||||||
assert_equal(miniwallet.get_balance(), balance + 1)
|
assert_equal(self.miniwallet.get_balance(), balance + 1)
|
||||||
self.log.debug("Check block should fail now, since it is a duplicate")
|
self.log.debug("Check block should fail now, since it is a duplicate")
|
||||||
check = await mining.checkBlock(block.serialize(), check_opts)
|
check = await mining.checkBlock(block.serialize(), check_opts)
|
||||||
assert_equal(check.result, False)
|
assert_equal(check.result, False)
|
||||||
@@ -304,6 +294,13 @@ class IPCMiningTest(BitcoinTestFramework):
|
|||||||
asyncio.run(capnp.run(async_routine()))
|
asyncio.run(capnp.run(async_routine()))
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
self.miniwallet = MiniWallet(self.nodes[0])
|
||||||
|
self.default_block_create_options = self.capnp_modules['mining'].BlockCreateOptions(
|
||||||
|
useMempool=True,
|
||||||
|
blockReservedWeight=4000,
|
||||||
|
coinbaseOutputMaxAdditionalSigops=0
|
||||||
|
)
|
||||||
|
|
||||||
self.run_mining_interface_test()
|
self.run_mining_interface_test()
|
||||||
self.run_block_template_test()
|
self.run_block_template_test()
|
||||||
self.run_coinbase_and_submission_test()
|
self.run_coinbase_and_submission_test()
|
||||||
|
|||||||
Reference in new issue
Block a user