Skip to content

Commit 8535802

Browse files
committed
Merge bitcoin/bitcoin#28070: test: Drop 22.x node from TxindexCompatibilityTest
fafe43c scripted-diff: Use blocks_path where possible (MarcoFalke) fa060c1 test: Add blocks_path property to TestNode (MarcoFalke) faba4fc test: Drop 22.x node from TxindexCompatibilityTest (MarcoFalke) fa7f65b test: Use clean chain in MempoolCompatibilityTest (MarcoFalke) Pull request description: The node in this test was never really needed, because the compatibility tests shouldn't be used to test previous releases. (The test suite of the previous release itself should be used for that). So remove it. Also, other test changes. (See individual commits) ACKs for top commit: theStack: Code-review ACK fafe43c Tree-SHA512: 289f54695bf5310663ab38ebf1aa457f53d0aafae56e6657be0e75bf96b303165bad417dc7eaf4c40f0639aa92ce139e5bacb318a2eabab1f8e23a811cabe0cc
2 parents f4f1d6d + fafe43c commit 8535802

10 files changed

+26
-37
lines changed

test/functional/feature_abortnode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def run_test(self):
2525
self.generate(self.nodes[0], 3, sync_fun=self.no_op)
2626

2727
# Deleting the undo file will result in reorg failure
28-
(self.nodes[0].chain_path / "blocks" / "rev00000.dat").unlink()
28+
(self.nodes[0].blocks_path / "rev00000.dat").unlink()
2929

3030
# Connecting to a node with a more work chain will trigger a reorg
3131
# attempt.

test/functional/feature_dirsymlinks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def run_test(self):
2626
self.stop_node(0)
2727

2828
rename_and_link(
29-
from_name=self.nodes[0].chain_path / "blocks",
29+
from_name=self.nodes[0].blocks_path,
3030
to_name=dir_new_blocks,
3131
)
3232
rename_and_link(

test/functional/feature_loadblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def run_test(self):
3737
cfg_file = os.path.join(data_dir, "linearize.cfg")
3838
bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat")
3939
genesis_block = self.nodes[0].getblockhash(0)
40-
blocks_dir = self.nodes[0].chain_path / "blocks"
40+
blocks_dir = self.nodes[0].blocks_path
4141
hash_list = tempfile.NamedTemporaryFile(dir=data_dir,
4242
mode='w',
4343
delete=False,

test/functional/feature_reindex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def out_of_order(self):
3838
# In this test environment, blocks will always be in order (since
3939
# we're generating them rather than getting them from peers), so to
4040
# test out-of-order handling, swap blocks 1 and 2 on disk.
41-
blk0 = self.nodes[0].chain_path / "blocks" / "blk00000.dat"
41+
blk0 = self.nodes[0].blocks_path / "blk00000.dat"
4242
with open(blk0, 'r+b') as bf:
4343
# Read at least the first few blocks (including genesis)
4444
b = bf.read(2000)

test/functional/feature_remove_pruned_files_on_startup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def mine_batches(self, blocks):
2020
self.sync_blocks()
2121

2222
def run_test(self):
23-
blk0 = self.nodes[0].chain_path / "blocks" / "blk00000.dat"
24-
rev0 = self.nodes[0].chain_path / "blocks" / "rev00000.dat"
25-
blk1 = self.nodes[0].chain_path / "blocks" / "blk00001.dat"
26-
rev1 = self.nodes[0].chain_path / "blocks" / "rev00001.dat"
23+
blk0 = self.nodes[0].blocks_path / "blk00000.dat"
24+
rev0 = self.nodes[0].blocks_path / "rev00000.dat"
25+
blk1 = self.nodes[0].blocks_path / "blk00001.dat"
26+
rev1 = self.nodes[0].blocks_path / "rev00001.dat"
2727
self.mine_batches(800)
2828
fo1 = os.open(blk0, os.O_RDONLY)
2929
fo2 = os.open(rev1, os.O_RDONLY)

test/functional/feature_txindex_compatibility.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
import shutil
1212

1313
from test_framework.test_framework import BitcoinTestFramework
14+
from test_framework.util import assert_raises_rpc_error
1415
from test_framework.wallet import MiniWallet
1516

1617

1718
class TxindexCompatibilityTest(BitcoinTestFramework):
1819
def set_test_params(self):
19-
self.num_nodes = 3
20+
self.num_nodes = 2
2021
self.extra_args = [
2122
["-reindex", "-txindex"],
2223
[],
23-
[],
2424
]
2525

2626
def skip_test_if_missing_module(self):
@@ -33,12 +33,10 @@ def setup_network(self):
3333
versions=[
3434
160300, # Last release with legacy txindex
3535
None, # For MiniWallet, without migration code
36-
220000, # Last release with migration code (0.17.x - 22.x)
3736
],
3837
)
3938
self.start_nodes()
4039
self.connect_nodes(0, 1)
41-
self.connect_nodes(1, 2)
4240

4341
def run_test(self):
4442
mini_wallet = MiniWallet(self.nodes[1])
@@ -47,22 +45,12 @@ def run_test(self):
4745
self.generate(self.nodes[1], 1)
4846

4947
self.log.info("Check legacy txindex")
48+
assert_raises_rpc_error(-5, "Use -txindex", lambda: self.nodes[1].getrawtransaction(txid=spend_utxo["txid"]))
5049
self.nodes[0].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex
5150

5251
self.stop_nodes()
5352
legacy_chain_dir = self.nodes[0].chain_path
5453

55-
self.log.info("Migrate legacy txindex")
56-
migrate_chain_dir = self.nodes[2].chain_path
57-
shutil.rmtree(migrate_chain_dir)
58-
shutil.copytree(legacy_chain_dir, migrate_chain_dir)
59-
with self.nodes[2].assert_debug_log([
60-
"Upgrading txindex database...",
61-
"txindex is enabled at height 200",
62-
]):
63-
self.start_node(2, extra_args=["-txindex"])
64-
self.nodes[2].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex
65-
6654
self.log.info("Drop legacy txindex")
6755
drop_index_chain_dir = self.nodes[1].chain_path
6856
shutil.rmtree(drop_index_chain_dir)
@@ -73,16 +61,14 @@ def run_test(self):
7361
)
7462
# Build txindex from scratch and check there is no error this time
7563
self.start_node(1, extra_args=["-txindex"])
76-
self.nodes[2].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex
64+
self.wait_until(lambda: self.nodes[1].getindexinfo()["txindex"]["synced"] == True)
65+
self.nodes[1].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex
7766

7867
self.stop_nodes()
7968

8069
self.log.info("Check migrated txindex cannot be read by legacy node")
8170
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."
8271
shutil.rmtree(legacy_chain_dir)
83-
shutil.copytree(migrate_chain_dir, legacy_chain_dir)
84-
self.nodes[0].assert_start_raises_init_error(extra_args=["-txindex"], expected_msg=err_msg)
85-
shutil.rmtree(legacy_chain_dir)
8672
shutil.copytree(drop_index_chain_dir, legacy_chain_dir)
8773
self.nodes[0].assert_start_raises_init_error(extra_args=["-txindex"], expected_msg=err_msg)
8874

test/functional/feature_unsupported_utxo_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def run_test(self):
4040

4141
self.log.info("Check init error")
4242
legacy_utxos_dir = self.nodes[0].chain_path / "chainstate"
43-
legacy_blocks_dir = self.nodes[0].chain_path / "blocks"
43+
legacy_blocks_dir = self.nodes[0].blocks_path
4444
recent_utxos_dir = self.nodes[1].chain_path / "chainstate"
45-
recent_blocks_dir = self.nodes[1].chain_path / "blocks"
45+
recent_blocks_dir = self.nodes[1].blocks_path
4646
shutil.copytree(legacy_utxos_dir, recent_utxos_dir)
4747
shutil.copytree(legacy_blocks_dir, recent_blocks_dir)
4848
self.nodes[1].assert_start_raises_init_error(

test/functional/mempool_compatibility.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
Previous releases are required by this test, see test/README.md.
1111
"""
1212

13-
import os
14-
1513
from test_framework.blocktools import COINBASE_MATURITY
1614
from test_framework.test_framework import BitcoinTestFramework
1715
from test_framework.wallet import (
@@ -23,6 +21,7 @@
2321
class MempoolCompatibilityTest(BitcoinTestFramework):
2422
def set_test_params(self):
2523
self.num_nodes = 2
24+
self.setup_clean_chain = True
2625

2726
def skip_test_if_missing_module(self):
2827
self.skip_if_no_previous_releases()
@@ -55,9 +54,9 @@ def run_test(self):
5554
self.stop_node(1)
5655

5756
self.log.info("Move mempool.dat from old to new node")
58-
old_node_mempool = os.path.join(old_node.chain_path, 'mempool.dat')
59-
new_node_mempool = os.path.join(new_node.chain_path, 'mempool.dat')
60-
os.rename(old_node_mempool, new_node_mempool)
57+
old_node_mempool = old_node.chain_path / "mempool.dat"
58+
new_node_mempool = new_node.chain_path / "mempool.dat"
59+
old_node_mempool.rename(new_node_mempool)
6160

6261
self.log.info("Start new node and verify mempool contains the tx")
6362
self.start_node(1)
@@ -70,7 +69,7 @@ def run_test(self):
7069
self.stop_node(1)
7170

7271
self.log.info("Move mempool.dat from new to old node")
73-
os.rename(new_node_mempool, old_node_mempool)
72+
new_node_mempool.rename(old_node_mempool)
7473

7574
self.log.info("Start old node again and verify mempool contains both txs")
7675
self.start_node(0, ['-nowallet'])

test/functional/rpc_blockchain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ def assert_vin_does_not_contain_prevout(verbosity):
577577
self.log.info("Test that getblock with verbosity 2 and 3 still works with pruned Undo data")
578578

579579
def move_block_file(old, new):
580-
old_path = self.nodes[0].chain_path / "blocks" / old
581-
new_path = self.nodes[0].chain_path / "blocks" / new
580+
old_path = self.nodes[0].blocks_path / old
581+
new_path = self.nodes[0].blocks_path / new
582582
old_path.rename(new_path)
583583

584584
# Move instead of deleting so we can restore chain state afterwards

test/functional/test_framework/test_node.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ def chain_path(self) -> Path:
420420
def debug_log_path(self) -> Path:
421421
return self.chain_path / 'debug.log'
422422

423+
@property
424+
def blocks_path(self) -> Path:
425+
return self.chain_path / "blocks"
426+
423427
@property
424428
def wallets_path(self) -> Path:
425429
return self.chain_path / "wallets"

0 commit comments

Comments
 (0)