diff --git a/test/functional/abc-finalize-block.py b/test/functional/abc-finalize-block.py --- a/test/functional/abc-finalize-block.py +++ b/test/functional/abc-finalize-block.py @@ -113,12 +113,22 @@ # (200 finalized)->(201)-> // ->(209)->(210 tip) node.invalidateblock(tip) node.reconsiderblock(tip) - finalized_block = node.getblockhash( - int(node.getblockheader(tip)['height']) - AUTO_FINALIZATION_DEPTH) - assert_equal(node.getbestblockhash(), tip) - assert_equal( - node.getfinalizedblockhash(), - finalized_block) + + node_best_block_height = node.getblockheader( + node.getbestblockhash())['height'] + node_finalized_block_height = node.getblockheader( + node.getfinalizedblockhash())['height'] + + assert_equal(node_best_block_height, 210) + assert_equal(node_finalized_block_height, 200) + + alt_node_best_block_height = alt_node.getblockheader( + alt_node.getbestblockhash())['height'] + alt_node_finalized_block_height = alt_node.getblockheader( + alt_node.getfinalizedblockhash())['height'] + + assert_equal(alt_node_best_block_height, 218) + assert_equal(alt_node_finalized_block_height, 208) # The node will now accept that chain as the finalized block moved back. # Generate a new block on alt_node to trigger getheader from node @@ -127,9 +137,9 @@ # Expected state: # # On alt_node: - # >(210)->(211)-> // ->(218)->(219 tip) - # / - # (200)->(201)-> // ->(208 auto-finalized)->(209)->(210 invalid) + # >(210)->(211)-> // ->(218)->(219 tip) + # / + # (200)->(201)-> // ->(209 auto-finalized)->(210 invalid) # # On node: # >(210)->(211)->(212)-> // ->(218)->(219 tip) @@ -139,8 +149,10 @@ alt_node.generate(1) sync_blocks(self.nodes[0:2]) + assert_equal(node.getbestblockhash(), alt_node.getbestblockhash()) assert_equal(node.getfinalizedblockhash(), auto_finalized_tip) + assert_equal(alt_node.getfinalizedblockhash(), auto_finalized_tip) self.log.info("Trigger reorg via block finalization...") # Finalizing the tip will move the finalized block maxreorgdepth backward and @@ -148,25 +160,29 @@ # Expected state: # # On alt_node: - # >(210)->(211)-> // ->(218)->(219 tip) - # / - # (200)->(201)-> // ->(209)->(210 invalid) + # >(210)->(211)-> // ->(218)->(219 tip) + # / + # (200)->(201)-> // ->(209 auto-finalized)->(210 invalid) # # On node: # >(210 invalid)->(211 invalid)->(212 invalid)-> // ->(219 invalid) # / # (200 finalized)->(201)-> // ->(209)->(210 tip) node.finalizeblock(tip) - assert_equal(node.getbestblockhash(), tip) - assert_equal(node.getfinalizedblockhash(), - finalized_block) + + node_best_block_height = node.getblockheader( + node.getbestblockhash())['height'] + node_finalized_block_height = node.getblockheader( + node.getfinalizedblockhash())['height'] + + assert_equal(node_best_block_height, 210) + assert_equal(node_finalized_block_height, 200) self.log.info("Try to finalize a block on a competiting fork...") assert_raises_rpc_error(-20, RPC_FINALIZE_INVALID_BLOCK_ERROR, node.finalizeblock, alt_node.getbestblockhash()) assert node.getfinalizedblockhash() != alt_node.getbestblockhash(), \ "Finalize block is alt_node's tip!" - assert_equal(node.getfinalizedblockhash(), finalized_block) self.log.info( "Make sure reconsidering block move the finalization point...") @@ -174,14 +190,14 @@ # Expected state: # # On alt_node: - # >(210)->(211)-> // ->(218)->(219 tip) - # / - # (200)->(201)-> // ->(209)->(210 invalid) + # >(210)->(211)-> // ->(218)->(219 tip) + # / + # (200)->(201)-> // ->(209 auto-finalized)->(210 invalid) # # On node: - # >(210)->(211)->(212)-> // ->(219 tip) - # / - # (200)->(201)-> // ->(209 finalized)->(210 invalid) + # >(210)->(211)->(212)-> // ->(219 tip) + # / + # (200)->(201)-> // ->(209 auto-finalized)->(210) node.reconsiderblock(alt_node.getbestblockhash()) assert_equal(node.getbestblockhash(), alt_node.getbestblockhash()) assert_equal(node.getfinalizedblockhash(), auto_finalized_tip)