Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-finalize-block.py
Show All 36 Lines | def run_test(self): | ||||
alt_node = self.nodes[1] | alt_node = self.nodes[1] | ||||
connect_nodes_bi(self.nodes, 0, 1) | connect_nodes_bi(self.nodes, 0, 1) | ||||
sync_blocks(self.nodes[0:2]) | sync_blocks(self.nodes[0:2]) | ||||
alt_node.invalidateblock(tip) | alt_node.invalidateblock(tip) | ||||
alt_node.generate(10) | alt_node.generate(10) | ||||
# Wait for node 0 to invalidate the chain. | # Wait for node 0 to invalidate the chain. | ||||
def wait_for_invalid_block(block): | def wait_for_invalid_block(node, block): | ||||
def check_block(): | def check_block(): | ||||
for tip in node.getchaintips(): | for tip in node.getchaintips(): | ||||
if tip["hash"] == block: | if tip["hash"] == block: | ||||
assert(tip["status"] != "active") | assert(tip["status"] != "active") | ||||
return tip["status"] == "invalid" | return tip["status"] == "invalid" | ||||
return False | return False | ||||
wait_until(check_block) | wait_until(check_block) | ||||
wait_for_invalid_block(alt_node.getbestblockhash()) | # node do not accept alt_node's chain due to tip being finalized, | ||||
# even though it is longer. | |||||
wait_for_invalid_block(node, alt_node.getbestblockhash()) | |||||
assert_equal(node.getbestblockhash(), tip) | |||||
# alt_node has mined 10 block, so tip must be invalid due to finalization. | |||||
wait_for_invalid_block(alt_node, tip) | |||||
self.log.info("Test that an invalid block cannot be finalized...") | self.log.info("Test that an invalid block cannot be finalized...") | ||||
assert_raises_rpc_error(-20, RPC_FINALIZE_INVALID_BLOCK_ERROR, | assert_raises_rpc_error(-20, RPC_FINALIZE_INVALID_BLOCK_ERROR, | ||||
node.finalizeblock, alt_node.getbestblockhash()) | node.finalizeblock, alt_node.getbestblockhash()) | ||||
self.log.info( | self.log.info( | ||||
"Test that invalidating a finalized block moves the finalization backward...") | "Test that invalidating a finalized block moves the finalization backward...") | ||||
node.invalidateblock(tip) | node.invalidateblock(tip) | ||||
Show All 18 Lines |