Skip to content

Commit

Permalink
test: Add test for outdated coinstats index version
Browse files Browse the repository at this point in the history
  • Loading branch information
fjahr committed Jul 16, 2024
1 parent 0e456ff commit f731bc2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/functional/data/coinstatsindex_v0/CURRENT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MANIFEST-000002
Empty file.
Binary file not shown.
16 changes: 16 additions & 0 deletions test/functional/feature_coinstatsindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"""

from decimal import Decimal
import os
from pathlib import Path
import shutil

from test_framework.blocktools import (
COINBASE_MATURITY,
Expand Down Expand Up @@ -53,6 +56,7 @@ def run_test(self):
self._test_reorg_index()
self._test_index_rejects_hash_serialized()
self._test_init_index_after_reorg()
self._test_outdated_index_version()

def block_sanity_check(self, block_info):
block_subsidy = 50
Expand Down Expand Up @@ -322,6 +326,18 @@ def _test_init_index_after_reorg(self):
res1 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=True)
assert_equal(res["muhash"], res1["muhash"])

def _test_outdated_index_version(self):
self.log.info("Test a node doesn't start with an outdated index version")
index_node = self.nodes[1]
index_db = index_node.chain_path / 'indexes' / 'coinstats' / 'db'
shutil.rmtree(index_db)
v0_index_db = Path(os.path.dirname(os.path.realpath(__file__))) / 'data' / 'coinstatsindex_v0'
shutil.copytree(v0_index_db, index_db)
self.stop_node(1)
msg = "[error] coinstatsindex version mismatch: expected 1 but 0 was found. In order to rebuild the index, remove the indexes/coinstats directory in your datadir"
with index_node.assert_debug_log(expected_msgs=[msg]):
index_node.assert_start_raises_init_error(extra_args=["-coinstatsindex"])


if __name__ == '__main__':
CoinStatsIndexTest().main()

0 comments on commit f731bc2

Please sign in to comment.