diff options
author | fanquake <fanquake@gmail.com> | 2023-06-29 09:36:15 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-06-29 09:51:53 +0100 |
commit | e8543629ae4355fdba28eea974394d61a44d1071 (patch) | |
tree | 293beb7992799569c0404a7e34120999f42e8090 /test | |
parent | 626d3464695ed513e555371b870a5899872d723b (diff) | |
parent | aaaa3aefbdfca1c9243057eeefdc19940e60bf18 (diff) |
Merge bitcoin/bitcoin#27884: test: Use TestNode datadir_path or chain_path where possible
aaaa3aefbdfca1c9243057eeefdc19940e60bf18 test: Use TestNode *_path properties where possible (MarcoFalke)
dddd89962b26b5593860d016586ee8feb5aeea24 test: Allow pathlib.Path as RPC argument via authproxy (MarcoFalke)
fa41614a0abc05cbfbf76d6af3a186ab8d79c3f2 scripted-diff: Use wallets_path and chain_path where possible (MarcoFalke)
fa493fadfb0ac73b7c0ee308f6623213702ae6f4 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 aaaa3aefbdfca1c9243057eeefdc19940e60bf18
theStack:
Code-review ACK aaaa3aefbdfca1c9243057eeefdc19940e60bf18 🌊
Tree-SHA512: e4720278085beb8164e1fe6c1aa18f601558a9263494ce69a83764c1487007de63ebb51d1b1151862dc4d5b49ded6162a5c1553cd30ea1c28627d447db4d8e72
Diffstat (limited to 'test')
43 files changed, 149 insertions, 164 deletions
diff --git a/test/functional/feature_abortnode.py b/test/functional/feature_abortnode.py index 586722aa65..afee9597ad 100755 --- a/test/functional/feature_abortnode.py +++ b/test/functional/feature_abortnode.py @@ -9,10 +9,7 @@ - Mine a fork that requires disconnecting the tip. - Verify that bitcoind AbortNode's. """ - from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import get_datadir_path -import os class AbortNodeTest(BitcoinTestFramework): @@ -26,10 +23,9 @@ class AbortNodeTest(BitcoinTestFramework): def run_test(self): self.generate(self.nodes[0], 3, sync_fun=self.no_op) - datadir = get_datadir_path(self.options.tmpdir, 0) # Deleting the undo file will result in reorg failure - os.unlink(os.path.join(datadir, self.chain, 'blocks', 'rev00000.dat')) + (self.nodes[0].chain_path / "blocks" / "rev00000.dat").unlink() # Connecting to a node with a more work chain will trigger a reorg # attempt. diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py index 28c3880513..7877f9d302 100755 --- a/test/functional/feature_addrman.py +++ b/test/functional/feature_addrman.py @@ -53,7 +53,7 @@ class AddrmanTest(BitcoinTestFramework): self.num_nodes = 1 def run_test(self): - peers_dat = os.path.join(self.nodes[0].datadir, self.chain, "peers.dat") + peers_dat = os.path.join(self.nodes[0].chain_path, "peers.dat") init_error = lambda reason: ( f"Error: Invalid or corrupt peers.dat \\({reason}\\). If you believe this " f"is a bug, please report it to {self.config['environment']['PACKAGE_BUGREPORT']}. " diff --git a/test/functional/feature_anchors.py b/test/functional/feature_anchors.py index 468ad1eafa..0961f21a40 100755 --- a/test/functional/feature_anchors.py +++ b/test/functional/feature_anchors.py @@ -20,9 +20,7 @@ class AnchorsTest(BitcoinTestFramework): self.disable_autoconnect = False def run_test(self): - node_anchors_path = os.path.join( - self.nodes[0].datadir, "regtest", "anchors.dat" - ) + node_anchors_path = self.nodes[0].chain_path / "anchors.dat" self.log.info("When node starts, check if anchors.dat doesn't exist") assert not os.path.exists(node_anchors_path) diff --git a/test/functional/feature_asmap.py b/test/functional/feature_asmap.py index 9440ba11f5..9cff8042a8 100755 --- a/test/functional/feature_asmap.py +++ b/test/functional/feature_asmap.py @@ -113,7 +113,7 @@ class AsmapTest(BitcoinTestFramework): def run_test(self): self.node = self.nodes[0] - self.datadir = os.path.join(self.node.datadir, self.chain) + self.datadir = self.node.chain_path self.default_asmap = os.path.join(self.datadir, DEFAULT_ASMAP_FILENAME) self.asmap_raw = os.path.join(os.path.dirname(os.path.realpath(__file__)), ASMAP) diff --git a/test/functional/feature_blocksdir.py b/test/functional/feature_blocksdir.py index e8d2ec3676..99763ab97f 100755 --- a/test/functional/feature_blocksdir.py +++ b/test/functional/feature_blocksdir.py @@ -18,7 +18,7 @@ class BlocksdirTest(BitcoinTestFramework): def run_test(self): self.stop_node(0) - assert os.path.isdir(os.path.join(self.nodes[0].datadir, self.chain, "blocks")) + assert os.path.isdir(os.path.join(self.nodes[0].chain_path, "blocks")) assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "blocks")) shutil.rmtree(self.nodes[0].datadir) initialize_datadir(self.options.tmpdir, 0, self.chain) @@ -31,7 +31,7 @@ class BlocksdirTest(BitcoinTestFramework): 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].datadir, self.chain, "blocks", "index")) + assert os.path.isdir(os.path.join(self.nodes[0].chain_path, "blocks", "index")) if __name__ == '__main__': diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py index b898488924..2927355bda 100755 --- a/test/functional/feature_config_args.py +++ b/test/functional/feature_config_args.py @@ -32,7 +32,7 @@ class ConfArgsTest(BitcoinTestFramework): self.stop_node(0) # Check that startup fails if conf= is set in bitcoin.conf or in an included conf file - bad_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'bitcoin_bad.conf') + bad_conf_file_path = self.nodes[0].datadir_path / "bitcoin_bad.conf" util.write_config(bad_conf_file_path, n=0, chain='', extra_config=f'conf=some.conf\n') 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' self.nodes[0].assert_start_raises_init_error( @@ -75,7 +75,7 @@ class ConfArgsTest(BitcoinTestFramework): conf.write("wallet=foo\n") 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.') - main_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'bitcoin_main.conf') + main_conf_file_path = self.nodes[0].datadir_path / "bitcoin_main.conf" util.write_config(main_conf_file_path, n=0, chain='', extra_config=f'includeconf={inc_conf_file_path}\n') with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: conf.write('acceptnonstdtxn=1\n') diff --git a/test/functional/feature_fee_estimation.py b/test/functional/feature_fee_estimation.py index 03970415ac..4f56d585d3 100755 --- a/test/functional/feature_fee_estimation.py +++ b/test/functional/feature_fee_estimation.py @@ -421,7 +421,7 @@ class EstimateFeeTest(BitcoinTestFramework): self.log.info("Restarting node with fresh estimation") self.stop_node(0) - fee_dat = os.path.join(self.nodes[0].datadir, self.chain, "fee_estimates.dat") + fee_dat = os.path.join(self.nodes[0].chain_path, "fee_estimates.dat") os.remove(fee_dat) self.start_node(0) self.connect_nodes(0, 1) diff --git a/test/functional/feature_filelock.py b/test/functional/feature_filelock.py index bb4104bf8e..cf2f21d553 100755 --- a/test/functional/feature_filelock.py +++ b/test/functional/feature_filelock.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. """Check that it's not possible to start a second bitcoind instance using the same datadir or wallet.""" -import os import random import string @@ -24,7 +23,7 @@ class FilelockTest(BitcoinTestFramework): self.nodes[0].wait_for_rpc_connection() def run_test(self): - datadir = os.path.join(self.nodes[0].datadir, self.chain) + datadir = self.nodes[0].chain_path self.log.info(f"Using datadir {datadir}") self.log.info("Check that we can't start a second bitcoind instance using the same datadir") @@ -35,7 +34,7 @@ class FilelockTest(BitcoinTestFramework): def check_wallet_filelock(descriptors): wallet_name = ''.join([random.choice(string.ascii_lowercase) for _ in range(6)]) self.nodes[0].createwallet(wallet_name=wallet_name, descriptors=descriptors) - wallet_dir = os.path.join(datadir, 'wallets') + wallet_dir = self.nodes[0].wallets_path self.log.info("Check that we can't start a second bitcoind instance using the same wallet") if descriptors: 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']}?" diff --git a/test/functional/feature_includeconf.py b/test/functional/feature_includeconf.py index 818e4c923b..58ab063e71 100755 --- a/test/functional/feature_includeconf.py +++ b/test/functional/feature_includeconf.py @@ -14,27 +14,25 @@ Verify that: 4. multiple includeconf arguments can be specified in the main config file. """ -import os - from test_framework.test_framework import BitcoinTestFramework + class IncludeConfTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 - def setup_chain(self): - super().setup_chain() + def run_test(self): # Create additional config files # - tmpdir/node0/relative.conf - with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: + with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f: f.write("uacomment=relative\n") # - tmpdir/node0/relative2.conf - with open(os.path.join(self.options.tmpdir, "node0", "relative2.conf"), "w", encoding="utf8") as f: + with open(self.nodes[0].datadir_path / "relative2.conf", "w", encoding="utf8") as f: f.write("uacomment=relative2\n") - with open(os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), "a", encoding='utf8') as f: + with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f: f.write("uacomment=main\nincludeconf=relative.conf\n") + self.restart_node(0) - def run_test(self): self.log.info("-includeconf works from config file. subversion should end with 'main; relative)/'") subversion = self.nodes[0].getnetworkinfo()["subversion"] @@ -52,7 +50,7 @@ class IncludeConfTest(BitcoinTestFramework): ) self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'") - with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f: + with open(self.nodes[0].datadir_path / "relative.conf", "a", encoding="utf8") as f: f.write("includeconf=relative2.conf\n") self.start_node(0) @@ -63,20 +61,20 @@ class IncludeConfTest(BitcoinTestFramework): self.log.info("-includeconf cannot contain invalid arg") # Commented out as long as we ignore invalid arguments in configuration files - #with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: + #with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f: # f.write("foo=bar\n") #self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Invalid configuration value foo") self.log.info("-includeconf cannot be invalid path") - os.remove(os.path.join(self.options.tmpdir, "node0", "relative.conf")) + (self.nodes[0].datadir_path / "relative.conf").unlink() self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Failed to include configuration file relative.conf") self.log.info("multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'") - with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: + with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f: # Restore initial file contents f.write("uacomment=relative\n") - with open(os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), "a", encoding='utf8') as f: + with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f: f.write("includeconf=relative2.conf\n") self.start_node(0) diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py index 7f030c6773..c90ccc4936 100755 --- a/test/functional/feature_loadblock.py +++ b/test/functional/feature_loadblock.py @@ -37,7 +37,7 @@ class LoadblockTest(BitcoinTestFramework): cfg_file = os.path.join(data_dir, "linearize.cfg") bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat") genesis_block = self.nodes[0].getblockhash(0) - blocks_dir = os.path.join(data_dir, self.chain, "blocks") + blocks_dir = self.nodes[0].chain_path / "blocks" hash_list = tempfile.NamedTemporaryFile(dir=data_dir, mode='w', delete=False, diff --git a/test/functional/feature_logging.py b/test/functional/feature_logging.py index b0788e2a2d..0e9aca358d 100755 --- a/test/functional/feature_logging.py +++ b/test/functional/feature_logging.py @@ -16,7 +16,7 @@ class LoggingTest(BitcoinTestFramework): self.setup_clean_chain = True def relative_log_path(self, name): - return os.path.join(self.nodes[0].datadir, self.chain, name) + return os.path.join(self.nodes[0].chain_path, name) def run_test(self): # test default log file name diff --git a/test/functional/feature_posix_fs_permissions.py b/test/functional/feature_posix_fs_permissions.py index c5a543e97a..40528779e6 100755 --- a/test/functional/feature_posix_fs_permissions.py +++ b/test/functional/feature_posix_fs_permissions.py @@ -31,11 +31,11 @@ class PosixFsPermissionsTest(BitcoinTestFramework): def run_test(self): self.stop_node(0) - datadir = os.path.join(self.nodes[0].datadir, self.chain) + datadir = self.nodes[0].chain_path self.check_directory_permissions(datadir) - walletsdir = os.path.join(datadir, "wallets") + walletsdir = self.nodes[0].wallets_path self.check_directory_permissions(walletsdir) - debuglog = os.path.join(datadir, "debug.log") + debuglog = self.nodes[0].debug_log_path self.check_file_permissions(debuglog) diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py index b0c6138bcf..15dd4827ae 100755 --- a/test/functional/feature_pruning.py +++ b/test/functional/feature_pruning.py @@ -91,7 +91,7 @@ class PruneTest(BitcoinTestFramework): def setup_network(self): self.setup_nodes() - self.prunedir = os.path.join(self.nodes[2].datadir, self.chain, 'blocks', '') + self.prunedir = os.path.join(self.nodes[2].chain_path, 'blocks', '') self.connect_nodes(0, 1) self.connect_nodes(1, 2) @@ -290,7 +290,7 @@ class PruneTest(BitcoinTestFramework): assert_equal(ret + 1, node.getblockchaininfo()['pruneheight']) def has_block(index): - return os.path.isfile(os.path.join(self.nodes[node_number].datadir, self.chain, "blocks", f"blk{index:05}.dat")) + return os.path.isfile(os.path.join(self.nodes[node_number].chain_path, "blocks", f"blk{index:05}.dat")) # should not prune because chain tip of node 3 (995) < PruneAfterHeight (1000) assert_raises_rpc_error(-1, "Blockchain is too short for pruning", node.pruneblockchain, height(500)) diff --git a/test/functional/feature_reindex.py b/test/functional/feature_reindex.py index 0f6a8fd0d2..fcbb49d420 100755 --- a/test/functional/feature_reindex.py +++ b/test/functional/feature_reindex.py @@ -10,7 +10,6 @@ - Verify that out-of-order blocks are correctly processed, see LoadExternalBlockFile() """ -import os from test_framework.test_framework import BitcoinTestFramework from test_framework.p2p import MAGIC_BYTES from test_framework.util import assert_equal @@ -39,7 +38,7 @@ class ReindexTest(BitcoinTestFramework): # In this test environment, blocks will always be in order (since # we're generating them rather than getting them from peers), so to # test out-of-order handling, swap blocks 1 and 2 on disk. - blk0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00000.dat') + blk0 = self.nodes[0].chain_path / "blocks" / "blk00000.dat" with open(blk0, 'r+b') as bf: # Read at least the first few blocks (including genesis) b = bf.read(2000) diff --git a/test/functional/feature_remove_pruned_files_on_startup.py b/test/functional/feature_remove_pruned_files_on_startup.py index ca0e5ace9f..a55e08ef1a 100755 --- a/test/functional/feature_remove_pruned_files_on_startup.py +++ b/test/functional/feature_remove_pruned_files_on_startup.py @@ -20,10 +20,10 @@ class FeatureRemovePrunedFilesOnStartupTest(BitcoinTestFramework): self.sync_blocks() def run_test(self): - blk0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00000.dat') - rev0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00000.dat') - blk1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00001.dat') - rev1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00001.dat') + blk0 = self.nodes[0].chain_path / "blocks" / "blk00000.dat" + rev0 = self.nodes[0].chain_path / "blocks" / "rev00000.dat" + blk1 = self.nodes[0].chain_path / "blocks" / "blk00001.dat" + rev1 = self.nodes[0].chain_path / "blocks" / "rev00001.dat" self.mine_batches(800) fo1 = os.open(blk0, os.O_RDONLY) fo2 = os.open(rev1, os.O_RDONLY) diff --git a/test/functional/feature_settings.py b/test/functional/feature_settings.py index 20018f010f..bcae963428 100755 --- a/test/functional/feature_settings.py +++ b/test/functional/feature_settings.py @@ -21,7 +21,7 @@ class SettingsTest(BitcoinTestFramework): def run_test(self): node, = self.nodes - settings = Path(node.datadir, self.chain, "settings.json") + settings = Path(node.chain_path, "settings.json") conf = Path(node.datadir, "bitcoin.conf") # Assert empty settings file was created diff --git a/test/functional/feature_startupnotify.py b/test/functional/feature_startupnotify.py index 5c00984404..a8e62c6244 100755 --- a/test/functional/feature_startupnotify.py +++ b/test/functional/feature_startupnotify.py @@ -3,9 +3,6 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test -startupnotify.""" - -import os - from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -20,12 +17,12 @@ class StartupNotifyTest(BitcoinTestFramework): self.num_nodes = 1 def run_test(self): - tmpdir_file = os.path.join(self.options.tmpdir, NODE_DIR, FILE_NAME) - assert not os.path.exists(tmpdir_file) + tmpdir_file = self.nodes[0].datadir_path / FILE_NAME + assert not tmpdir_file.exists() self.log.info("Test -startupnotify command is run when node starts") self.restart_node(0, extra_args=[f"-startupnotify=echo '{FILE_NAME}' >> {NODE_DIR}/{FILE_NAME}"]) - self.wait_until(lambda: os.path.exists(tmpdir_file)) + self.wait_until(lambda: tmpdir_file.exists()) self.log.info("Test -startupnotify is executed once") diff --git a/test/functional/feature_txindex_compatibility.py b/test/functional/feature_txindex_compatibility.py index 48fefaa0ba..a5b25cbd71 100755 --- a/test/functional/feature_txindex_compatibility.py +++ b/test/functional/feature_txindex_compatibility.py @@ -50,10 +50,10 @@ class TxindexCompatibilityTest(BitcoinTestFramework): 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) + legacy_chain_dir = self.nodes[0].chain_path self.log.info("Migrate legacy txindex") - migrate_chain_dir = os.path.join(self.nodes[2].datadir, self.chain) + migrate_chain_dir = self.nodes[2].chain_path shutil.rmtree(migrate_chain_dir) shutil.copytree(legacy_chain_dir, migrate_chain_dir) with self.nodes[2].assert_debug_log([ @@ -64,7 +64,7 @@ class TxindexCompatibilityTest(BitcoinTestFramework): 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) + drop_index_chain_dir = self.nodes[1].chain_path shutil.rmtree(drop_index_chain_dir) shutil.copytree(legacy_chain_dir, drop_index_chain_dir) self.nodes[1].assert_start_raises_init_error( diff --git a/test/functional/interface_rpc.py b/test/functional/interface_rpc.py index 3725c89719..e873e2da0b 100755 --- a/test/functional/interface_rpc.py +++ b/test/functional/interface_rpc.py @@ -46,7 +46,7 @@ class RPCInterfaceTest(BitcoinTestFramework): command = info['active_commands'][0] assert_equal(command['method'], 'getrpcinfo') assert_greater_than_or_equal(command['duration'], 0) - assert_equal(info['logpath'], os.path.join(self.nodes[0].datadir, self.chain, 'debug.log')) + assert_equal(info['logpath'], os.path.join(self.nodes[0].chain_path, 'debug.log')) def test_batch_request(self): self.log.info("Testing basic JSON-RPC batch request...") diff --git a/test/functional/mempool_compatibility.py b/test/functional/mempool_compatibility.py index 7337802aea..3f632d3d56 100755 --- a/test/functional/mempool_compatibility.py +++ b/test/functional/mempool_compatibility.py @@ -55,8 +55,8 @@ class MempoolCompatibilityTest(BitcoinTestFramework): self.stop_node(1) self.log.info("Move mempool.dat from old to new node") - old_node_mempool = os.path.join(old_node.datadir, self.chain, 'mempool.dat') - new_node_mempool = os.path.join(new_node.datadir, self.chain, 'mempool.dat') + old_node_mempool = os.path.join(old_node.chain_path, 'mempool.dat') + new_node_mempool = os.path.join(new_node.chain_path, 'mempool.dat') os.rename(old_node_mempool, new_node_mempool) self.log.info("Start new node and verify mempool contains the tx") diff --git a/test/functional/mempool_persist.py b/test/functional/mempool_persist.py index 8f74d9de20..a1335ff069 100755 --- a/test/functional/mempool_persist.py +++ b/test/functional/mempool_persist.py @@ -143,8 +143,8 @@ class MempoolPersistTest(BitcoinTestFramework): self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet assert_equal(node2_balance, wallet_watch.getbalance()) - mempooldat0 = os.path.join(self.nodes[0].datadir, self.chain, 'mempool.dat') - mempooldat1 = os.path.join(self.nodes[1].datadir, self.chain, 'mempool.dat') + mempooldat0 = os.path.join(self.nodes[0].chain_path, 'mempool.dat') + mempooldat1 = os.path.join(self.nodes[1].chain_path, 'mempool.dat') self.log.debug("Force -persistmempool=0 node1 to savemempool to disk via RPC") assert not os.path.exists(mempooldat1) diff --git a/test/functional/p2p_message_capture.py b/test/functional/p2p_message_capture.py index 3ab0b79ba2..62ff4da8fd 100755 --- a/test/functional/p2p_message_capture.py +++ b/test/functional/p2p_message_capture.py @@ -58,7 +58,7 @@ class MessageCaptureTest(BitcoinTestFramework): self.setup_clean_chain = True def run_test(self): - capturedir = os.path.join(self.nodes[0].datadir, "regtest/message_capture") + capturedir = self.nodes[0].chain_path / "message_capture" # Connect a node so that the handshake occurs self.nodes[0].add_p2p_connection(P2PDataStore()) self.nodes[0].disconnect_p2ps() diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 6022042c11..5f2bece733 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -49,7 +49,6 @@ from test_framework.util import ( assert_raises_rpc_error, assert_is_hex_string, assert_is_hash_string, - get_datadir_path, ) from test_framework.wallet import MiniWallet @@ -572,16 +571,15 @@ class BlockchainTest(BitcoinTestFramework): self.log.info("Test that getblock with verbosity 3 includes prevout") assert_vin_contains_prevout(3) - self.log.info("Test that getblock with verbosity 2 and 3 still works with pruned Undo data") - datadir = get_datadir_path(self.options.tmpdir, 0) - self.log.info("Test getblock with invalid verbosity type returns proper error message") assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", node.getblock, blockhash, "2") + self.log.info("Test that getblock with verbosity 2 and 3 still works with pruned Undo data") + def move_block_file(old, new): - old_path = os.path.join(datadir, self.chain, 'blocks', old) - new_path = os.path.join(datadir, self.chain, 'blocks', new) - os.rename(old_path, new_path) + old_path = self.nodes[0].chain_path / "blocks" / old + new_path = self.nodes[0].chain_path / "blocks" / new + old_path.rename(new_path) # Move instead of deleting so we can restore chain state afterwards move_block_file('rev00000.dat', 'rev_wrong') diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py index 34e60d70f0..65d7b4c422 100755 --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -157,7 +157,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework): try: node1.loadwallet('wmulti') except JSONRPCException as e: - path = os.path.join(self.options.tmpdir, "node1", "regtest", "wallets", "wmulti") + path = self.nodes[1].wallets_path / "wmulti" if e.error['code'] == -18 and "Wallet file verification failed. Failed to load database path '{}'. Path does not exist.".format(path) in e.error['message']: node1.createwallet(wallet_name='wmulti', disable_private_keys=True) else: diff --git a/test/functional/rpc_dumptxoutset.py b/test/functional/rpc_dumptxoutset.py index 39a931be03..4260e95629 100755 --- a/test/functional/rpc_dumptxoutset.py +++ b/test/functional/rpc_dumptxoutset.py @@ -52,7 +52,7 @@ class DumptxoutsetTest(BitcoinTestFramework): # Specifying a path to an existing or invalid file will fail. assert_raises_rpc_error( -8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME) - invalid_path = str(Path(node.datadir) / "invalid" / "path") + invalid_path = node.datadir_path / "invalid" / "path" assert_raises_rpc_error( -8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path) diff --git a/test/functional/rpc_users.py b/test/functional/rpc_users.py index 8cc3ec401e..66cdd7cf9a 100755 --- a/test/functional/rpc_users.py +++ b/test/functional/rpc_users.py @@ -7,11 +7,9 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, - get_datadir_path, str_to_b64str, ) -import os import http.client import urllib.parse import subprocess @@ -38,8 +36,7 @@ class HTTPBasicsTest(BitcoinTestFramework): self.num_nodes = 2 self.supports_cli = False - def setup_chain(self): - super().setup_chain() + def conf_setup(self): #Append rpcauth to bitcoin.conf before initialization self.rtpassword = "cA773lm788buwYe4g4WT+05pKyNruVKjQ25x3n0DQcM=" rpcauth = "rpcauth=rt:93648e835a54c573682c2eb19f882535$7681e9c5b74bdd85e78166031d2058e1069b3ed7ed967c93fc63abba06f31144" @@ -64,13 +61,15 @@ class HTTPBasicsTest(BitcoinTestFramework): rpcauth3 = lines[1] self.password = lines[3] - with open(os.path.join(get_datadir_path(self.options.tmpdir, 0), "bitcoin.conf"), 'a', encoding='utf8') as f: + with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f: f.write(rpcauth + "\n") f.write(rpcauth2 + "\n") f.write(rpcauth3 + "\n") - with open(os.path.join(get_datadir_path(self.options.tmpdir, 1), "bitcoin.conf"), 'a', encoding='utf8') as f: + with open(self.nodes[1].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f: f.write("rpcuser={}\n".format(self.rpcuser)) f.write("rpcpassword={}\n".format(self.rpcpassword)) + self.restart_node(0) + self.restart_node(1) def test_auth(self, node, user, password): self.log.info('Correct...') @@ -86,6 +85,7 @@ class HTTPBasicsTest(BitcoinTestFramework): assert_equal(401, call_with_auth(node, user + 'wrong', password + 'wrong').status) def run_test(self): + self.conf_setup() self.log.info('Check correctness of the rpcauth config option') url = urllib.parse.urlparse(self.nodes[0].url) @@ -112,8 +112,7 @@ class HTTPBasicsTest(BitcoinTestFramework): self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo$bar$baz']) self.log.info('Check that failure to write cookie file will abort the node gracefully') - cookie_file = os.path.join(get_datadir_path(self.options.tmpdir, 0), self.chain, '.cookie.tmp') - os.mkdir(cookie_file) + (self.nodes[0].chain_path / ".cookie.tmp").mkdir() self.nodes[0].assert_start_raises_init_error(expected_msg=init_error) diff --git a/test/functional/rpc_whitelist.py b/test/functional/rpc_whitelist.py index 219132410b..fb404fb479 100755 --- a/test/functional/rpc_whitelist.py +++ b/test/functional/rpc_whitelist.py @@ -6,11 +6,9 @@ A test for RPC users with restricted permissions """ from test_framework.test_framework import BitcoinTestFramework -import os from test_framework.util import ( - get_datadir_path, assert_equal, - str_to_b64str + str_to_b64str, ) import http.client import urllib.parse @@ -30,8 +28,7 @@ class RPCWhitelistTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 - def setup_chain(self): - super().setup_chain() + def run_test(self): # 0 => Username # 1 => Password (Hashed) # 2 => Permissions @@ -55,7 +52,7 @@ class RPCWhitelistTest(BitcoinTestFramework): ] # These commands shouldn't be allowed for any user to test failures self.never_allowed = ["getnetworkinfo"] - with open(os.path.join(get_datadir_path(self.options.tmpdir, 0), "bitcoin.conf"), 'a', encoding='utf8') as f: + with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f: f.write("\nrpcwhitelistdefault=0\n") for user in self.users: f.write("rpcauth=" + user[0] + ":" + user[1] + "\n") @@ -64,9 +61,8 @@ class RPCWhitelistTest(BitcoinTestFramework): for strangedude in self.strange_users: f.write("rpcauth=" + strangedude[0] + ":" + strangedude[1] + "\n") f.write("rpcwhitelist=" + strangedude[0] + strangedude[2] + "\n") + self.restart_node(0) - - def run_test(self): for user in self.users: permissions = user[2].replace(" ", "").split(",") # Pop all empty items diff --git a/test/functional/test_framework/authproxy.py b/test/functional/test_framework/authproxy.py index f7765a9dfa..4bab36503c 100644 --- a/test/functional/test_framework/authproxy.py +++ b/test/functional/test_framework/authproxy.py @@ -39,6 +39,7 @@ from http import HTTPStatus import http.client import json import logging +import pathlib import socket import time import urllib.parse @@ -62,6 +63,8 @@ class JSONRPCException(Exception): def EncodeDecimal(o): if isinstance(o, decimal.Decimal): return str(o) + if isinstance(o, pathlib.Path): + return str(o) raise TypeError(repr(o) + " is not JSON serializable") class AuthServiceProxy(): diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 9583d6f7d7..a5995b9d37 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -22,7 +22,10 @@ import shlex import sys from pathlib import Path -from .authproxy import JSONRPCException +from .authproxy import ( + JSONRPCException, + EncodeDecimal, +) from .descriptors import descsum_create from .p2p import P2P_SUBVERSION from .util import ( @@ -35,7 +38,6 @@ from .util import ( rpc_url, wait_until_helper, p2p_port, - EncodeDecimal, ) BITCOIND_PROC_WAIT_TIMEOUT = 60 @@ -406,13 +408,21 @@ class TestNode(): conf.write(conf_data) @property + def datadir_path(self) -> Path: + return Path(self.datadir) + + @property def chain_path(self) -> Path: - return Path(self.datadir) / self.chain + return self.datadir_path / self.chain @property def debug_log_path(self) -> Path: return self.chain_path / 'debug.log' + @property + def wallets_path(self) -> Path: + return self.chain_path / "wallets" + def debug_log_bytes(self) -> int: with open(self.debug_log_path, encoding='utf-8') as dl: dl.seek(0, 2) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index d3b3e4d536..e480d63e03 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -211,12 +211,6 @@ def check_json_precision(): raise RuntimeError("JSON encode/decode loses precision") -def EncodeDecimal(o): - if isinstance(o, Decimal): - return str(o) - raise TypeError(repr(o) + " is not JSON serializable") - - def count_bytes(hex_string): return len(bytearray.fromhex(hex_string)) diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py index 95999649b4..327dd43e5a 100755 --- a/test/functional/tool_wallet.py +++ b/test/functional/tool_wallet.py @@ -173,12 +173,12 @@ class ToolWalletTest(BitcoinTestFramework): if file_format is not None and file_format != dump_data["format"]: load_output += "Warning: Dumpfile wallet format \"{}\" does not match command line specified format \"{}\".\n".format(dump_data["format"], file_format) self.assert_tool_output(load_output, *args) - assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", wallet_name)) + assert (self.nodes[0].wallets_path / wallet_name).is_dir() self.assert_tool_output("The dumpfile may contain private keys. To ensure the safety of your Bitcoin, do not share the dumpfile.\n", '-wallet={}'.format(wallet_name), '-dumpfile={}'.format(rt_dumppath), 'dump') rt_dump_data = self.read_dump(rt_dumppath) - wallet_dat = os.path.join(self.nodes[0].datadir, "regtest/wallets/", wallet_name, "wallet.dat") + wallet_dat = self.nodes[0].wallets_path / wallet_name / "wallet.dat" if rt_dump_data["format"] == "bdb": self.assert_is_bdb(wallet_dat) else: @@ -193,7 +193,7 @@ class ToolWalletTest(BitcoinTestFramework): self.assert_raises_tool_error('Error parsing command line arguments: Invalid parameter -foo', '-foo') self.assert_raises_tool_error('No method provided. Run `bitcoin-wallet -help` for valid methods.') self.assert_raises_tool_error('Wallet name must be provided when creating a new wallet.', 'create') - locked_dir = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets") + locked_dir = self.nodes[0].wallets_path error = 'Error initializing wallet database environment "{}"!'.format(locked_dir) if self.options.descriptors: error = f"SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of {self.config['environment']['PACKAGE_NAME']}?" @@ -202,7 +202,7 @@ class ToolWalletTest(BitcoinTestFramework): '-wallet=' + self.default_wallet_name, 'info', ) - path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "nonexistent.dat") + path = self.nodes[0].wallets_path / "nonexistent.dat" self.assert_raises_tool_error("Failed to load database path '{}'. Path does not exist.".format(path), '-wallet=nonexistent.dat', 'info') def test_tool_wallet_info(self): @@ -347,7 +347,7 @@ class ToolWalletTest(BitcoinTestFramework): non_exist_dump = os.path.join(self.nodes[0].datadir, "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 = os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', 'todump2') + wallet_path = self.nodes[0].wallets_path / "todump2" self.assert_raises_tool_error('Failed to create database path \'{}\'. Database already exists.'.format(wallet_path), '-wallet=todump2', '-dumpfile={}'.format(wallet_dump), 'createfromdump') self.assert_raises_tool_error("The -descriptors option can only be used with the 'create' command.", '-descriptors', '-wallet=todump2', '-dumpfile={}'.format(wallet_dump), 'createfromdump') @@ -363,18 +363,18 @@ class ToolWalletTest(BitcoinTestFramework): 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 os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + 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") 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 os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + 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") 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") self.assert_raises_tool_error('Error: Dumpfile identifier record is incorrect. Got "not_the_right_magic", expected "BITCOIN_CORE_WALLET_DUMP".', '-wallet=badload', '-dumpfile={}'.format(bad_magic_wallet_dump), 'createfromdump') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + 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") @@ -383,25 +383,25 @@ class ToolWalletTest(BitcoinTestFramework): 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 os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + 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") 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 os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + 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") 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') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + assert not (self.nodes[0].wallets_path / "badload").is_dir() dump_data["checksum"] = "3" * 66 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') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + assert not (self.nodes[0].wallets_path / "badload").is_dir() def run_test(self): - self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename) + self.wallet_path = os.path.join(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 4ad25d964e..fa92ebd436 100755 --- a/test/functional/wallet_backup.py +++ b/test/functional/wallet_backup.py @@ -109,16 +109,16 @@ class WalletBackupTest(BitcoinTestFramework): self.stop_node(2) def erase_three(self): - os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)) - os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)) - os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)) + 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)) def restore_invalid_wallet(self): node = self.nodes[3] invalid_wallet_file = os.path.join(self.nodes[0].datadir, '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.datadir, self.chain, 'wallets', wallet_name) + not_created_wallet_file = os.path.join(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) @@ -128,14 +128,14 @@ class WalletBackupTest(BitcoinTestFramework): nonexistent_wallet_file = os.path.join(self.nodes[0].datadir, '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.datadir, self.chain, 'wallets', wallet_name) + not_created_wallet_file = os.path.join(node.wallets_path, wallet_name) assert not os.path.exists(not_created_wallet_file) def restore_wallet_existent_name(self): node = self.nodes[3] backup_file = os.path.join(self.nodes[0].datadir, 'wallet.bak') wallet_name = "res0" - wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name) + wallet_file = os.path.join(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) @@ -206,9 +206,9 @@ class WalletBackupTest(BitcoinTestFramework): self.nodes[3].restorewallet("res1", backup_file_1) self.nodes[3].restorewallet("res2", backup_file_2) - assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res0")) - assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res1")) - assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res2")) + 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")) res0_rpc = self.nodes[3].get_wallet_rpc("res0") res1_rpc = self.nodes[3].get_wallet_rpc("res1") @@ -226,8 +226,8 @@ class WalletBackupTest(BitcoinTestFramework): self.erase_three() #start node2 with no chain - shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks')) - shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate')) + shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'blocks')) + shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'chainstate')) self.start_three(["-nowallet"]) self.init_three() @@ -248,10 +248,10 @@ class WalletBackupTest(BitcoinTestFramework): # Backup to source wallet file must fail sourcePaths = [ - os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename), - os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', self.default_wallet_name, self.wallet_data_filename), - os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name), - os.path.join(self.nodes[0].datadir, self.chain, 'wallets')] + os.path.join(self.nodes[0].wallets_path, self.default_wallet_name, self.wallet_data_filename), + os.path.join(self.nodes[0].wallets_path, '.', self.default_wallet_name, self.wallet_data_filename), + os.path.join(self.nodes[0].wallets_path, self.default_wallet_name), + os.path.join(self.nodes[0].wallets_path)] for sourcePath in sourcePaths: assert_raises_rpc_error(-4, "backup failed", self.nodes[0].backupwallet, sourcePath) diff --git a/test/functional/wallet_backwards_compatibility.py b/test/functional/wallet_backwards_compatibility.py index 5088e11eda..7d88e009c7 100755 --- a/test/functional/wallet_backwards_compatibility.py +++ b/test/functional/wallet_backwards_compatibility.py @@ -74,8 +74,8 @@ class BackwardsCompatibilityTest(BitcoinTestFramework): def nodes_wallet_dir(self, node): if node.version < 170000: - return os.path.join(node.datadir, "regtest") - return os.path.join(node.datadir, "regtest/wallets") + return node.chain_path + return node.wallets_path def run_test(self): node_miner = self.nodes[0] @@ -157,10 +157,10 @@ class BackwardsCompatibilityTest(BitcoinTestFramework): assert info['keypoolsize'] == 0 # Unload wallets and copy to older nodes: - node_master_wallets_dir = os.path.join(node_master.datadir, "regtest/wallets") - node_v19_wallets_dir = os.path.join(node_v19.datadir, "regtest/wallets") - node_v17_wallets_dir = os.path.join(node_v17.datadir, "regtest/wallets") - node_v16_wallets_dir = os.path.join(node_v16.datadir, "regtest") + node_master_wallets_dir = node_master.wallets_path + node_v19_wallets_dir = node_v19.wallets_path + node_v17_wallets_dir = node_v17.wallets_path + node_v16_wallets_dir = node_v16.chain_path node_master.unloadwallet("w1") node_master.unloadwallet("w2") node_master.unloadwallet("w3") diff --git a/test/functional/wallet_descriptor.py b/test/functional/wallet_descriptor.py index 4673eb091c..f4b67bae1b 100755 --- a/test/functional/wallet_descriptor.py +++ b/test/functional/wallet_descriptor.py @@ -234,7 +234,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].datadir, self.chain, "wallets", "crashme", self.wallet_data_filename) + wallet_db = os.path.join(self.nodes[0].wallets_path, "crashme", self.wallet_data_filename) with sqlite3.connect(wallet_db) as conn: # add "cscript" entry: key type is uint160 (20 bytes), value type is CScript (zero-length here) conn.execute('INSERT INTO main VALUES(?, ?)', (b'\x07cscript' + b'\x00'*20, b'\x00')) diff --git a/test/functional/wallet_hd.py b/test/functional/wallet_hd.py index 8f84d8ed60..0fb0d7ea97 100755 --- a/test/functional/wallet_hd.py +++ b/test/functional/wallet_hd.py @@ -87,11 +87,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].datadir, self.chain, "blocks")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "blocks")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "chainstate")) shutil.copyfile( os.path.join(self.nodes[1].datadir, "hd.bak"), - os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename), + os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename), ) self.start_node(1) @@ -115,11 +115,11 @@ class WalletHDTest(BitcoinTestFramework): # Try a RPC based rescan self.stop_node(1) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "blocks")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "chainstate")) shutil.copyfile( os.path.join(self.nodes[1].datadir, "hd.bak"), - os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename), + os.path.join(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_inactive_hdchains.py b/test/functional/wallet_inactive_hdchains.py index c0b3fea1c0..c6d22ab90b 100755 --- a/test/functional/wallet_inactive_hdchains.py +++ b/test/functional/wallet_inactive_hdchains.py @@ -5,7 +5,6 @@ """ Test Inactive HD Chains. """ -import os import shutil import time @@ -130,8 +129,8 @@ class InactiveHDChainsTest(BitcoinTestFramework): # Copy test wallet to node 0 test_wallet.unloadwallet() - test_wallet_dir = os.path.join(self.nodes[1].datadir, "regtest/wallets/keymeta_test") - new_test_wallet_dir = os.path.join(self.nodes[0].datadir, "regtest/wallets/keymeta_test") + test_wallet_dir = self.nodes[1].wallets_path / "keymeta_test" + new_test_wallet_dir = self.nodes[0].wallets_path / "keymeta_test" shutil.copytree(test_wallet_dir, new_test_wallet_dir) self.nodes[0].loadwallet("keymeta_test") test_wallet = self.nodes[0].get_wallet_rpc("keymeta_test") diff --git a/test/functional/wallet_keypool_topup.py b/test/functional/wallet_keypool_topup.py index f1458bb374..0f1c33a0c2 100755 --- a/test/functional/wallet_keypool_topup.py +++ b/test/functional/wallet_keypool_topup.py @@ -33,7 +33,7 @@ class KeypoolRestoreTest(BitcoinTestFramework): self.skip_if_no_wallet() def run_test(self): - wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename) + 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") self.generate(self.nodes[0], COINBASE_MATURITY + 1) diff --git a/test/functional/wallet_listtransactions.py b/test/functional/wallet_listtransactions.py index a44c129c87..18bb8a0cd8 100755 --- a/test/functional/wallet_listtransactions.py +++ b/test/functional/wallet_listtransactions.py @@ -234,8 +234,8 @@ class ListTransactionsTest(BitcoinTestFramework): # refill keypool otherwise the second node wouldn't recognize addresses generated on the first nodes self.nodes[0].keypoolrefill(1000) self.stop_nodes() - wallet0 = os.path.join(self.nodes[0].datadir, self.chain, self.default_wallet_name, "wallet.dat") - wallet2 = os.path.join(self.nodes[2].datadir, self.chain, self.default_wallet_name, "wallet.dat") + wallet0 = os.path.join(self.nodes[0].chain_path, self.default_wallet_name, "wallet.dat") + wallet2 = os.path.join(self.nodes[2].chain_path, self.default_wallet_name, "wallet.dat") shutil.copyfile(wallet0, wallet2) self.start_nodes() # reconnect nodes diff --git a/test/functional/wallet_migration.py b/test/functional/wallet_migration.py index 320f5dd9df..b64e5a8cd8 100755 --- a/test/functional/wallet_migration.py +++ b/test/functional/wallet_migration.py @@ -4,7 +4,6 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test Migrating a wallet from legacy to descriptor.""" -import os import random import shutil from test_framework.descriptors import descsum_create @@ -35,7 +34,7 @@ class WalletMigrationTest(BitcoinTestFramework): self.skip_if_no_bdb() def assert_is_sqlite(self, wallet_name): - wallet_file_path = os.path.join(self.nodes[0].datadir, "regtest/wallets", wallet_name, self.wallet_data_filename) + wallet_file_path = self.nodes[0].wallets_path / wallet_name / self.wallet_data_filename with open(wallet_file_path, 'rb') as f: file_magic = f.read(16) assert_equal(file_magic, b'SQLite format 3\x00') @@ -458,11 +457,11 @@ class WalletMigrationTest(BitcoinTestFramework): wallet.unloadwallet() - wallet_file_path = os.path.join(self.nodes[0].datadir, "regtest", "wallets", "notloaded2") + wallet_file_path = self.nodes[0].wallets_path / "notloaded2" self.nodes[0].migratewallet(wallet_file_path) # Because we gave the name by full path, the loaded wallet's name is that path too. - wallet = self.nodes[0].get_wallet_rpc(wallet_file_path) + wallet = self.nodes[0].get_wallet_rpc(str(wallet_file_path)) info = wallet.getwalletinfo() assert_equal(info["descriptors"], True) @@ -485,12 +484,12 @@ class WalletMigrationTest(BitcoinTestFramework): wallet = self.create_legacy_wallet("plainfile") wallet.unloadwallet() - wallets_dir = os.path.join(self.nodes[0].datadir, "regtest", "wallets") - wallet_path = os.path.join(wallets_dir, "plainfile") - wallet_dat_path = os.path.join(wallet_path, "wallet.dat") - shutil.copyfile(wallet_dat_path, os.path.join(wallets_dir, "plainfile.bak")) + wallets_dir = self.nodes[0].wallets_path + wallet_path = wallets_dir / "plainfile" + wallet_dat_path = wallet_path / "wallet.dat" + shutil.copyfile(wallet_dat_path, wallets_dir / "plainfile.bak") shutil.rmtree(wallet_path) - shutil.move(os.path.join(wallets_dir, "plainfile.bak"), wallet_path) + shutil.move(wallets_dir / "plainfile.bak", wallet_path) self.nodes[0].loadwallet("plainfile") info = wallet.getwalletinfo() @@ -502,8 +501,8 @@ class WalletMigrationTest(BitcoinTestFramework): assert_equal(info["descriptors"], True) assert_equal(info["format"], "sqlite") - assert os.path.isdir(wallet_path) - assert os.path.isfile(wallet_dat_path) + assert wallet_path.is_dir() + assert wallet_dat_path.is_file() def run_test(self): self.generate(self.nodes[0], 101) diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index 2faf6cad8b..10bc516d8f 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -62,7 +62,7 @@ class MultiWalletTest(BitcoinTestFramework): def run_test(self): node = self.nodes[0] - data_dir = lambda *p: os.path.join(node.datadir, self.chain, *p) + data_dir = lambda *p: os.path.join(node.chain_path, *p) wallet_dir = lambda *p: data_dir('wallets', *p) wallet = lambda name: node.get_wallet_rpc(name) @@ -299,7 +299,7 @@ class MultiWalletTest(BitcoinTestFramework): assert_equal(set(self.nodes[0].listwallets()), set(wallet_names)) # Fail to load if wallet doesn't exist - path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "wallets") + path = wallet_dir("wallets") assert_raises_rpc_error(-18, "Wallet file verification failed. Failed to load database path '{}'. Path does not exist.".format(path), self.nodes[0].loadwallet, 'wallets') # Fail to load duplicate wallets @@ -307,7 +307,7 @@ class MultiWalletTest(BitcoinTestFramework): if not self.options.descriptors: # This tests the default wallet that BDB makes, so SQLite wallet doesn't need to test this # Fail to load duplicate wallets by different ways (directory and filepath) - path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "wallet.dat") + path = wallet_dir("wallet.dat") assert_raises_rpc_error(-35, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, 'wallet.dat') # Only BDB doesn't open duplicate wallet files. SQLite does not have this limitation. While this may be desired in the future, it is not necessary @@ -322,13 +322,13 @@ class MultiWalletTest(BitcoinTestFramework): # Fail to load if a directory is specified that doesn't contain a wallet os.mkdir(wallet_dir('empty_wallet_dir')) - path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "empty_wallet_dir") + path = wallet_dir("empty_wallet_dir") assert_raises_rpc_error(-18, "Wallet file verification failed. Failed to load database path '{}'. Data is not in recognized format.".format(path), self.nodes[0].loadwallet, 'empty_wallet_dir') self.log.info("Test dynamic wallet creation.") # Fail to create a wallet if it already exists. - path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "w2") + path = wallet_dir("w2") assert_raises_rpc_error(-4, "Failed to create database path '{}'. Database already exists.".format(path), self.nodes[0].createwallet, 'w2') # Successfully create a wallet with a new name diff --git a/test/functional/wallet_pruning.py b/test/functional/wallet_pruning.py index 1ceceaee93..9e6061287c 100755 --- a/test/functional/wallet_pruning.py +++ b/test/functional/wallet_pruning.py @@ -106,7 +106,7 @@ 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].datadir, self.chain, "blocks", f"blk{block_index:05}.dat")) + return os.path.isfile(os.path.join(self.nodes[1].chain_path, "blocks", f"blk{block_index:05}.dat")) 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""" diff --git a/test/functional/wallet_reorgsrestore.py b/test/functional/wallet_reorgsrestore.py index 1c79c6816c..af01b9439f 100755 --- a/test/functional/wallet_reorgsrestore.py +++ b/test/functional/wallet_reorgsrestore.py @@ -89,7 +89,7 @@ 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].datadir, self.chain, self.default_wallet_name, self.wallet_data_filename)) + 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.start_node(1) tx_after_reorg = self.nodes[1].gettransaction(txid) # Check that normal confirmed tx is confirmed again but with different blockhash diff --git a/test/functional/wallet_upgradewallet.py b/test/functional/wallet_upgradewallet.py index 4495a7d778..a4f2a9b74d 100755 --- a/test/functional/wallet_upgradewallet.py +++ b/test/functional/wallet_upgradewallet.py @@ -138,11 +138,11 @@ class UpgradeWalletTest(BitcoinTestFramework): self.log.info("Test upgradewallet RPC...") # Prepare for copying of the older wallet - node_master_wallet_dir = os.path.join(node_master.datadir, "regtest/wallets", self.default_wallet_name) - node_master_wallet = os.path.join(node_master_wallet_dir, self.default_wallet_name, self.wallet_data_filename) - v16_3_wallet = os.path.join(v16_3_node.datadir, "regtest/wallets/wallet.dat") - v15_2_wallet = os.path.join(v15_2_node.datadir, "regtest/wallet.dat") - split_hd_wallet = os.path.join(v15_2_node.datadir, "regtest/splithd") + node_master_wallet_dir = node_master.wallets_path / self.default_wallet_name + node_master_wallet = node_master_wallet_dir / self.default_wallet_name / self.wallet_data_filename + v16_3_wallet = v16_3_node.wallets_path / "wallet.dat" + v15_2_wallet = v15_2_node.chain_path / "wallet.dat" + split_hd_wallet = v15_2_node.chain_path / "splithd" self.stop_nodes() # Make split hd wallet |