diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-11-15 09:36:27 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-11-15 09:36:42 +0100 |
commit | 41a1b5f58ca59d2177dcadf834efd187fa3fba52 (patch) | |
tree | 2156d420db44c8a294f0b1f29fc28390ee0d57dc | |
parent | 8251316acb60b2f5c9c19ca5d9e457c5af3c110a (diff) | |
parent | fadc4c72723d67a59d80d843c85b090ae22b463b (diff) |
Merge bitcoin/bitcoin#23046: test: Add txindex migration test
fadc4c72723d67a59d80d843c85b090ae22b463b test: Add txindex migration test (MarcoFalke)
Pull request description:
Test for #22626
ACKs for top commit:
theStack:
Tested ACK fadc4c72723d67a59d80d843c85b090ae22b463b 🌁
Tree-SHA512: fc7133ef52826bf0d4fa2ac72c3f1bed4a185ff7492396552ff2cbf6531b053238039211a710cbb949379c56875cd7715f1ed49a514dd3b3f1b46554e3d4bef5
-rwxr-xr-x | test/functional/feature_txindex_compatibility.py | 92 | ||||
-rwxr-xr-x | test/functional/test_runner.py | 1 |
2 files changed, 93 insertions, 0 deletions
diff --git a/test/functional/feature_txindex_compatibility.py b/test/functional/feature_txindex_compatibility.py new file mode 100755 index 0000000000..bbe1d1b537 --- /dev/null +++ b/test/functional/feature_txindex_compatibility.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +# Copyright (c) 2021 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +"""Test that legacy txindex will be disabled on upgrade. + +Previous releases are required by this test, see test/README.md. +""" + +import os +import shutil + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.wallet import MiniWallet + + +class MempoolCompatibilityTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 3 + self.extra_args = [ + ["-reindex", "-txindex"], + [], + [], + ] + + def skip_test_if_missing_module(self): + self.skip_if_no_previous_releases() + + def setup_network(self): + self.add_nodes( + self.num_nodes, + self.extra_args, + versions=[ + 160300, # Last release with legacy txindex + None, # For MiniWallet, without migration code + 200100, # Any release with migration code (0.17.x - 22.x) + ], + ) + self.start_nodes() + self.connect_nodes(0, 1) + self.connect_nodes(1, 2) + + def run_test(self): + mini_wallet = MiniWallet(self.nodes[1]) + mini_wallet.rescan_utxos() + spend_utxo = mini_wallet.get_utxo() + mini_wallet.send_self_transfer(from_node=self.nodes[1], utxo_to_spend=spend_utxo) + self.generate(self.nodes[1], 1) + + self.log.info("Check legacy txindex") + self.nodes[0].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex + + self.stop_nodes() + legacy_chain_dir = os.path.join(self.nodes[0].datadir, self.chain) + + self.log.info("Migrate legacy txindex") + migrate_chain_dir = os.path.join(self.nodes[2].datadir, self.chain) + shutil.rmtree(migrate_chain_dir) + shutil.copytree(legacy_chain_dir, migrate_chain_dir) + with self.nodes[2].assert_debug_log([ + "Upgrading txindex database...", + "txindex is enabled at height 200", + ]): + self.start_node(2, extra_args=["-txindex"]) + self.nodes[2].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex + + self.log.info("Drop legacy txindex") + drop_index_chain_dir = os.path.join(self.nodes[1].datadir, self.chain) + shutil.rmtree(drop_index_chain_dir) + shutil.copytree(legacy_chain_dir, drop_index_chain_dir) + self.nodes[1].assert_start_raises_init_error( + extra_args=["-txindex"], + expected_msg="Error: The block index db contains a legacy 'txindex'. To clear the occupied disk space, run a full -reindex, otherwise ignore this error. This error message will not be displayed again.", + ) + # Build txindex from scratch and check there is no error this time + self.start_node(1, extra_args=["-txindex"]) + self.nodes[2].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex + + self.stop_nodes() + + self.log.info("Check migrated txindex can not be read by legacy node") + err_msg = f": You need to rebuild the database using -reindex to change -txindex.{os.linesep}Please restart with -reindex or -reindex-chainstate to recover." + shutil.rmtree(legacy_chain_dir) + shutil.copytree(migrate_chain_dir, legacy_chain_dir) + self.nodes[0].assert_start_raises_init_error(extra_args=["-txindex"], expected_msg=err_msg) + shutil.rmtree(legacy_chain_dir) + shutil.copytree(drop_index_chain_dir, legacy_chain_dir) + self.nodes[0].assert_start_raises_init_error(extra_args=["-txindex"], expected_msg=err_msg) + + +if __name__ == "__main__": + MempoolCompatibilityTest().main() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 2d84507151..37fc549922 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -296,6 +296,7 @@ BASE_SCRIPTS = [ 'rpc_deriveaddresses.py --usecli', 'p2p_ping.py', 'rpc_scantxoutset.py', + 'feature_txindex_compatibility.py', 'feature_logging.py', 'feature_anchors.py', 'feature_coinstatsindex.py', |