/ test / functional / feature_coinstatsindex_compatibility.py
feature_coinstatsindex_compatibility.py
 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.supports_cli = False
20          self.extra_args = [["-coinstatsindex"],["-coinstatsindex"]]
21  
22      def skip_test_if_missing_module(self):
23          self.skip_if_no_previous_releases()
24  
25      def setup_nodes(self):
26          self.add_nodes(
27              self.num_nodes,
28              extra_args=self.extra_args,
29              versions=[
30                  None,
31                  280200,
32              ],
33          )
34          self.start_nodes()
35  
36      def run_test(self):
37          self._test_coin_stats_index_compatibility()
38  
39      def _test_coin_stats_index_compatibility(self):
40          node = self.nodes[0]
41          legacy_node = self.nodes[1]
42          for n in self.nodes:
43              self.wait_until(lambda: n.getindexinfo()['coinstatsindex']['synced'] is True)
44  
45          self.log.info("Test that gettxoutsetinfo() output is consistent between the different index versions")
46          res0 = node.gettxoutsetinfo('muhash')
47          res1 = legacy_node.gettxoutsetinfo('muhash')
48          assert_equal(res1, res0)
49  
50          self.log.info("Test that gettxoutsetinfo() output is consistent for the new index running on a datadir with the old version")
51          self.stop_nodes()
52          shutil.rmtree(node.chain_path / "indexes" / "coinstatsindex")
53          shutil.copytree(legacy_node.chain_path / "indexes" / "coinstats", node.chain_path / "indexes" / "coinstats")
54          old_version_path = node.chain_path / "indexes" / "coinstats"
55          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.'
56          with node.assert_debug_log(expected_msgs=[msg]):
57              self.start_node(0, ['-coinstatsindex'])
58          self.wait_until(lambda: node.getindexinfo()['coinstatsindex']['synced'] is True)
59          res2 = node.gettxoutsetinfo('muhash')
60          assert_equal(res2, res0)
61  
62  
63  if __name__ == '__main__':
64      CoinStatsIndexTest(__file__).main()