Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2026 The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Test txindex forward compatibility.7"""9import shutil11from test_framework.test_framework import BitcoinTestFramework12from test_framework.util import assert_equal13from test_framework.wallet import MiniWallet15class TxIndexTest(BitcoinTestFramework):16def set_test_params(self):17self.num_nodes = 218self.extra_args = [["-txindex"],["-txindex"]]20def skip_test_if_missing_module(self):21self.skip_if_no_previous_releases()23def setup_nodes(self):24self.add_nodes(25self.num_nodes,26extra_args=self.extra_args,27versions=[28None,29280200,30],31)32self.start_nodes()34def run_test(self):35self._test_txindex_compatibility()37def _test_txindex_compatibility(self):38node = self.nodes[0]39legacy_node = self.nodes[1]40self.wallet = MiniWallet(self.nodes[0])41tx1 = self.wallet.send_self_transfer(from_node=self.nodes[0])42self.generate(self.nodes[0], 1)43txId1 = tx1['txid']45for n in self.nodes:46self.wait_until(lambda: n.getindexinfo()['txindex']['synced'])48self.log.info("Ensure that queries to the txindex are consistent between the different index versions")49assert_equal(node.getrawtransaction(txId1), tx1['hex'])50assert_equal(legacy_node.getrawtransaction(txId1), tx1['hex'])52self.log.info("Exercise the new index running on a datadir with the old version")53self.stop_nodes()54self.cleanup_folder(node.chain_path)55shutil.copytree(legacy_node.chain_path, node.chain_path)56msg = "txindex contains entries in the legacy format"57with node.assert_debug_log(expected_msgs=[msg]):58self.start_node(0)59self.wait_until(lambda: node.getindexinfo()['txindex']['synced'])60assert_equal(node.getrawtransaction(txId1), tx1['hex'])62self.log.info("Test that looking up a newly added transaction in a mixed-format db is possible")63tx2 = self.wallet.send_self_transfer(from_node=self.nodes[0])64self.generate(self.nodes[0], 1, sync_fun=self.no_op)65txId2 = tx2['txid']66self.wait_until(lambda: node.getindexinfo()['txindex']['synced'])67assert_equal(node.getrawtransaction(txId1), tx1['hex'])68assert_equal(node.getrawtransaction(txId2), tx2['hex'])71if __name__ == '__main__':72TxIndexTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.