aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorns-xvrn <ns@xvrn.tech>2023-09-02 01:09:43 -0400
committerns-xvrn <ns@xvrn.tech>2023-10-10 09:26:56 -0400
commitbfa0bd632a7ce5d04005e20cba79abb32aec8da8 (patch)
tree44e80e5f1339e5bb4308cc3c5de1abf2e60c543b
parent04265ba9378efbd4c35b33390b1e5cf246d420a9 (diff)
downloadbitcoin-bfa0bd632a7ce5d04005e20cba79abb32aec8da8.tar.xz
test: Use pathlib over os.path #28362
revert netutil chgs py3.8 compliant fixes based on PR review
-rwxr-xr-xtest/functional/feature_blocksdir.py16
-rwxr-xr-xtest/functional/feature_config_args.py63
-rwxr-xr-xtest/functional/feature_filelock.py2
-rwxr-xr-xtest/functional/feature_loadblock.py14
-rwxr-xr-xtest/functional/feature_settings.py7
-rwxr-xr-xtest/functional/interface_bitcoin_cli.py2
-rwxr-xr-xtest/functional/rpc_bind.py2
-rwxr-xr-xtest/functional/rpc_dumptxoutset.py3
-rwxr-xr-xtest/functional/test_framework/test_framework.py4
-rwxr-xr-xtest/functional/test_framework/test_node.py34
-rw-r--r--test/functional/test_framework/util.py2
-rwxr-xr-xtest/functional/tool_wallet.py24
-rwxr-xr-xtest/functional/wallet_backup.py63
-rwxr-xr-xtest/functional/wallet_blank.py3
-rwxr-xr-xtest/functional/wallet_crosschain.py10
-rwxr-xr-xtest/functional/wallet_descriptor.py3
-rwxr-xr-xtest/functional/wallet_dump.py9
-rwxr-xr-xtest/functional/wallet_fast_rescan.py3
-rwxr-xr-xtest/functional/wallet_hd.py21
-rwxr-xr-xtest/functional/wallet_keypool_topup.py5
-rwxr-xr-xtest/functional/wallet_pruning.py11
-rwxr-xr-xtest/functional/wallet_reorgsrestore.py5
22 files changed, 138 insertions, 168 deletions
diff --git a/test/functional/feature_blocksdir.py b/test/functional/feature_blocksdir.py
index 76b9277e2f..1a60c13c2c 100755
--- a/test/functional/feature_blocksdir.py
+++ b/test/functional/feature_blocksdir.py
@@ -5,8 +5,8 @@
"""Test the blocksdir option.
"""
-import os
import shutil
+from pathlib import Path
from test_framework.test_framework import BitcoinTestFramework, initialize_datadir
@@ -18,20 +18,20 @@ class BlocksdirTest(BitcoinTestFramework):
def run_test(self):
self.stop_node(0)
- assert os.path.isdir(os.path.join(self.nodes[0].blocks_path))
- assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "blocks"))
- shutil.rmtree(self.nodes[0].datadir)
+ assert self.nodes[0].blocks_path.is_dir()
+ assert not (self.nodes[0].datadir_path / "blocks").is_dir()
+ shutil.rmtree(self.nodes[0].datadir_path)
initialize_datadir(self.options.tmpdir, 0, self.chain)
self.log.info("Starting with nonexistent blocksdir ...")
- blocksdir_path = os.path.join(self.options.tmpdir, 'blocksdir')
+ blocksdir_path = Path(self.options.tmpdir) / 'blocksdir'
self.nodes[0].assert_start_raises_init_error([f"-blocksdir={blocksdir_path}"], f'Error: Specified blocks directory "{blocksdir_path}" does not exist.')
- os.mkdir(blocksdir_path)
+ blocksdir_path.mkdir()
self.log.info("Starting with existing blocksdir ...")
self.start_node(0, [f"-blocksdir={blocksdir_path}"])
self.log.info("mining blocks..")
self.generatetoaddress(self.nodes[0], 10, self.nodes[0].get_deterministic_priv_key().address)
- assert os.path.isfile(os.path.join(blocksdir_path, self.chain, "blocks", "blk00000.dat"))
- assert os.path.isdir(os.path.join(self.nodes[0].blocks_path, "index"))
+ assert (blocksdir_path / self.chain / "blocks" / "blk00000.dat").is_file()
+ assert (self.nodes[0].blocks_path / "index").is_dir()
if __name__ == '__main__':
diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py
index 97ee9538dc..dcea662089 100755
--- a/test/functional/feature_config_args.py
+++ b/test/functional/feature_config_args.py
@@ -5,7 +5,7 @@
"""Test various command line arguments and configuration file parameters."""
import os
-import pathlib
+from pathlib import Path
import re
import sys
import tempfile
@@ -39,8 +39,8 @@ class ConfArgsTest(BitcoinTestFramework):
extra_args=[f'-conf={bad_conf_file_path}'],
expected_msg=conf_in_config_file_err,
)
- inc_conf_file_path = os.path.join(self.nodes[0].datadir, 'include.conf')
- with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf:
+ inc_conf_file_path = self.nodes[0].datadir_path / 'include.conf'
+ with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a', encoding='utf-8') as conf:
conf.write(f'includeconf={inc_conf_file_path}\n')
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
conf.write('conf=some.conf\n')
@@ -97,8 +97,8 @@ class ConfArgsTest(BitcoinTestFramework):
conf.write('server=1\nrpcuser=someuser\n[main]\nrpcpassword=some#pass')
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 4, using # in rpcpassword can be ambiguous and should be avoided')
- inc_conf_file2_path = os.path.join(self.nodes[0].datadir, 'include2.conf')
- with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf:
+ inc_conf_file2_path = self.nodes[0].datadir_path / 'include2.conf'
+ with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a', encoding='utf-8') as conf:
conf.write(f'includeconf={inc_conf_file2_path}\n')
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
@@ -123,15 +123,15 @@ class ConfArgsTest(BitcoinTestFramework):
# Create a temporary directory that will be treated as the default data
# directory by bitcoind.
- env, default_datadir = util.get_temp_default_datadir(pathlib.Path(self.options.tmpdir, "test_config_file_log"))
+ env, default_datadir = util.get_temp_default_datadir(Path(self.options.tmpdir, "test_config_file_log"))
default_datadir.mkdir(parents=True)
# Write a bitcoin.conf file in the default data directory containing a
# datadir= line pointing at the node datadir.
node = self.nodes[0]
- conf_text = pathlib.Path(node.bitcoinconf).read_text()
+ conf_text = node.bitcoinconf.read_text()
conf_path = default_datadir / "bitcoin.conf"
- conf_path.write_text(f"datadir={node.datadir}\n{conf_text}")
+ conf_path.write_text(f"datadir={node.datadir_path}\n{conf_text}")
# Drop the node -datadir= argument during this test, because if it is
# specified it would take precedence over the datadir setting in the
@@ -218,7 +218,8 @@ class ConfArgsTest(BitcoinTestFramework):
def test_seed_peers(self):
self.log.info('Test seed peers')
- default_data_dir = self.nodes[0].datadir
+ default_data_dir = self.nodes[0].datadir_path
+ peer_dat = default_data_dir / 'peers.dat'
# Only regtest has no fixed seeds. To avoid connections to random
# nodes, regtest is the only network where it is safe to enable
# -fixedseeds in tests
@@ -229,7 +230,7 @@ class ConfArgsTest(BitcoinTestFramework):
# We expect the node will use DNS Seeds, but Regtest mode does not have
# any valid DNS seeds. So after 60 seconds, the node should fallback to
# fixed seeds
- assert not os.path.exists(os.path.join(default_data_dir, "peers.dat"))
+ assert not peer_dat.exists()
start = int(time.time())
with self.nodes[0].assert_debug_log(
expected_msgs=[
@@ -248,7 +249,7 @@ class ConfArgsTest(BitcoinTestFramework):
# No peers.dat exists and -dnsseed=0
# We expect the node will fallback immediately to fixed seeds
- assert not os.path.exists(os.path.join(default_data_dir, "peers.dat"))
+ assert not peer_dat.exists()
with self.nodes[0].assert_debug_log(expected_msgs=[
"Loaded 0 addresses from peers.dat",
"DNS seeding disabled",
@@ -260,7 +261,7 @@ class ConfArgsTest(BitcoinTestFramework):
# No peers.dat exists and dns seeds are disabled.
# We expect the node will not add fixed seeds when explicitly disabled.
- assert not os.path.exists(os.path.join(default_data_dir, "peers.dat"))
+ assert not peer_dat.exists()
with self.nodes[0].assert_debug_log(expected_msgs=[
"Loaded 0 addresses from peers.dat",
"DNS seeding disabled",
@@ -271,7 +272,7 @@ class ConfArgsTest(BitcoinTestFramework):
# No peers.dat exists and -dnsseed=0, but a -addnode is provided
# We expect the node will allow 60 seconds prior to using fixed seeds
- assert not os.path.exists(os.path.join(default_data_dir, "peers.dat"))
+ assert not peer_dat.exists()
start = int(time.time())
with self.nodes[0].assert_debug_log(
expected_msgs=[
@@ -323,16 +324,16 @@ class ConfArgsTest(BitcoinTestFramework):
'because a conflicting -conf file argument is passed.')
node = self.nodes[0]
with tempfile.NamedTemporaryFile(dir=self.options.tmpdir, mode="wt", delete=False) as temp_conf:
- temp_conf.write(f"datadir={node.datadir}\n")
+ temp_conf.write(f"datadir={node.datadir_path}\n")
node.assert_start_raises_init_error([f"-conf={temp_conf.name}"], re.escape(
- f'Error: Data directory "{node.datadir}" contains a "bitcoin.conf" file which is ignored, because a '
+ f'Error: Data directory "{node.datadir_path}" contains a "bitcoin.conf" file which is ignored, because a '
f'different configuration file "{temp_conf.name}" from command line argument "-conf={temp_conf.name}" '
f'is being used instead.') + r"[\s\S]*", match=ErrorMatch.FULL_REGEX)
# Test that passing a redundant -conf command line argument pointing to
# the same bitcoin.conf that would be loaded anyway does not trigger an
# error.
- self.start_node(0, [f'-conf={node.datadir}/bitcoin.conf'])
+ self.start_node(0, [f'-conf={node.datadir_path}/bitcoin.conf'])
self.stop_node(0)
def test_ignored_default_conf(self):
@@ -346,7 +347,7 @@ class ConfArgsTest(BitcoinTestFramework):
# Create a temporary directory that will be treated as the default data
# directory by bitcoind.
- env, default_datadir = util.get_temp_default_datadir(pathlib.Path(self.options.tmpdir, "home"))
+ env, default_datadir = util.get_temp_default_datadir(Path(self.options.tmpdir, "home"))
default_datadir.mkdir(parents=True)
# Write a bitcoin.conf file in the default data directory containing a
@@ -354,7 +355,7 @@ class ConfArgsTest(BitcoinTestFramework):
# startup error because the node datadir contains a different
# bitcoin.conf that would be ignored.
node = self.nodes[0]
- (default_datadir / "bitcoin.conf").write_text(f"datadir={node.datadir}\n")
+ (default_datadir / "bitcoin.conf").write_text(f"datadir={node.datadir_path}\n")
# Drop the node -datadir= argument during this test, because if it is
# specified it would take precedence over the datadir setting in the
@@ -362,7 +363,7 @@ class ConfArgsTest(BitcoinTestFramework):
node_args = node.args
node.args = [arg for arg in node.args if not arg.startswith("-datadir=")]
node.assert_start_raises_init_error([], re.escape(
- f'Error: Data directory "{node.datadir}" contains a "bitcoin.conf" file which is ignored, because a '
+ f'Error: Data directory "{node.datadir_path}" contains a "bitcoin.conf" file which is ignored, because a '
f'different configuration file "{default_datadir}/bitcoin.conf" from data directory "{default_datadir}" '
f'is being used instead.') + r"[\s\S]*", env=env, match=ErrorMatch.FULL_REGEX)
node.args = node_args
@@ -392,16 +393,16 @@ class ConfArgsTest(BitcoinTestFramework):
# Remove the -datadir argument so it doesn't override the config file
self.nodes[0].args = [arg for arg in self.nodes[0].args if not arg.startswith("-datadir")]
- default_data_dir = self.nodes[0].datadir
- new_data_dir = os.path.join(default_data_dir, 'newdatadir')
- new_data_dir_2 = os.path.join(default_data_dir, 'newdatadir2')
+ default_data_dir = self.nodes[0].datadir_path
+ new_data_dir = default_data_dir / 'newdatadir'
+ new_data_dir_2 = default_data_dir / 'newdatadir2'
# Check that using -datadir argument on non-existent directory fails
- self.nodes[0].datadir = new_data_dir
+ self.nodes[0].datadir_path = new_data_dir
self.nodes[0].assert_start_raises_init_error([f'-datadir={new_data_dir}'], f'Error: Specified data directory "{new_data_dir}" does not exist.')
# Check that using non-existent datadir in conf file fails
- conf_file = os.path.join(default_data_dir, "bitcoin.conf")
+ conf_file = default_data_dir / "bitcoin.conf"
# datadir needs to be set before [chain] section
with open(conf_file, encoding='utf8') as f:
@@ -413,20 +414,20 @@ class ConfArgsTest(BitcoinTestFramework):
self.nodes[0].assert_start_raises_init_error([f'-conf={conf_file}'], f'Error: Error reading configuration file: specified data directory "{new_data_dir}" does not exist.')
# Check that an explicitly specified config file that cannot be opened fails
- none_existent_conf_file = os.path.join(default_data_dir, "none_existent_bitcoin.conf")
- self.nodes[0].assert_start_raises_init_error(['-conf=' + none_existent_conf_file], 'Error: Error reading configuration file: specified config file "' + none_existent_conf_file + '" could not be opened.')
+ none_existent_conf_file = default_data_dir / "none_existent_bitcoin.conf"
+ self.nodes[0].assert_start_raises_init_error(['-conf=' + f'{none_existent_conf_file}'], 'Error: Error reading configuration file: specified config file "' + f'{none_existent_conf_file}' + '" could not be opened.')
# Create the directory and ensure the config file now works
- os.mkdir(new_data_dir)
+ new_data_dir.mkdir()
self.start_node(0, [f'-conf={conf_file}'])
self.stop_node(0)
- assert os.path.exists(os.path.join(new_data_dir, self.chain, 'blocks'))
+ assert (new_data_dir / self.chain / 'blocks').exists()
# Ensure command line argument overrides datadir in conf
- os.mkdir(new_data_dir_2)
- self.nodes[0].datadir = new_data_dir_2
+ new_data_dir_2.mkdir()
+ self.nodes[0].datadir_path = new_data_dir_2
self.start_node(0, [f'-datadir={new_data_dir_2}', f'-conf={conf_file}'])
- assert os.path.exists(os.path.join(new_data_dir_2, self.chain, 'blocks'))
+ assert (new_data_dir_2 / self.chain / 'blocks').exists()
if __name__ == '__main__':
diff --git a/test/functional/feature_filelock.py b/test/functional/feature_filelock.py
index cf2f21d553..24a68a04bf 100755
--- a/test/functional/feature_filelock.py
+++ b/test/functional/feature_filelock.py
@@ -28,7 +28,7 @@ class FilelockTest(BitcoinTestFramework):
self.log.info("Check that we can't start a second bitcoind instance using the same datadir")
expected_msg = f"Error: Cannot obtain a lock on data directory {datadir}. {self.config['environment']['PACKAGE_NAME']} is probably already running."
- self.nodes[1].assert_start_raises_init_error(extra_args=[f'-datadir={self.nodes[0].datadir}', '-noserver'], expected_msg=expected_msg)
+ self.nodes[1].assert_start_raises_init_error(extra_args=[f'-datadir={self.nodes[0].datadir_path}', '-noserver'], expected_msg=expected_msg)
if self.is_wallet_compiled():
def check_wallet_filelock(descriptors):
diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py
index 12d65fde68..5129e0d328 100755
--- a/test/functional/feature_loadblock.py
+++ b/test/functional/feature_loadblock.py
@@ -10,7 +10,7 @@ To generate that file this test uses the helper scripts available
in contrib/linearize.
"""
-import os
+from pathlib import Path
import subprocess
import sys
import tempfile
@@ -32,10 +32,10 @@ class LoadblockTest(BitcoinTestFramework):
self.generate(self.nodes[0], COINBASE_MATURITY, sync_fun=self.no_op)
# Parsing the url of our node to get settings for config file
- data_dir = self.nodes[0].datadir
+ data_dir = self.nodes[0].datadir_path
node_url = urllib.parse.urlparse(self.nodes[0].url)
- cfg_file = os.path.join(data_dir, "linearize.cfg")
- bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat")
+ cfg_file = data_dir / "linearize.cfg"
+ bootstrap_file = Path(self.options.tmpdir) / "bootstrap.dat"
genesis_block = self.nodes[0].getblockhash(0)
blocks_dir = self.nodes[0].blocks_path
hash_list = tempfile.NamedTemporaryFile(dir=data_dir,
@@ -58,16 +58,16 @@ class LoadblockTest(BitcoinTestFramework):
cfg.write(f"hashlist={hash_list.name}\n")
base_dir = self.config["environment"]["SRCDIR"]
- linearize_dir = os.path.join(base_dir, "contrib", "linearize")
+ linearize_dir = Path(base_dir) / "contrib" / "linearize"
self.log.info("Run linearization of block hashes")
- linearize_hashes_file = os.path.join(linearize_dir, "linearize-hashes.py")
+ linearize_hashes_file = linearize_dir / "linearize-hashes.py"
subprocess.run([sys.executable, linearize_hashes_file, cfg_file],
stdout=hash_list,
check=True)
self.log.info("Run linearization of block data")
- linearize_data_file = os.path.join(linearize_dir, "linearize-data.py")
+ linearize_data_file = linearize_dir / "linearize-data.py"
subprocess.run([sys.executable, linearize_data_file, cfg_file],
check=True)
diff --git a/test/functional/feature_settings.py b/test/functional/feature_settings.py
index bcae963428..1bacdd447a 100755
--- a/test/functional/feature_settings.py
+++ b/test/functional/feature_settings.py
@@ -6,7 +6,6 @@
import json
-from pathlib import Path
from test_framework.test_framework import BitcoinTestFramework
from test_framework.test_node import ErrorMatch
@@ -21,8 +20,8 @@ class SettingsTest(BitcoinTestFramework):
def run_test(self):
node, = self.nodes
- settings = Path(node.chain_path, "settings.json")
- conf = Path(node.datadir, "bitcoin.conf")
+ settings = node.chain_path / "settings.json"
+ conf = node.datadir_path / "bitcoin.conf"
# Assert empty settings file was created
self.stop_node(0)
@@ -79,7 +78,7 @@ class SettingsTest(BitcoinTestFramework):
self.stop_node(0)
# Test alternate settings path
- altsettings = Path(node.datadir, "altsettings.json")
+ altsettings = node.datadir_path / "altsettings.json"
with altsettings.open("w") as fp:
fp.write('{"key": "value"}')
with node.assert_debug_log(expected_msgs=['Setting file arg: key = "value"']):
diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py
index 25ea557217..83bb5121e5 100755
--- a/test/functional/interface_bitcoin_cli.py
+++ b/test/functional/interface_bitcoin_cli.py
@@ -94,7 +94,7 @@ class TestBitcoinCli(BitcoinTestFramework):
assert_equal(self.nodes[0].cli("-named", "echo", "arg0=0", "arg1=1", "arg2=2", "arg1=3").send_cli(), ['0', '3', '2'])
assert_raises_rpc_error(-8, "Parameter args specified multiple times", self.nodes[0].cli("-named", "echo", "args=[0,1,2,3]", "4", "5", "6", ).send_cli)
- user, password = get_auth_cookie(self.nodes[0].datadir, self.chain)
+ user, password = get_auth_cookie(self.nodes[0].datadir_path, self.chain)
self.log.info("Test -stdinrpcpass option")
assert_equal(BLOCKS, self.nodes[0].cli(f'-rpcuser={user}', '-stdinrpcpass', input=password).getblockcount())
diff --git a/test/functional/rpc_bind.py b/test/functional/rpc_bind.py
index 664a15a5ec..43cd23fc7a 100755
--- a/test/functional/rpc_bind.py
+++ b/test/functional/rpc_bind.py
@@ -56,7 +56,7 @@ class RPCBindTest(BitcoinTestFramework):
self.nodes[0].rpchost = None
self.start_nodes([node_args])
# connect to node through non-loopback interface
- node = get_rpc_proxy(rpc_url(self.nodes[0].datadir, 0, self.chain, "%s:%d" % (rpchost, rpcport)), 0, coveragedir=self.options.coveragedir)
+ node = get_rpc_proxy(rpc_url(self.nodes[0].datadir_path, 0, self.chain, "%s:%d" % (rpchost, rpcport)), 0, coveragedir=self.options.coveragedir)
node.getnetworkinfo()
self.stop_nodes()
diff --git a/test/functional/rpc_dumptxoutset.py b/test/functional/rpc_dumptxoutset.py
index 2cae602cc2..f378878181 100755
--- a/test/functional/rpc_dumptxoutset.py
+++ b/test/functional/rpc_dumptxoutset.py
@@ -4,7 +4,6 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the generation of UTXO snapshots using `dumptxoutset`.
"""
-from pathlib import Path
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework
@@ -29,7 +28,7 @@ class DumptxoutsetTest(BitcoinTestFramework):
FILENAME = 'txoutset.dat'
out = node.dumptxoutset(FILENAME)
- expected_path = Path(node.datadir) / self.chain / FILENAME
+ expected_path = node.datadir_path / self.chain / FILENAME
assert expected_path.is_file()
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index c46c04c0ec..50444b95bb 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -1006,5 +1006,5 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
return self.config["components"].getboolean("USE_BDB")
def has_blockfile(self, node, filenum: str):
- blocksdir = os.path.join(node.datadir, self.chain, 'blocks', '')
- return os.path.isfile(os.path.join(blocksdir, f"blk{filenum}.dat"))
+ blocksdir = node.datadir_path / self.chain / 'blocks'
+ return (blocksdir / f"blk{filenum}.dat").is_file()
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 33a7539641..fc92aa445a 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -67,7 +67,7 @@ class TestNode():
To make things easier for the test writer, any unrecognised messages will
be dispatched to the RPC connection."""
- def __init__(self, i, datadir, *, chain, rpchost, timewait, timeout_factor, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None, descriptors=False):
+ def __init__(self, i, datadir_path, *, chain, rpchost, timewait, timeout_factor, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None, descriptors=False):
"""
Kwargs:
start_perf (bool): If True, begin profiling the node with `perf` as soon as
@@ -76,10 +76,10 @@ class TestNode():
self.index = i
self.p2p_conn_index = 1
- self.datadir = datadir
- self.bitcoinconf = os.path.join(self.datadir, "bitcoin.conf")
- self.stdout_dir = os.path.join(self.datadir, "stdout")
- self.stderr_dir = os.path.join(self.datadir, "stderr")
+ self.datadir_path = datadir_path
+ self.bitcoinconf = self.datadir_path / "bitcoin.conf"
+ self.stdout_dir = self.datadir_path / "stdout"
+ self.stderr_dir = self.datadir_path / "stderr"
self.chain = chain
self.rpchost = rpchost
self.rpc_timeout = timewait
@@ -88,7 +88,7 @@ class TestNode():
self.cwd = cwd
self.descriptors = descriptors
if extra_conf is not None:
- append_config(datadir, extra_conf)
+ append_config(self.datadir_path, extra_conf)
# Most callers will just need to add extra args to the standard list below.
# For those callers that need more flexibility, they can just set the args property directly.
# Note that common args are set in the config file (see initialize_datadir)
@@ -99,7 +99,7 @@ class TestNode():
# spam debug.log.
self.args = [
self.binary,
- "-datadir=" + self.datadir,
+ f"-datadir={self.datadir_path}",
"-logtimemicros",
"-debug",
"-debugexclude=libevent",
@@ -111,9 +111,7 @@ class TestNode():
self.args.append("-disablewallet")
if use_valgrind:
- default_suppressions_file = os.path.join(
- os.path.dirname(os.path.realpath(__file__)),
- "..", "..", "..", "contrib", "valgrind.supp")
+ default_suppressions_file = Path(__file__).parents[3] / "contrib" / "valgrind.supp"
suppressions_file = os.getenv("VALGRIND_SUPPRESSIONS_FILE",
default_suppressions_file)
self.args = ["valgrind", "--suppressions={}".format(suppressions_file),
@@ -127,7 +125,7 @@ class TestNode():
if self.version_is_at_least(239000):
self.args.append("-loglevel=trace")
- self.cli = TestNodeCLI(bitcoin_cli, self.datadir)
+ self.cli = TestNodeCLI(bitcoin_cli, self.datadir_path)
self.use_cli = use_cli
self.start_perf = start_perf
@@ -213,7 +211,7 @@ class TestNode():
# Delete any existing cookie file -- if such a file exists (eg due to
# unclean shutdown), it will get overwritten anyway by bitcoind, and
# potentially interfere with our attempt to authenticate
- delete_cookie_file(self.datadir, self.chain)
+ delete_cookie_file(self.datadir_path, self.chain)
# add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are written to stderr and not the terminal
subp_env = dict(os.environ, LIBC_FATAL_STDERR_="1")
@@ -243,7 +241,7 @@ class TestNode():
f'bitcoind exited with status {self.process.returncode} during initialization. {str_error}'))
try:
rpc = get_rpc_proxy(
- rpc_url(self.datadir, self.index, self.chain, self.rpchost),
+ rpc_url(self.datadir_path, self.index, self.chain, self.rpchost),
self.index,
timeout=self.rpc_timeout // 2, # Shorter timeout to allow for one retry in case of ETIMEDOUT
coveragedir=self.coverage_dir,
@@ -307,7 +305,7 @@ class TestNode():
poll_per_s = 4
for _ in range(poll_per_s * self.rpc_timeout):
try:
- get_auth_cookie(self.datadir, self.chain)
+ get_auth_cookie(self.datadir_path, self.chain)
self.log.debug("Cookie credentials successfully retrieved")
return
except ValueError: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting
@@ -425,10 +423,6 @@ class TestNode():
conf.write(conf_data)
@property
- def datadir_path(self) -> Path:
- return Path(self.datadir)
-
- @property
def chain_path(self) -> Path:
return self.datadir_path / self.chain
@@ -556,7 +550,7 @@ class TestNode():
"perf output won't be very useful without debug symbols compiled into bitcoind")
output_path = tempfile.NamedTemporaryFile(
- dir=self.datadir,
+ dir=self.datadir_path,
prefix="{}.perf.data.".format(profile_name or 'test'),
delete=False,
).name
@@ -783,7 +777,7 @@ class TestNodeCLI():
"""Run bitcoin-cli command. Deserializes returned string as python object."""
pos_args = [arg_to_cli(arg) for arg in args]
named_args = [str(key) + "=" + arg_to_cli(value) for (key, value) in kwargs.items()]
- p_args = [self.binary, "-datadir=" + self.datadir] + self.options
+ p_args = [self.binary, f"-datadir={self.datadir}"] + self.options
if named_args:
p_args += ["-named"]
if command is not None:
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 0c10d500af..61346e9d19 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -413,7 +413,7 @@ def write_config(config_path, *, n, chain, extra_config="", disable_autoconnect=
def get_datadir_path(dirname, n):
- return os.path.join(dirname, "node" + str(n))
+ return pathlib.Path(dirname) / f"node{n}"
def get_temp_default_datadir(temp_dir: pathlib.Path) -> Tuple[dict, pathlib.Path]:
diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py
index 8b0c8ce405..fc042bca66 100755
--- a/test/functional/tool_wallet.py
+++ b/test/functional/tool_wallet.py
@@ -32,7 +32,7 @@ class ToolWalletTest(BitcoinTestFramework):
self.skip_if_no_wallet_tool()
def bitcoin_wallet_process(self, *args):
- default_args = ['-datadir={}'.format(self.nodes[0].datadir), '-chain=%s' % self.chain]
+ default_args = ['-datadir={}'.format(self.nodes[0].datadir_path), '-chain=%s' % self.chain]
if not self.options.descriptors and 'create' in args:
default_args.append('-legacy')
@@ -153,8 +153,8 @@ class ToolWalletTest(BitcoinTestFramework):
assert_equal(v, r[k])
def do_tool_createfromdump(self, wallet_name, dumpfile, file_format=None):
- dumppath = os.path.join(self.nodes[0].datadir, dumpfile)
- rt_dumppath = os.path.join(self.nodes[0].datadir, "rt-{}.dump".format(wallet_name))
+ dumppath = self.nodes[0].datadir_path / dumpfile
+ rt_dumppath = self.nodes[0].datadir_path / "rt-{}.dump".format(wallet_name)
dump_data = self.read_dump(dumppath)
@@ -324,7 +324,7 @@ class ToolWalletTest(BitcoinTestFramework):
self.assert_raises_tool_error('No dump file provided. To use dump, -dumpfile=<filename> must be provided.', '-wallet=todump', 'dump')
self.log.info('Checking basic dump')
- wallet_dump = os.path.join(self.nodes[0].datadir, "wallet.dump")
+ wallet_dump = self.nodes[0].datadir_path / "wallet.dump"
self.assert_tool_output('The dumpfile may contain private keys. To ensure the safety of your Bitcoin, do not share the dumpfile.\n', '-wallet=todump', '-dumpfile={}'.format(wallet_dump), 'dump')
dump_data = self.read_dump(wallet_dump)
@@ -339,7 +339,7 @@ class ToolWalletTest(BitcoinTestFramework):
self.log.info('Checking createfromdump arguments')
self.assert_raises_tool_error('No dump file provided. To use createfromdump, -dumpfile=<filename> must be provided.', '-wallet=todump', 'createfromdump')
- non_exist_dump = os.path.join(self.nodes[0].datadir, "wallet.nodump")
+ non_exist_dump = self.nodes[0].datadir_path / "wallet.nodump"
self.assert_raises_tool_error('Unknown wallet file format "notaformat" provided. Please provide one of "bdb" or "sqlite".', '-wallet=todump', '-format=notaformat', '-dumpfile={}'.format(wallet_dump), 'createfromdump')
self.assert_raises_tool_error('Dump file {} does not exist.'.format(non_exist_dump), '-wallet=todump', '-dumpfile={}'.format(non_exist_dump), 'createfromdump')
wallet_path = self.nodes[0].wallets_path / "todump2"
@@ -354,17 +354,17 @@ class ToolWalletTest(BitcoinTestFramework):
self.do_tool_createfromdump("load-sqlite", "wallet.dump", "sqlite")
self.log.info('Checking createfromdump handling of magic and versions')
- bad_ver_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_ver1.dump")
+ bad_ver_wallet_dump = self.nodes[0].datadir_path / "wallet-bad_ver1.dump"
dump_data["BITCOIN_CORE_WALLET_DUMP"] = "0"
self.write_dump(dump_data, bad_ver_wallet_dump)
self.assert_raises_tool_error('Error: Dumpfile version is not supported. This version of bitcoin-wallet only supports version 1 dumpfiles. Got dumpfile with version 0', '-wallet=badload', '-dumpfile={}'.format(bad_ver_wallet_dump), 'createfromdump')
assert not (self.nodes[0].wallets_path / "badload").is_dir()
- bad_ver_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_ver2.dump")
+ bad_ver_wallet_dump = self.nodes[0].datadir_path / "wallet-bad_ver2.dump"
dump_data["BITCOIN_CORE_WALLET_DUMP"] = "2"
self.write_dump(dump_data, bad_ver_wallet_dump)
self.assert_raises_tool_error('Error: Dumpfile version is not supported. This version of bitcoin-wallet only supports version 1 dumpfiles. Got dumpfile with version 2', '-wallet=badload', '-dumpfile={}'.format(bad_ver_wallet_dump), 'createfromdump')
assert not (self.nodes[0].wallets_path / "badload").is_dir()
- bad_magic_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_magic.dump")
+ bad_magic_wallet_dump = self.nodes[0].datadir_path / "wallet-bad_magic.dump"
del dump_data["BITCOIN_CORE_WALLET_DUMP"]
dump_data["not_the_right_magic"] = "1"
self.write_dump(dump_data, bad_magic_wallet_dump, "not_the_right_magic")
@@ -372,19 +372,19 @@ class ToolWalletTest(BitcoinTestFramework):
assert not (self.nodes[0].wallets_path / "badload").is_dir()
self.log.info('Checking createfromdump handling of checksums')
- bad_sum_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_sum1.dump")
+ bad_sum_wallet_dump = self.nodes[0].datadir_path / "wallet-bad_sum1.dump"
dump_data = orig_dump.copy()
checksum = dump_data["checksum"]
dump_data["checksum"] = "1" * 64
self.write_dump(dump_data, bad_sum_wallet_dump)
self.assert_raises_tool_error('Error: Dumpfile checksum does not match. Computed {}, expected {}'.format(checksum, "1" * 64), '-wallet=bad', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
assert not (self.nodes[0].wallets_path / "badload").is_dir()
- bad_sum_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_sum2.dump")
+ bad_sum_wallet_dump = self.nodes[0].datadir_path / "wallet-bad_sum2.dump"
del dump_data["checksum"]
self.write_dump(dump_data, bad_sum_wallet_dump, skip_checksum=True)
self.assert_raises_tool_error('Error: Missing checksum', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
assert not (self.nodes[0].wallets_path / "badload").is_dir()
- bad_sum_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_sum3.dump")
+ bad_sum_wallet_dump = self.nodes[0].datadir_path / "wallet-bad_sum3.dump"
dump_data["checksum"] = "2" * 10
self.write_dump(dump_data, bad_sum_wallet_dump)
self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump')
@@ -452,7 +452,7 @@ class ToolWalletTest(BitcoinTestFramework):
self.assert_tool_output(expected_output, "-wallet=conflicts", "info")
def run_test(self):
- self.wallet_path = os.path.join(self.nodes[0].wallets_path, self.default_wallet_name, self.wallet_data_filename)
+ self.wallet_path = self.nodes[0].wallets_path / self.default_wallet_name / self.wallet_data_filename
self.test_invalid_tool_commands_and_args()
# Warning: The following tests are order-dependent.
self.test_tool_wallet_info()
diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py
index 9f6f54c7a6..eb3e0ae728 100755
--- a/test/functional/wallet_backup.py
+++ b/test/functional/wallet_backup.py
@@ -109,36 +109,35 @@ class WalletBackupTest(BitcoinTestFramework):
self.stop_node(2)
def erase_three(self):
- os.remove(os.path.join(self.nodes[0].wallets_path, self.default_wallet_name, self.wallet_data_filename))
- os.remove(os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename))
- os.remove(os.path.join(self.nodes[2].wallets_path, self.default_wallet_name, self.wallet_data_filename))
+ for node_num in range(3):
+ (self.nodes[node_num].wallets_path / self.default_wallet_name / self.wallet_data_filename).unlink()
def restore_invalid_wallet(self):
node = self.nodes[3]
- invalid_wallet_file = os.path.join(self.nodes[0].datadir, 'invalid_wallet_file.bak')
+ invalid_wallet_file = self.nodes[0].datadir_path / 'invalid_wallet_file.bak'
open(invalid_wallet_file, 'a', encoding="utf8").write('invald wallet')
wallet_name = "res0"
- not_created_wallet_file = os.path.join(node.wallets_path, wallet_name)
+ not_created_wallet_file = node.wallets_path / wallet_name
error_message = "Wallet file verification failed. Failed to load database path '{}'. Data is not in recognized format.".format(not_created_wallet_file)
assert_raises_rpc_error(-18, error_message, node.restorewallet, wallet_name, invalid_wallet_file)
- assert not os.path.exists(not_created_wallet_file)
+ assert not not_created_wallet_file.exists()
def restore_nonexistent_wallet(self):
node = self.nodes[3]
- nonexistent_wallet_file = os.path.join(self.nodes[0].datadir, 'nonexistent_wallet.bak')
+ nonexistent_wallet_file = self.nodes[0].datadir_path / 'nonexistent_wallet.bak'
wallet_name = "res0"
assert_raises_rpc_error(-8, "Backup file does not exist", node.restorewallet, wallet_name, nonexistent_wallet_file)
- not_created_wallet_file = os.path.join(node.wallets_path, wallet_name)
- assert not os.path.exists(not_created_wallet_file)
+ not_created_wallet_file = node.wallets_path / wallet_name
+ assert not not_created_wallet_file.exists()
def restore_wallet_existent_name(self):
node = self.nodes[3]
- backup_file = os.path.join(self.nodes[0].datadir, 'wallet.bak')
+ backup_file = self.nodes[0].datadir_path / 'wallet.bak'
wallet_name = "res0"
- wallet_file = os.path.join(node.wallets_path, wallet_name)
+ wallet_file = node.wallets_path / wallet_name
error_message = "Failed to create database path '{}'. Database already exists.".format(wallet_file)
assert_raises_rpc_error(-36, error_message, node.restorewallet, wallet_name, backup_file)
- assert os.path.exists(wallet_file)
+ assert wallet_file.exists()
def run_test(self):
self.log.info("Generating initial blockchain")
@@ -159,14 +158,12 @@ class WalletBackupTest(BitcoinTestFramework):
self.log.info("Backing up")
- self.nodes[0].backupwallet(os.path.join(self.nodes[0].datadir, 'wallet.bak'))
- self.nodes[1].backupwallet(os.path.join(self.nodes[1].datadir, 'wallet.bak'))
- self.nodes[2].backupwallet(os.path.join(self.nodes[2].datadir, 'wallet.bak'))
+ for node_num in range(3):
+ self.nodes[node_num].backupwallet(self.nodes[node_num].datadir_path / 'wallet.bak')
if not self.options.descriptors:
- self.nodes[0].dumpwallet(os.path.join(self.nodes[0].datadir, 'wallet.dump'))
- self.nodes[1].dumpwallet(os.path.join(self.nodes[1].datadir, 'wallet.dump'))
- self.nodes[2].dumpwallet(os.path.join(self.nodes[2].datadir, 'wallet.dump'))
+ for node_num in range(3):
+ self.nodes[node_num].dumpwallet(self.nodes[node_num].datadir_path / 'wallet.dump')
self.log.info("More transactions")
for _ in range(5):
@@ -193,17 +190,13 @@ class WalletBackupTest(BitcoinTestFramework):
self.restore_invalid_wallet()
self.restore_nonexistent_wallet()
- backup_file_0 = os.path.join(self.nodes[0].datadir, 'wallet.bak')
- backup_file_1 = os.path.join(self.nodes[1].datadir, 'wallet.bak')
- backup_file_2 = os.path.join(self.nodes[2].datadir, 'wallet.bak')
-
- self.nodes[3].restorewallet("res0", backup_file_0)
- self.nodes[3].restorewallet("res1", backup_file_1)
- self.nodes[3].restorewallet("res2", backup_file_2)
+ backup_files = []
+ for node_num in range(3):
+ backup_files.append(self.nodes[node_num].datadir_path / 'wallet.bak')
- assert os.path.exists(os.path.join(self.nodes[3].wallets_path, "res0"))
- assert os.path.exists(os.path.join(self.nodes[3].wallets_path, "res1"))
- assert os.path.exists(os.path.join(self.nodes[3].wallets_path, "res2"))
+ for idx, backup_file in enumerate(backup_files):
+ self.nodes[3].restorewallet(f'res{idx}', backup_file)
+ assert (self.nodes[3].wallets_path / f'res{idx}').exists()
res0_rpc = self.nodes[3].get_wallet_rpc("res0")
res1_rpc = self.nodes[3].get_wallet_rpc("res1")
@@ -221,22 +214,16 @@ class WalletBackupTest(BitcoinTestFramework):
self.erase_three()
#start node2 with no chain
- shutil.rmtree(os.path.join(self.nodes[2].blocks_path))
- shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'chainstate'))
+ shutil.rmtree(self.nodes[2].blocks_path)
+ shutil.rmtree(self.nodes[2].chain_path / 'chainstate')
self.start_three(["-nowallet"])
# Create new wallets for the three nodes.
# We will use this empty wallets to test the 'importwallet()' RPC command below.
for node_num in range(3):
self.nodes[node_num].createwallet(wallet_name=self.default_wallet_name, descriptors=self.options.descriptors, load_on_startup=True)
-
- assert_equal(self.nodes[0].getbalance(), 0)
- assert_equal(self.nodes[1].getbalance(), 0)
- assert_equal(self.nodes[2].getbalance(), 0)
-
- self.nodes[0].importwallet(os.path.join(self.nodes[0].datadir, 'wallet.dump'))
- self.nodes[1].importwallet(os.path.join(self.nodes[1].datadir, 'wallet.dump'))
- self.nodes[2].importwallet(os.path.join(self.nodes[2].datadir, 'wallet.dump'))
+ assert_equal(self.nodes[node_num].getbalance(), 0)
+ self.nodes[node_num].importwallet(self.nodes[node_num].datadir_path / 'wallet.dump')
self.sync_blocks()
diff --git a/test/functional/wallet_blank.py b/test/functional/wallet_blank.py
index 4836eba3b2..e646d27005 100755
--- a/test/functional/wallet_blank.py
+++ b/test/functional/wallet_blank.py
@@ -3,7 +3,6 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php.
-import os
from test_framework.test_framework import BitcoinTestFramework
from test_framework.address import (
@@ -110,7 +109,7 @@ class WalletBlankTest(BitcoinTestFramework):
assert_equal(info["descriptors"], False)
assert_equal(info["blank"], True)
- wallet_dump_path = os.path.join(self.nodes[0].datadir, "wallet.dump")
+ wallet_dump_path = self.nodes[0].datadir_path / "wallet.dump"
def_wallet.dumpwallet(wallet_dump_path)
wallet.importwallet(wallet_dump_path)
diff --git a/test/functional/wallet_crosschain.py b/test/functional/wallet_crosschain.py
index 7a1297e65f..4c5d7192ae 100755
--- a/test/functional/wallet_crosschain.py
+++ b/test/functional/wallet_crosschain.py
@@ -3,8 +3,6 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-import os
-
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_raises_rpc_error
@@ -31,13 +29,13 @@ class WalletCrossChain(BitcoinTestFramework):
def run_test(self):
self.log.info("Creating wallets")
- node0_wallet = os.path.join(self.nodes[0].datadir, 'node0_wallet')
- node0_wallet_backup = os.path.join(self.nodes[0].datadir, 'node0_wallet.bak')
+ node0_wallet = self.nodes[0].datadir_path / 'node0_wallet'
+ node0_wallet_backup = self.nodes[0].datadir_path / 'node0_wallet.bak'
self.nodes[0].createwallet(node0_wallet)
self.nodes[0].backupwallet(node0_wallet_backup)
self.nodes[0].unloadwallet(node0_wallet)
- node1_wallet = os.path.join(self.nodes[1].datadir, 'node1_wallet')
- node1_wallet_backup = os.path.join(self.nodes[0].datadir, 'node1_wallet.bak')
+ node1_wallet = self.nodes[1].datadir_path / 'node1_wallet'
+ node1_wallet_backup = self.nodes[0].datadir_path / 'node1_wallet.bak'
self.nodes[1].createwallet(node1_wallet)
self.nodes[1].backupwallet(node1_wallet_backup)
self.nodes[1].unloadwallet(node1_wallet)
diff --git a/test/functional/wallet_descriptor.py b/test/functional/wallet_descriptor.py
index 6af01f8cfd..c220675eb6 100755
--- a/test/functional/wallet_descriptor.py
+++ b/test/functional/wallet_descriptor.py
@@ -3,7 +3,6 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test descriptor wallet function."""
-import os
try:
import sqlite3
@@ -234,7 +233,7 @@ class WalletDescriptorTest(BitcoinTestFramework):
self.log.info("Test that loading descriptor wallet containing legacy key types throws error")
self.nodes[0].createwallet(wallet_name="crashme", descriptors=True)
self.nodes[0].unloadwallet("crashme")
- wallet_db = os.path.join(self.nodes[0].wallets_path, "crashme", self.wallet_data_filename)
+ wallet_db = self.nodes[0].wallets_path / "crashme" / self.wallet_data_filename
conn = sqlite3.connect(wallet_db)
with conn:
# add "cscript" entry: key type is uint160 (20 bytes), value type is CScript (zero-length here)
diff --git a/test/functional/wallet_dump.py b/test/functional/wallet_dump.py
index 8c68d03f97..fdce9739eb 100755
--- a/test/functional/wallet_dump.py
+++ b/test/functional/wallet_dump.py
@@ -4,7 +4,6 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the dumpwallet RPC."""
import datetime
-import os
import time
from test_framework.test_framework import BitcoinTestFramework
@@ -111,8 +110,8 @@ class WalletDumpTest(BitcoinTestFramework):
def run_test(self):
self.nodes[0].createwallet("dump")
- wallet_unenc_dump = os.path.join(self.nodes[0].datadir, "wallet.unencrypted.dump")
- wallet_enc_dump = os.path.join(self.nodes[0].datadir, "wallet.encrypted.dump")
+ wallet_unenc_dump = self.nodes[0].datadir_path / "wallet.unencrypted.dump"
+ wallet_enc_dump = self.nodes[0].datadir_path / "wallet.encrypted.dump"
# generate 30 addresses to compare against the dump
# - 10 legacy P2PKH
@@ -156,7 +155,7 @@ class WalletDumpTest(BitcoinTestFramework):
self.log.info('Dump unencrypted wallet')
result = self.nodes[0].dumpwallet(wallet_unenc_dump)
- assert_equal(result['filename'], wallet_unenc_dump)
+ assert_equal(result['filename'], str(wallet_unenc_dump))
found_comments, found_legacy_addr, found_p2sh_segwit_addr, found_bech32_addr, found_script_addr, found_addr_chg, found_addr_rsv, hd_master_addr_unenc = \
read_dump(wallet_unenc_dump, addrs, [multisig_addr], None)
@@ -220,7 +219,7 @@ class WalletDumpTest(BitcoinTestFramework):
w3.sendtoaddress(w3.getnewaddress(), 10)
w3.unloadwallet()
self.nodes[0].loadwallet("w3")
- w3.dumpwallet(os.path.join(self.nodes[0].datadir, "w3.dump"))
+ w3.dumpwallet(self.nodes[0].datadir_path / "w3.dump")
if __name__ == '__main__':
WalletDumpTest().main()
diff --git a/test/functional/wallet_fast_rescan.py b/test/functional/wallet_fast_rescan.py
index 112aa25e86..2f9c924e71 100755
--- a/test/functional/wallet_fast_rescan.py
+++ b/test/functional/wallet_fast_rescan.py
@@ -4,7 +4,6 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test that fast rescan using block filters for descriptor wallets detects
top-ups correctly and finds the same transactions than the slow variant."""
-import os
from typing import List
from test_framework.address import address_to_scriptpubkey
@@ -43,7 +42,7 @@ class WalletFastRescanTest(BitcoinTestFramework):
wallet = MiniWallet(node)
self.log.info("Create descriptor wallet with backup")
- WALLET_BACKUP_FILENAME = os.path.join(node.datadir, 'wallet.bak')
+ WALLET_BACKUP_FILENAME = node.datadir_path / 'wallet.bak'
node.createwallet(wallet_name='topup_test', descriptors=True)
w = node.get_wallet_rpc('topup_test')
fixed_key = get_generate_key()
diff --git a/test/functional/wallet_hd.py b/test/functional/wallet_hd.py
index 62f8301c16..0f4b7cfcb1 100755
--- a/test/functional/wallet_hd.py
+++ b/test/functional/wallet_hd.py
@@ -4,7 +4,6 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test Hierarchical Deterministic wallet function."""
-import os
import shutil
from test_framework.blocktools import COINBASE_MATURITY
@@ -51,8 +50,8 @@ class WalletHDTest(BitcoinTestFramework):
self.nodes[1].importprivkey(non_hd_key)
# This should be enough to keep the master key and the non-HD key
- self.nodes[1].backupwallet(os.path.join(self.nodes[1].datadir, "hd.bak"))
- #self.nodes[1].dumpwallet(os.path.join(self.nodes[1].datadir, "hd.dump"))
+ self.nodes[1].backupwallet(self.nodes[1].datadir_path / "hd.bak")
+ #self.nodes[1].dumpwallet(self.nodes[1].datadir_path / "hd.dump")
# Derive some HD addresses and remember the last
# Also send funds to each add
@@ -87,11 +86,11 @@ class WalletHDTest(BitcoinTestFramework):
self.stop_node(1)
# we need to delete the complete chain directory
# otherwise node1 would auto-recover all funds in flag the keypool keys as used
- shutil.rmtree(os.path.join(self.nodes[1].blocks_path))
- shutil.rmtree(os.path.join(self.nodes[1].chain_path, "chainstate"))
+ shutil.rmtree(self.nodes[1].blocks_path)
+ shutil.rmtree(self.nodes[1].chain_path / "chainstate")
shutil.copyfile(
- os.path.join(self.nodes[1].datadir, "hd.bak"),
- os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename),
+ self.nodes[1].datadir_path / "hd.bak",
+ self.nodes[1].wallets_path / self.default_wallet_name / self.wallet_data_filename
)
self.start_node(1)
@@ -115,11 +114,11 @@ class WalletHDTest(BitcoinTestFramework):
# Try a RPC based rescan
self.stop_node(1)
- shutil.rmtree(os.path.join(self.nodes[1].blocks_path))
- shutil.rmtree(os.path.join(self.nodes[1].chain_path, "chainstate"))
+ shutil.rmtree(self.nodes[1].blocks_path)
+ shutil.rmtree(self.nodes[1].chain_path / "chainstate")
shutil.copyfile(
- os.path.join(self.nodes[1].datadir, "hd.bak"),
- os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename),
+ self.nodes[1].datadir_path / "hd.bak",
+ self.nodes[1].wallets_path / self.default_wallet_name / self.wallet_data_filename
)
self.start_node(1, extra_args=self.extra_args[1])
self.connect_nodes(0, 1)
diff --git a/test/functional/wallet_keypool_topup.py b/test/functional/wallet_keypool_topup.py
index 0f1c33a0c2..48180e8294 100755
--- a/test/functional/wallet_keypool_topup.py
+++ b/test/functional/wallet_keypool_topup.py
@@ -10,7 +10,6 @@ Two nodes. Node1 is under test. Node0 is providing transactions and generating b
- Generate 110 keys (enough to drain the keypool). Store key 90 (in the initial keypool) and key 110 (beyond the initial keypool). Send funds to key 90 and key 110.
- Stop node1, clear the datadir, move wallet file back into the datadir and restart node1.
- connect node1 to node0. Verify that they sync and node1 receives its funds."""
-import os
import shutil
from test_framework.blocktools import COINBASE_MATURITY
@@ -33,8 +32,8 @@ class KeypoolRestoreTest(BitcoinTestFramework):
self.skip_if_no_wallet()
def run_test(self):
- wallet_path = os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename)
- wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak")
+ wallet_path = self.nodes[1].wallets_path / self.default_wallet_name / self.wallet_data_filename
+ wallet_backup_path = self.nodes[1].datadir_path / "wallet.bak"
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
self.log.info("Make backup of wallet")
diff --git a/test/functional/wallet_pruning.py b/test/functional/wallet_pruning.py
index 06bd992da7..6e252b5406 100755
--- a/test/functional/wallet_pruning.py
+++ b/test/functional/wallet_pruning.py
@@ -4,7 +4,6 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test wallet import on pruned node."""
-import os
from test_framework.util import assert_equal, assert_raises_rpc_error
from test_framework.blocktools import (
@@ -74,7 +73,7 @@ class WalletPruningTest(BitcoinTestFramework):
# Import wallet into pruned node
self.nodes[1].createwallet(wallet_name="wallet_pruned", descriptors=False, load_on_startup=True)
- self.nodes[1].importwallet(os.path.join(self.nodes[0].datadir, wallet_file))
+ self.nodes[1].importwallet(self.nodes[0].datadir_path / wallet_file)
# Make sure that prune node's wallet correctly accounts for balances
assert_equal(self.nodes[1].getbalance(), self.nodes[0].getbalance())
@@ -93,12 +92,12 @@ class WalletPruningTest(BitcoinTestFramework):
# Make sure wallet cannot be imported because of missing blocks
# This will try to rescan blocks `TIMESTAMP_WINDOW` (2h) before the wallet birthheight.
# There are 6 blocks an hour, so 11 blocks (excluding birthheight).
- assert_raises_rpc_error(-4, f"Pruned blocks from height {wallet_birthheight - 11} required to import keys. Use RPC call getblockchaininfo to determine your pruned height.", self.nodes[1].importwallet, os.path.join(self.nodes[0].datadir, wallet_file))
+ assert_raises_rpc_error(-4, f"Pruned blocks from height {wallet_birthheight - 11} required to import keys. Use RPC call getblockchaininfo to determine your pruned height.", self.nodes[1].importwallet, self.nodes[0].datadir_path / wallet_file)
self.log.info("- Done")
def get_birthheight(self, wallet_file):
"""Gets birthheight of a wallet on node0"""
- with open(os.path.join(self.nodes[0].datadir, wallet_file), 'r', encoding="utf8") as f:
+ with open(self.nodes[0].datadir_path / wallet_file, 'r', encoding="utf8") as f:
for line in f:
if line.startswith('# * Best block at time of backup'):
wallet_birthheight = int(line.split(' ')[9])
@@ -106,12 +105,12 @@ class WalletPruningTest(BitcoinTestFramework):
def has_block(self, block_index):
"""Checks if the pruned node has the specific blk0000*.dat file"""
- return os.path.isfile(os.path.join(self.nodes[1].blocks_path, f"blk{block_index:05}.dat"))
+ return (self.nodes[1].blocks_path / f"blk{block_index:05}.dat").is_file()
def create_wallet(self, wallet_name, *, unload=False):
"""Creates and dumps a wallet on the non-pruned node0 to be later import by the pruned node"""
self.nodes[0].createwallet(wallet_name=wallet_name, descriptors=False, load_on_startup=True)
- self.nodes[0].dumpwallet(os.path.join(self.nodes[0].datadir, wallet_name + ".dat"))
+ self.nodes[0].dumpwallet(self.nodes[0].datadir_path / f"{wallet_name}.dat")
if (unload):
self.nodes[0].unloadwallet(wallet_name)
diff --git a/test/functional/wallet_reorgsrestore.py b/test/functional/wallet_reorgsrestore.py
index af01b9439f..86a2905c72 100755
--- a/test/functional/wallet_reorgsrestore.py
+++ b/test/functional/wallet_reorgsrestore.py
@@ -14,7 +14,6 @@ disconnected.
"""
from decimal import Decimal
-import os
import shutil
from test_framework.test_framework import BitcoinTestFramework
@@ -88,8 +87,8 @@ class ReorgsRestoreTest(BitcoinTestFramework):
# Node0 wallet file is loaded on longest sync'ed node1
self.stop_node(1)
- self.nodes[0].backupwallet(os.path.join(self.nodes[0].datadir, 'wallet.bak'))
- shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[1].chain_path, self.default_wallet_name, self.wallet_data_filename))
+ self.nodes[0].backupwallet(self.nodes[0].datadir_path / 'wallet.bak')
+ shutil.copyfile(self.nodes[0].datadir_path / 'wallet.bak', self.nodes[1].chain_path / self.default_wallet_name / self.wallet_data_filename)
self.start_node(1)
tx_after_reorg = self.nodes[1].gettransaction(txid)
# Check that normal confirmed tx is confirmed again but with different blockhash