Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add coverage for rpc error when trying to rescan beyond pruned data #25937

Merged
merged 1 commit into from Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/functional/feature_pruning.py
Expand Up @@ -143,6 +143,10 @@ def test_invalid_command_line_options(self):
extra_args=['-prune=550', '-reindex-chainstate'],
)

def test_rescan_blockchain(self):
self.restart_node(0, ["-prune=550"])
assert_raises_rpc_error(-1, "Can't rescan beyond pruned data. Use RPC call getblockchaininfo to determine your pruned height.", self.nodes[0].rescanblockchain)
brunoerg marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to explain in a docstring or comment why this assert will fail here.

If helpful, here is the result of printing getblockchaininfo at this point.

    def test_rescan_blockchain(self):
        self.restart_node(0, ["-prune=550"])
+        import pprint
+        pprint.pprint(self.nodes[0].getblockchaininfo())
         assert_raises_rpc_error(-1, "Can't rescan beyond pruned data. Use RPC call getblockchaininfo to determine your pruned height.", self.nodes[0].rescanblockchain)
results (two runs)

2022-09-01T22:12:35.086000Z TestFramework (INFO): Test it's not possible to rescan beyond pruned data
{'automatic_pruning': True,
 'bestblockhash': '5e4cd87c756bfa94ee47f7ad64e7ccc2db3ca77ba214ac64ca121159388acb2c',
 'blocks': 1553,
 'chain': 'regtest',
 'chainwork': '0000000000000000000000000000000000000000000000000000000000000c24',
 'difficulty': Decimal('4.656542373906925E-10'),
 'headers': 1553,
 'initialblockdownload': False,
 'mediantime': 1662069944,
 'prune_target_size': 576716800,
 'pruned': True,
 'pruneheight': 1056,
 'size_on_disk': 461006996,
 'time': 1662069945,
 'verificationprogress': 1,
 'warnings': 'This is a pre-release test build - use at your own risk - do not '
             'use for mining or merchant applications'}
2022-09-01T22:12:35.847000Z TestFramework (INFO): Done
2022-09-01T23:00:43.821000Z TestFramework (INFO): Test it's not possible to rescan beyond pruned data
{'automatic_pruning': True,
 'bestblockhash': '7075780a24234273a3d53f0a73e0be233c0748fd3fe74c8beb6c6a7ea8ee9686',
 'blocks': 1553,
 'chain': 'regtest',
 'chainwork': '0000000000000000000000000000000000000000000000000000000000000c24',
 'difficulty': Decimal('4.656542373906925E-10'),
 'headers': 1553,
 'initialblockdownload': False,
 'mediantime': 1662072650,
 'prune_target_size': 576716800,
 'pruned': True,
 'pruneheight': 1056,
 'size_on_disk': 461006996,
 'time': 1662072651,
 'verificationprogress': 1,
 'warnings': 'This is a pre-release test build - use at your own risk - do not '
             'use for mining or merchant applications'}
2022-09-01T23:00:44.840000Z TestFramework (INFO): Done


def test_height_min(self):
assert os.path.isfile(os.path.join(self.prunedir, "blk00000.dat")), "blk00000.dat is missing, pruning too early"
self.log.info("Success")
Expand Down Expand Up @@ -477,6 +481,9 @@ def run_test(self):
self.log.info("Test wallet re-scan")
self.wallet_test()

self.log.info("Test it's not possible to rescan beyond pruned data")
self.test_rescan_blockchain()

self.log.info("Test invalid pruning command line options")
self.test_invalid_command_line_options()

Expand Down