Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-invalid-chains.py
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
node.invalidateblock(self.blocks[1].hash) | node.invalidateblock(self.blocks[1].hash) | ||||
assert_equal(self.blocks[0].hash, node.getbestblockhash()) | assert_equal(self.blocks[0].hash, node.getbestblockhash()) | ||||
node.invalidateblock(self.blocks[2].hash) | node.invalidateblock(self.blocks[2].hash) | ||||
assert_equal(self.blocks[0].hash, node.getbestblockhash()) | assert_equal(self.blocks[0].hash, node.getbestblockhash()) | ||||
# Mining on top of blocks 1 or 2 is rejected | # Mining on top of blocks 1 or 2 is rejected | ||||
tip(1) | tip(1) | ||||
node.p2p.send_blocks_and_test( | node.p2p.send_blocks_and_test( | ||||
[block(11)], node, success=False, reject_reason='bad-prevblk', request_block=False) | [block(11)], node, success=False, force_send=True, reject_reason='bad-prevblk') | ||||
tip(2) | tip(2) | ||||
node.p2p.send_blocks_and_test( | node.p2p.send_blocks_and_test( | ||||
[block(21)], node, success=False, reject_reason='bad-prevblk', request_block=False) | [block(21)], node, success=False, force_send=True, reject_reason='bad-prevblk') | ||||
# Reconsider block 2 to remove invalid status from *both* 1 and 2 | # Reconsider block 2 to remove invalid status from *both* 1 and 2 | ||||
# The goal is to test that block 1 is not retaining any internal state | # The goal is to test that block 1 is not retaining any internal state | ||||
# that prevents us from accepting blocks building on top of block 1 | # that prevents us from accepting blocks building on top of block 1 | ||||
node.reconsiderblock(self.blocks[2].hash) | node.reconsiderblock(self.blocks[2].hash) | ||||
assert_equal(self.blocks[2].hash, node.getbestblockhash()) | assert_equal(self.blocks[2].hash, node.getbestblockhash()) | ||||
# Mining on the block 1 chain should be accepted | # Mining on the block 1 chain should be accepted | ||||
Show All 17 Lines | def run_test(self): | ||||
# Invalidating the block 2 chain should reject new blocks on that chain | # Invalidating the block 2 chain should reject new blocks on that chain | ||||
node.invalidateblock(self.blocks[2].hash) | node.invalidateblock(self.blocks[2].hash) | ||||
assert_equal(self.blocks[13].hash, node.getbestblockhash()) | assert_equal(self.blocks[13].hash, node.getbestblockhash()) | ||||
# Mining on the block 2 chain should be rejected | # Mining on the block 2 chain should be rejected | ||||
tip(24) | tip(24) | ||||
node.p2p.send_blocks_and_test( | node.p2p.send_blocks_and_test( | ||||
[block(25)], node, success=False, reject_reason='bad-prevblk', request_block=False) | [block(25)], node, success=False, force_send=True, reject_reason='bad-prevblk') | ||||
# Continued mining on the block 1 chain is still ok | # Continued mining on the block 1 chain is still ok | ||||
tip(13) | tip(13) | ||||
node.p2p.send_blocks_and_test([block(14)], node) | node.p2p.send_blocks_and_test([block(14)], node) | ||||
# Mining on a once-valid chain forking from block 2's longest chain, | # Mining on a once-valid chain forking from block 2's longest chain, | ||||
# which is now invalid, should also be rejected. | # which is now invalid, should also be rejected. | ||||
tip(221) | tip(221) | ||||
node.p2p.send_blocks_and_test( | node.p2p.send_blocks_and_test( | ||||
[block(222)], node, success=False, reject_reason='bad-prevblk', request_block=False) | [block(222)], node, success=False, force_send=True, reject_reason='bad-prevblk') | ||||
self.log.info( | self.log.info( | ||||
"Make sure that reconsidering a block behaves correctly when cousin chains (neither ancestors nor descendants) become available as a result") | "Make sure that reconsidering a block behaves correctly when cousin chains (neither ancestors nor descendants) become available as a result") | ||||
# Reorg out 14 with four blocks. | # Reorg out 14 with four blocks. | ||||
tip(13) | tip(13) | ||||
node.p2p.send_blocks_and_test( | node.p2p.send_blocks_and_test( | ||||
[block(15), block(16), block(17), block(18)], node) | [block(15), block(16), block(17), block(18)], node) | ||||
Show All 19 Lines |