(self)
| 75 | |
| 76 | |
| 77 | def run_test(self): |
| 78 | node = self.nodes[0] |
| 79 | # Clear disk space warning |
| 80 | node.stderr.seek(0) |
| 81 | node.stderr.truncate() |
| 82 | self.log.info("Load alternative mainnet blocks") |
| 83 | path = os.path.join(os.path.dirname(os.path.realpath(__file__)), self.options.datafile) |
| 84 | prev_hash = node.getbestblockhash() |
| 85 | blocks = None |
| 86 | with open(path) as f: |
| 87 | blocks = json.load(f) |
| 88 | n_blocks = len(blocks['timestamps']) |
| 89 | assert_equal(n_blocks, 2016) |
| 90 | |
| 91 | # Mine up to the last block of the first retarget period |
| 92 | for i in range(2015): |
| 93 | prev_hash = self.mine(i + 1, prev_hash, blocks, node) |
| 94 | |
| 95 | assert_equal(node.getblockcount(), 2015) |
| 96 | |
| 97 | self.log.info("Check difficulty adjustment with getmininginfo") |
| 98 | mining_info = node.getmininginfo() |
| 99 | assert_equal(mining_info['difficulty'], 1) |
| 100 | assert_equal(mining_info['bits'], nbits_str(DIFF_1_N_BITS)) |
| 101 | assert_equal(mining_info['target'], target_str(DIFF_1_TARGET)) |
| 102 | |
| 103 | assert_equal(mining_info['next']['height'], 2016) |
| 104 | assert_equal(mining_info['next']['difficulty'], 4) |
| 105 | assert_equal(mining_info['next']['bits'], nbits_str(DIFF_4_N_BITS)) |
| 106 | assert_equal(mining_info['next']['target'], target_str(DIFF_4_TARGET)) |
| 107 | |
| 108 | # Mine first block of the second retarget period |
| 109 | height = 2016 |
| 110 | prev_hash = self.mine(height, prev_hash, blocks, node) |
| 111 | assert_equal(node.getblockcount(), height) |
| 112 | |
| 113 | mining_info = node.getmininginfo() |
| 114 | assert_equal(mining_info['difficulty'], 4) |
| 115 | |
| 116 | self.log.info("getblock RPC should show historical target") |
| 117 | block_info = node.getblock(node.getblockhash(1)) |
| 118 | |
| 119 | assert_equal(block_info['difficulty'], 1) |
| 120 | assert_equal(block_info['bits'], nbits_str(DIFF_1_N_BITS)) |
| 121 | assert_equal(block_info['target'], target_str(DIFF_1_TARGET)) |
| 122 | |
| 123 | |
| 124 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected