|
| 1 | +""" |
| 2 | +invalidateblock.py |
| 3 | +
|
| 4 | +Test the `invalidateblock` RPC on florestad. |
| 5 | +
|
| 6 | +We mine blocks via utreexod, sync them to florestad, then call `invalidateblock` |
| 7 | +on florestad to mark a block as invalid. We verify that florestad's tip rolls back |
| 8 | +to the parent of the invalidated block. |
| 9 | +""" |
| 10 | + |
| 11 | +import time |
| 12 | + |
| 13 | +from test_framework import FlorestaTestFramework |
| 14 | +from test_framework.node import NodeType |
| 15 | + |
| 16 | + |
| 17 | +class InvalidateBlockTest(FlorestaTestFramework): |
| 18 | + """Test that invalidateblock marks a block invalid and rolls back the tip.""" |
| 19 | + |
| 20 | + def set_test_params(self): |
| 21 | + self.florestad = self.add_node_default_args(variant=NodeType.FLORESTAD) |
| 22 | + self.utreexod = self.add_node_extra_args( |
| 23 | + variant=NodeType.UTREEXOD, |
| 24 | + extra_args=[ |
| 25 | + "--miningaddr=bcrt1q4gfcga7jfjmm02zpvrh4ttc5k7lmnq2re52z2y", |
| 26 | + "--utreexoproofindex", |
| 27 | + "--prune=0", |
| 28 | + ], |
| 29 | + ) |
| 30 | + |
| 31 | + def run_test(self): |
| 32 | + self.run_node(self.florestad) |
| 33 | + self.run_node(self.utreexod) |
| 34 | + |
| 35 | + # Mine 10 blocks on utreexod and sync to florestad |
| 36 | + self.log("=== Mining 10 blocks with utreexod") |
| 37 | + self.utreexod.rpc.generate(10) |
| 38 | + |
| 39 | + self.log("=== Connecting florestad to utreexod") |
| 40 | + self.connect_nodes(self.florestad, self.utreexod) |
| 41 | + |
| 42 | + self.log("=== Waiting for sync") |
| 43 | + time.sleep(20) |
| 44 | + |
| 45 | + # Verify both nodes are synced |
| 46 | + floresta_info = self.florestad.rpc.get_blockchain_info() |
| 47 | + utreexo_info = self.utreexod.rpc.get_blockchain_info() |
| 48 | + self.assertEqual(floresta_info["height"], utreexo_info["blocks"]) |
| 49 | + self.assertEqual(floresta_info["best_block"], utreexo_info["bestblockhash"]) |
| 50 | + |
| 51 | + # Get the hash of block 5 and its parent (block 4) |
| 52 | + hash_at_5 = self.florestad.rpc.get_blockhash(5) |
| 53 | + hash_at_4 = self.florestad.rpc.get_blockhash(4) |
| 54 | + |
| 55 | + # Invalidate block 5 on florestad |
| 56 | + self.log(f"=== Invalidating block at height 5: {hash_at_5}") |
| 57 | + self.florestad.rpc.invalidate_block(hash_at_5) |
| 58 | + |
| 59 | + # Verify florestad's tip rolled back to block 4 |
| 60 | + new_info = self.florestad.rpc.get_blockchain_info() |
| 61 | + self.assertEqual(new_info["height"], 4) |
| 62 | + self.assertEqual(new_info["best_block"], hash_at_4) |
| 63 | + |
| 64 | + self.log("=== invalidateblock test passed") |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + InvalidateBlockTest().main() |
0 commit comments