1 #!/usr/bin/env python3
2 # Copyright (c) 2025-present The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test coinstatsindex across node versions.
6 7 This test may be removed some time after v29 has reached end of life.
8 """
9 10 import shutil
11 12 from test_framework.test_framework import BitcoinTestFramework
13 from test_framework.util import assert_equal
14 15 16 class CoinStatsIndexTest(BitcoinTestFramework):
17 def set_test_params(self):
18 self.num_nodes = 2
19 self.extra_args = [["-coinstatsindex"],["-coinstatsindex"]]
20 21 def skip_test_if_missing_module(self):
22 self.skip_if_no_previous_releases()
23 24 def setup_nodes(self):
25 self.add_nodes(
26 self.num_nodes,
27 extra_args=self.extra_args,
28 versions=[
29 None,
30 280200,
31 ],
32 )
33 self.start_nodes()
34 35 def run_test(self):
36 self._test_coin_stats_index_compatibility()
37 38 def _test_coin_stats_index_compatibility(self):
39 node = self.nodes[0]
40 legacy_node = self.nodes[1]
41 for n in self.nodes:
42 self.wait_until(lambda: n.getindexinfo()['coinstatsindex']['synced'] is True)
43 44 self.log.info("Test that gettxoutsetinfo() output is consistent between the different index versions")
45 res0 = node.gettxoutsetinfo('muhash')
46 res1 = legacy_node.gettxoutsetinfo('muhash')
47 assert_equal(res1, res0)
48 49 self.log.info("Test that gettxoutsetinfo() output is consistent for the new index running on a datadir with the old version")
50 self.stop_nodes()
51 self.cleanup_folder(node.chain_path / "indexes" / "coinstatsindex")
52 shutil.copytree(legacy_node.chain_path / "indexes" / "coinstats", node.chain_path / "indexes" / "coinstats")
53 old_version_path = node.chain_path / "indexes" / "coinstats"
54 msg = f'[warning] Old version of coinstatsindex found at {old_version_path}. This folder can be safely deleted unless you plan to downgrade your node to version 29 or lower.'
55 with node.assert_debug_log(expected_msgs=[msg]):
56 self.start_node(0, ['-coinstatsindex'])
57 self.wait_until(lambda: node.getindexinfo()['coinstatsindex']['synced'] is True)
58 res2 = node.gettxoutsetinfo('muhash')
59 assert_equal(res2, res0)
60 61 62 if __name__ == '__main__':
63 CoinStatsIndexTest(__file__).main()
64