|
6 | 6 |
|
7 | 7 | from test_framework.test_framework import BitcoinTestFramework
|
8 | 8 | from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR
|
| 9 | +from test_framework.blocktools import ( |
| 10 | + create_block, |
| 11 | + create_coinbase, |
| 12 | +) |
9 | 13 | from test_framework.util import (
|
10 | 14 | assert_equal,
|
11 | 15 | assert_raises_rpc_error,
|
@@ -35,15 +39,34 @@ def run_test(self):
|
35 | 39 | self.connect_nodes(0, 1)
|
36 | 40 | self.sync_blocks(self.nodes[0:2])
|
37 | 41 | assert_equal(self.nodes[0].getblockcount(), 6)
|
38 |
| - badhash = self.nodes[1].getblockhash(2) |
| 42 | + |
| 43 | + # Add a header to the tip of node 0 without submitting the block. This shouldn't |
| 44 | + # affect results since this chain will be invalidated next. |
| 45 | + tip = self.nodes[0].getbestblockhash() |
| 46 | + block_time = self.nodes[0].getblock(self.nodes[0].getbestblockhash())['time'] + 1 |
| 47 | + block = create_block(int(tip, 16), create_coinbase(self.nodes[0].getblockcount()), block_time, version=4) |
| 48 | + block.solve() |
| 49 | + self.nodes[0].submitheader(block.serialize().hex()) |
| 50 | + assert_equal(self.nodes[0].getblockchaininfo()["headers"], self.nodes[0].getblockchaininfo()["blocks"] + 1) |
39 | 51 |
|
40 | 52 | self.log.info("Invalidate block 2 on node 0 and verify we reorg to node 0's original chain")
|
| 53 | + badhash = self.nodes[1].getblockhash(2) |
41 | 54 | self.nodes[0].invalidateblock(badhash)
|
42 | 55 | assert_equal(self.nodes[0].getblockcount(), 4)
|
43 | 56 | assert_equal(self.nodes[0].getbestblockhash(), besthash_n0)
|
44 | 57 | # Should report consistent blockchain info
|
45 | 58 | assert_equal(self.nodes[0].getblockchaininfo()["headers"], self.nodes[0].getblockchaininfo()["blocks"])
|
46 | 59 |
|
| 60 | + self.log.info("Reconsider block 6 on node 0 again and verify that the best header is set correctly") |
| 61 | + self.nodes[0].reconsiderblock(tip) |
| 62 | + assert_equal(self.nodes[0].getblockchaininfo()["headers"], self.nodes[0].getblockchaininfo()["blocks"] + 1) |
| 63 | + |
| 64 | + self.log.info("Invalidate block 2 on node 0 and verify we reorg to node 0's original chain again") |
| 65 | + self.nodes[0].invalidateblock(badhash) |
| 66 | + assert_equal(self.nodes[0].getblockcount(), 4) |
| 67 | + assert_equal(self.nodes[0].getbestblockhash(), besthash_n0) |
| 68 | + assert_equal(self.nodes[0].getblockchaininfo()["headers"], self.nodes[0].getblockchaininfo()["blocks"]) |
| 69 | + |
47 | 70 | self.log.info("Make sure we won't reorg to a lower work chain:")
|
48 | 71 | self.connect_nodes(1, 2)
|
49 | 72 | self.log.info("Sync node 2 to node 1 so both have 6 blocks")
|
|
0 commit comments