Skip to content

Commit a5b38e6

Browse files
fanquakevijaydasmp
authored andcommitted
Merge bitcoin#27884: test: Use TestNode datadir_path or chain_path where possible
aaaa3ae test: Use TestNode *_path properties where possible (MarcoFalke) dddd899 test: Allow pathlib.Path as RPC argument via authproxy (MarcoFalke) fa41614 scripted-diff: Use wallets_path and chain_path where possible (MarcoFalke) fa493fa test: Use wallet_dir lambda in wallet_multiwallet test where possible (MarcoFalke) Pull request description: It seems inconsistent, fragile and verbose to: * Call `get_datadir_path` to recreate the path that already exists as field in TestNode * Call `os.path.join` with the hardcoded chain name or `self.chain` to recreate the TestNode `chain_path` property * Sometimes even use the hardcoded node dir name (`"node0"`) Fix all issues by using the TestNode properties. ACKs for top commit: willcl-ark: re-ACK aaaa3ae theStack: Code-review ACK aaaa3ae 🌊 Tree-SHA512: e4720278085beb8164e1fe6c1aa18f601558a9263494ce69a83764c1487007de63ebb51d1b1151862dc4d5b49ded6162a5c1553cd30ea1c28627d447db4d8e72
1 parent ad5d403 commit a5b38e6

34 files changed

+123
-132
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 dashd AbortNode's.
1111
"""
12-
1312
from test_framework.test_framework import BitcoinTestFramework
14-
from test_framework.util import get_datadir_path
15-
import os
1613

1714

1815
class AbortNodeTest(BitcoinTestFramework):
@@ -27,10 +24,9 @@ def setup_network(self):
2724

2825
def run_test(self):
2926
self.generate(self.nodes[0], 3, sync_fun=self.no_op)
30-
datadir = get_datadir_path(self.options.tmpdir, 0)
3127

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

3531
# Connecting to a node with a more work chain will trigger a reorg
3632
# attempt.

test/functional/feature_addrman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def set_test_params(self):
5252
self.num_nodes = 1
5353

5454
def run_test(self):
55-
peers_dat = os.path.join(self.nodes[0].datadir, self.chain, "peers.dat")
55+
peers_dat = os.path.join(self.nodes[0].chain_path, "peers.dat")
5656
init_error = lambda reason: (
5757
f"Error: Invalid or corrupt peers.dat \\({reason}\\). If you believe this "
5858
f"is a bug, please report it to {self.config['environment']['PACKAGE_BUGREPORT']}. "

test/functional/feature_anchors.py

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

2525
def run_test(self):
26-
node_anchors_path = os.path.join(
27-
self.nodes[0].datadir, "regtest", "anchors.dat"
28-
)
26+
node_anchors_path = self.nodes[0].chain_path / "anchors.dat"
2927

3028
self.log.info("When node starts, check if anchors.dat doesn't exist")
3129
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
@@ -113,7 +113,7 @@ def test_empty_asmap(self):
113113

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

test/functional/feature_blocksdir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def set_test_params(self):
1818

1919
def run_test(self):
2020
self.stop_node(0)
21-
assert os.path.isdir(os.path.join(self.nodes[0].datadir, self.chain, "blocks"))
21+
assert os.path.isdir(os.path.join(self.nodes[0].chain_path, "blocks"))
2222
assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "blocks"))
2323
shutil.rmtree(self.nodes[0].datadir)
2424
initialize_datadir(self.options.tmpdir, 0, self.chain)
@@ -31,7 +31,7 @@ def run_test(self):
3131
self.log.info("mining blocks..")
3232
self.generatetoaddress(self.nodes[0], 10, self.nodes[0].get_deterministic_priv_key().address)
3333
assert os.path.isfile(os.path.join(blocksdir_path, self.chain, "blocks", "blk00000.dat"))
34-
assert os.path.isdir(os.path.join(self.nodes[0].datadir, self.chain, "blocks", "index"))
34+
assert os.path.isdir(os.path.join(self.nodes[0].chain_path, "blocks", "index"))
3535

3636

3737
if __name__ == '__main__':

test/functional/feature_config_args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_config_file_parser(self):
2727
self.stop_node(0)
2828

2929
# Check that startup fails if conf= is set in bitcoin.conf or in an included conf file
30-
bad_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'bitcoin_bad.conf')
30+
bad_conf_file_path = self.nodes[0].datadir_path / "bitcoin_bad.conf"
3131
util.write_config(bad_conf_file_path, n=0, chain='', extra_config=f'conf=some.conf\n')
3232
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'
3333
self.nodes[0].assert_start_raises_init_error(
@@ -70,7 +70,7 @@ def test_config_file_parser(self):
7070
conf.write("wallet=foo\n")
7171
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.')
7272

73-
main_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'dash_main.conf')
73+
main_conf_file_path = self.nodes[0].datadir_path / "dash_main.conf"
7474
util.write_config(main_conf_file_path, n=0, chain='', extra_config=f'includeconf={inc_conf_file_path}\n')
7575
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
7676
conf.write('acceptnonstdtxn=1\n')

test/functional/feature_filelock.py

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

@@ -26,7 +25,7 @@ def setup_network(self):
2625
self.nodes[0].wait_for_rpc_connection()
2726

2827
def run_test(self):
29-
datadir = os.path.join(self.nodes[0].datadir, self.chain)
28+
datadir = self.nodes[0].chain_path
3029
self.log.info(f"Using datadir {datadir}")
3130

3231
self.log.info("Check that we can't start a second dashd instance using the same datadir")
@@ -43,7 +42,7 @@ def run_test(self):
4342
def check_wallet_filelock(descriptors):
4443
wallet_name = ''.join([random.choice(string.ascii_lowercase) for _ in range(6)])
4544
self.nodes[0].createwallet(wallet_name=wallet_name, descriptors=descriptors)
46-
wallet_dir = os.path.join(datadir, 'wallets')
45+
wallet_dir = self.nodes[0].wallets_path
4746
self.log.info("Check that we can't start a second dashd instance using the same wallet")
4847
if descriptors:
4948
expected_msg = f"Error: SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of {self.config['environment']['PACKAGE_NAME']}?"

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 BitcoinTestFramework
2018

19+
2120
class IncludeConfTest(BitcoinTestFramework):
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", "dash.conf"), "a", encoding='utf8') as f:
32+
with open(self.nodes[0].datadir_path / "dash.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", "dash.conf"), "a", encoding='utf8') as f:
77+
with open(self.nodes[0].datadir_path / "dash.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, self.chain, "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_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def set_test_params(self):
1616
self.setup_clean_chain = True
1717

1818
def relative_log_path(self, name):
19-
return os.path.join(self.nodes[0].datadir, self.chain, name)
19+
return os.path.join(self.nodes[0].chain_path, name)
2020

2121
def run_test(self):
2222
# test default log file name

0 commit comments

Comments
 (0)