Skip to content

Commit 5c4d177

Browse files
MarcoFalkejanus
authored andcommitted
test: Use TestNode *_path properties where possible
Seems odd to place the burden on test writers to hardcode the chain or datadir path for the nodes under test.
1 parent b4b3485 commit 5c4d177

22 files changed

+102
-124
lines changed

test/functional/feature_abortnode.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
- Mine a fork that requires disconnecting the tip.
1010
- Verify that BGLd AbortNode's.
1111
"""
12-
1312
from test_framework.test_framework import BGLTestFramework
14-
from test_framework.util import get_datadir_path
15-
import os
1613

1714
class AbortNodeTest(BGLTestFramework):
1815
def set_test_params(self):
@@ -25,10 +22,9 @@ def setup_network(self):
2522

2623
def run_test(self):
2724
self.generate(self.nodes[0], 3, sync_fun=self.no_op)
28-
datadir = get_datadir_path(self.options.tmpdir, 0)
2925

3026
# Deleting the undo file will result in reorg failure
31-
os.unlink(os.path.join(datadir, 'regtest', 'blocks', 'rev00000.dat'))
27+
(self.nodes[0].chain_path / "blocks" / "rev00000.dat").unlink()
3228

3329
# Connecting to a node with a more work chain will trigger a reorg
3430
# attempt.

test/functional/feature_anchors.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ def set_test_params(self):
2020
self.disable_autoconnect = False
2121

2222
def run_test(self):
23-
node_anchors_path = os.path.join(
24-
self.nodes[0].datadir, "regtest", "anchors.dat"
25-
)
23+
node_anchors_path = self.nodes[0].chain_path / "anchors.dat"
2624

2725
self.log.info("When node starts, check if anchors.dat doesn't exist")
2826
assert not os.path.exists(node_anchors_path)

test/functional/feature_asmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_empty_asmap(self):
114114

115115
def run_test(self):
116116
self.node = self.nodes[0]
117-
self.datadir = os.path.join(self.node.datadir, self.chain)
117+
self.datadir = self.node.chain_path
118118
self.default_asmap = os.path.join(self.datadir, DEFAULT_ASMAP_FILENAME)
119119
self.asmap_raw = os.path.join(os.path.dirname(os.path.realpath(__file__)), ASMAP)
120120

test/functional/feature_config_args.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_config_file_parser(self):
3232
self.stop_node(0)
3333

3434
# Check that startup fails if conf= is set in bitcoin.conf or in an included conf file
35-
bad_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'bitcoin_bad.conf')
35+
bad_conf_file_path = self.nodes[0].datadir_path / "BGL_bad.conf"
3636
util.write_config(bad_conf_file_path, n=0, chain='', extra_config=f'conf=some.conf\n')
3737
conf_in_config_file_err = 'Error: Error reading configuration file: conf cannot be set in the configuration file; use includeconf= if you want to include additional config files'
3838
self.nodes[0].assert_start_raises_init_error(
@@ -75,7 +75,7 @@ def test_config_file_parser(self):
7575
conf.write("wallet=foo\n")
7676
self.nodes[0].assert_start_raises_init_error(expected_msg=f'Error: Config setting for -wallet only applied on {self.chain} network when in [{self.chain}] section.')
7777

78-
main_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'BGL_main.conf')
78+
main_conf_file_path = self.nodes[0].datadir_path / "BGL_main.conf"
7979
util.write_config(main_conf_file_path, n=0, chain='', extra_config=f'includeconf={inc_conf_file_path}\n')
8080
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
8181
conf.write('regtest=0\n') # mainnet
@@ -130,8 +130,8 @@ def test_config_file_log(self):
130130
# Write a bitcoin.conf file in the default data directory containing a
131131
# datadir= line pointing at the node datadir.
132132
node = self.nodes[0]
133-
conf_text = pathlib.Path(node.bitcoinconf).read_text()
134-
conf_path = default_datadir / "bitcoin.conf"
133+
conf_text = pathlib.Path(node.BGLconf).read_text()
134+
conf_path = default_datadir / "BGL.conf"
135135
conf_path.write_text(f"datadir={node.datadir}\n{conf_text}")
136136

137137
# Drop the node -datadir= argument during this test, because if it is
@@ -324,20 +324,20 @@ def test_connect_with_seednode(self):
324324
self.restart_node(0, extra_args=[connect_arg, '-seednode=fakeaddress2'])
325325

326326
def test_ignored_conf(self):
327-
self.log.info('Test error is triggered when the datadir in use contains a bitcoin.conf file that would be ignored '
327+
self.log.info('Test error is triggered when the datadir in use contains a BGL.conf file that would be ignored '
328328
'because a conflicting -conf file argument is passed.')
329329
node = self.nodes[0]
330330
with tempfile.NamedTemporaryFile(dir=self.options.tmpdir, mode="wt", delete=False) as temp_conf:
331331
temp_conf.write(f"datadir={node.datadir}\n")
332332
node.assert_start_raises_init_error([f"-conf={temp_conf.name}"], re.escape(
333-
f'Error: Data directory "{node.datadir}" contains a "bitcoin.conf" file which is ignored, because a '
333+
f'Error: Data directory "{node.datadir}" contains a "BGL.conf" file which is ignored, because a '
334334
f'different configuration file "{temp_conf.name}" from command line argument "-conf={temp_conf.name}" '
335335
f'is being used instead.') + r"[\s\S]*", match=ErrorMatch.FULL_REGEX)
336336

337337
# Test that passing a redundant -conf command line argument pointing to
338338
# the same bitcoin.conf that would be loaded anyway does not trigger an
339339
# error.
340-
self.start_node(0, [f'-conf={node.datadir}/bitcoin.conf'])
340+
self.start_node(0, [f'-conf={node.datadir}/BGL.conf'])
341341
self.stop_node(0)
342342

343343
def test_ignored_default_conf(self):
@@ -346,8 +346,8 @@ def test_ignored_default_conf(self):
346346
if sys.platform == "win32":
347347
return
348348

349-
self.log.info('Test error is triggered when bitcoin.conf in the default data directory sets another datadir '
350-
'and it contains a different bitcoin.conf file that would be ignored')
349+
self.log.info('Test error is triggered when BGL.conf in the default data directory sets another datadir '
350+
'and it contains a different BGL.conf file that would be ignored')
351351

352352
# Create a temporary directory that will be treated as the default data
353353
# directory by bitcoind.
@@ -359,16 +359,16 @@ def test_ignored_default_conf(self):
359359
# startup error because the node datadir contains a different
360360
# bitcoin.conf that would be ignored.
361361
node = self.nodes[0]
362-
(default_datadir / "bitcoin.conf").write_text(f"datadir={node.datadir}\n")
362+
(default_datadir / "BGL.conf").write_text(f"datadir={node.datadir}\n")
363363

364364
# Drop the node -datadir= argument during this test, because if it is
365365
# specified it would take precedence over the datadir setting in the
366366
# config file.
367367
node_args = node.args
368368
node.args = [arg for arg in node.args if not arg.startswith("-datadir=")]
369369
node.assert_start_raises_init_error([], re.escape(
370-
f'Error: Data directory "{node.datadir}" contains a "bitcoin.conf" file which is ignored, because a '
371-
f'different configuration file "{default_datadir}/bitcoin.conf" from data directory "{default_datadir}" '
370+
f'Error: Data directory "{node.datadir}" contains a "BGL.conf" file which is ignored, because a '
371+
f'different configuration file "{default_datadir}/BGL.conf" from data directory "{default_datadir}" '
372372
f'is being used instead.') + r"[\s\S]*", env=env, match=ErrorMatch.FULL_REGEX)
373373
node.args = node_args
374374

test/functional/feature_filelock.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
# Copyright (c) 2018-2022 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Check that it's not possible to start a second BGLd instance using the same datadir or wallet."""
6-
import os
5+
"""Check that it's not possible to start a second bitcoind instance using the same datadir or wallet."""
76
import random
87
import string
98

@@ -24,7 +23,7 @@ def setup_network(self):
2423
self.nodes[0].wait_for_rpc_connection()
2524

2625
def run_test(self):
27-
datadir = os.path.join(self.nodes[0].datadir, self.chain)
26+
datadir = self.nodes[0].chain_path
2827
self.log.info(f"Using datadir {datadir}")
2928

3029
self.log.info("Check that we can't start a second BGLd instance using the same datadir")
@@ -35,7 +34,7 @@ def run_test(self):
3534
def check_wallet_filelock(descriptors):
3635
wallet_name = ''.join([random.choice(string.ascii_lowercase) for _ in range(6)])
3736
self.nodes[0].createwallet(wallet_name=wallet_name, descriptors=descriptors)
38-
wallet_dir = os.path.join(datadir, 'wallets')
37+
wallet_dir = self.nodes[0].wallets_path
3938
self.log.info("Check that we can't start a second BGLd instance using the same wallet")
4039
if descriptors:
4140
expected_msg = "Error: SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of Bitgesell Core?"

test/functional/feature_includeconf.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,25 @@
1414
4. multiple includeconf arguments can be specified in the main config
1515
file.
1616
"""
17-
import os
18-
1917
from test_framework.test_framework import BGLTestFramework
2018

19+
2120
class IncludeConfTest(BGLTestFramework):
2221
def set_test_params(self):
2322
self.num_nodes = 1
2423

25-
def setup_chain(self):
26-
super().setup_chain()
24+
def run_test(self):
2725
# Create additional config files
2826
# - tmpdir/node0/relative.conf
29-
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f:
27+
with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f:
3028
f.write("uacomment=relative\n")
3129
# - tmpdir/node0/relative2.conf
32-
with open(os.path.join(self.options.tmpdir, "node0", "relative2.conf"), "w", encoding="utf8") as f:
30+
with open(self.nodes[0].datadir_path / "relative2.conf", "w", encoding="utf8") as f:
3331
f.write("uacomment=relative2\n")
34-
with open(os.path.join(self.options.tmpdir, "node0", "BGL.conf"), "a", encoding='utf8') as f:
32+
with open(self.nodes[0].datadir_path / "BGL.conf", "a", encoding="utf8") as f:
3533
f.write("uacomment=main\nincludeconf=relative.conf\n")
34+
self.restart_node(0)
3635

37-
def run_test(self):
3836
self.log.info("-includeconf works from config file. subversion should end with 'main; relative)/'")
3937

4038
subversion = self.nodes[0].getnetworkinfo()["subversion"]
@@ -52,7 +50,7 @@ def run_test(self):
5250
)
5351

5452
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
55-
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:
53+
with open(self.nodes[0].datadir_path / "relative.conf", "a", encoding="utf8") as f:
5654
f.write("includeconf=relative2.conf\n")
5755
self.start_node(0)
5856

@@ -63,20 +61,20 @@ def run_test(self):
6361
self.log.info("-includeconf cannot contain invalid arg")
6462

6563
# Commented out as long as we ignore invalid arguments in configuration files
66-
#with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f:
64+
#with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f:
6765
# f.write("foo=bar\n")
6866
#self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Invalid configuration value foo")
6967

7068
self.log.info("-includeconf cannot be invalid path")
71-
os.remove(os.path.join(self.options.tmpdir, "node0", "relative.conf"))
69+
(self.nodes[0].datadir_path / "relative.conf").unlink()
7270
self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Failed to include configuration file relative.conf")
7371

7472
self.log.info("multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'")
75-
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f:
73+
with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f:
7674
# Restore initial file contents
7775
f.write("uacomment=relative\n")
7876

79-
with open(os.path.join(self.options.tmpdir, "node0", "BGL.conf"), "a", encoding='utf8') as f:
77+
with open(self.nodes[0].datadir_path / "BGL.conf", "a", encoding="utf8") as f:
8078
f.write("includeconf=relative2.conf\n")
8179

8280
self.start_node(0)

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 = os.path.join(data_dir, "regtest", "blocks")
40+
blocks_dir = self.nodes[0].chain_path / "blocks"
4141
hash_list = tempfile.NamedTemporaryFile(dir=data_dir,
4242
mode='w',
4343
delete=False,

test/functional/feature_posix_fs_permissions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def check_file_permissions(self, file):
3131

3232
def run_test(self):
3333
self.stop_node(0)
34-
datadir = os.path.join(self.nodes[0].datadir, self.chain)
34+
datadir = self.nodes[0].chain_path
3535
self.check_directory_permissions(datadir)
36-
walletsdir = os.path.join(datadir, "wallets")
36+
walletsdir = self.nodes[0].wallets_path
3737
self.check_directory_permissions(walletsdir)
38-
debuglog = os.path.join(datadir, "debug.log")
38+
debuglog = self.nodes[0].debug_log_path
3939
self.check_file_permissions(debuglog)
4040

4141

test/functional/feature_reindex.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
- Verify that out-of-order blocks are correctly processed, see LoadExternalBlockFile()
1111
"""
1212

13-
import os
1413
from test_framework.test_framework import BGLTestFramework
1514
from test_framework.p2p import MAGIC_BYTES
1615
from test_framework.util import assert_equal
@@ -39,7 +38,7 @@ def out_of_order(self):
3938
# In this test environment, blocks will always be in order (since
4039
# we're generating them rather than getting them from peers), so to
4140
# test out-of-order handling, swap blocks 1 and 2 on disk.
42-
blk0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00000.dat')
41+
blk0 = self.nodes[0].chain_path / "blocks" / "blk00000.dat"
4342
with open(blk0, 'r+b') as bf:
4443
# Read at least the first few blocks (including genesis)
4544
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 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00000.dat')
24-
rev0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00000.dat')
25-
blk1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00001.dat')
26-
rev1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00001.dat')
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"
2727
self.mine_batches(800)
2828
fo1 = os.open(blk0, os.O_RDONLY)
2929
fo2 = os.open(rev1, os.O_RDONLY)

0 commit comments

Comments
 (0)