Repository navigation
test: Use TestNode datadir_path or chain_path where possible - #27884
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
theStack
left a comment
There was a problem hiding this comment.
Concept ACK
Here's a few more instances which I think could be simplified by using chain_path (found via $ git grep join.*regtest ./test):
bitcoin/test/functional/wallet_backwards_compatibility.py
Lines 75 to 78 in 1ecdf6e
bitcoin/test/functional/wallet_backwards_compatibility.py
Lines 160 to 163 in 1ecdf6e
bitcoin/test/functional/wallet_inactive_hdchains.py
Lines 133 to 134 in 1ecdf6e
bitcoin/test/functional/wallet_migration.py
Line 460 in 1ecdf6e
bitcoin/test/functional/wallet_upgradewallet.py
Lines 141 to 145 in 1ecdf6e
|
Concept ACK. In addition to those highlighted by TheStack, there are also quite a few other places we could update to use this, e.g. some of these matches: $ git grep -n "os.path" test/functional | rg -e '.*\.chain*'
test/functional/feature_addrman.py:56: peers_dat = os.path.join(self.nodes[0].datadir, self.chain, "peers.dat")
test/functional/feature_asmap.py:116: self.datadir = os.path.join(self.node.datadir, self.chain)
test/functional/feature_blocksdir.py:33: assert os.path.isfile(os.path.join(blocksdir_path, self.chain, "blocks", "blk00000.dat"))
test/functional/feature_blocksdir.py:34: assert os.path.isdir(os.path.join(self.nodes[0].datadir, self.chain, "blocks", "index"))
test/functional/feature_config_args.py:418: assert os.path.exists(os.path.join(new_data_dir, self.chain, 'blocks'))
test/functional/feature_config_args.py:424: assert os.path.exists(os.path.join(new_data_dir_2, self.chain, 'blocks'))
test/functional/feature_fee_estimation.py:323: fee_dat = os.path.join(self.nodes[0].datadir, self.chain, "fee_estimates.dat")
test/functional/feature_filelock.py:27: datadir = os.path.join(self.nodes[0].datadir, self.chain)
test/functional/feature_loadblock.py:40: blocks_dir = os.path.join(data_dir, self.chain, "blocks")
test/functional/feature_logging.py:19: return os.path.join(self.nodes[0].datadir, self.chain, name)
test/functional/feature_posix_fs_permissions.py:34: datadir = os.path.join(self.nodes[0].datadir, self.chain)
test/functional/feature_pruning.py:94: self.prunedir = os.path.join(self.nodes[2].datadir, self.chain, 'blocks', '')
test/functional/feature_pruning.py:293: return os.path.isfile(os.path.join(self.nodes[node_number].datadir, self.chain, "blocks", f"blk{index:05}.dat"))
test/functional/feature_reindex.py:42: blk0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00000.dat')
test/functional/feature_remove_pruned_files_on_startup.py:23: blk0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00000.dat')
test/functional/feature_remove_pruned_files_on_startup.py:24: rev0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00000.dat')
test/functional/feature_remove_pruned_files_on_startup.py:25: blk1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00001.dat')
test/functional/feature_remove_pruned_files_on_startup.py:26: rev1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00001.dat')
test/functional/feature_txindex_compatibility.py:53: legacy_chain_dir = os.path.join(self.nodes[0].datadir, self.chain)
test/functional/feature_txindex_compatibility.py:56: migrate_chain_dir = os.path.join(self.nodes[2].datadir, self.chain)
test/functional/feature_txindex_compatibility.py:67: drop_index_chain_dir = os.path.join(self.nodes[1].datadir, self.chain)
test/functional/interface_rpc.py:49: assert_equal(info['logpath'], os.path.join(self.nodes[0].datadir, self.chain, 'debug.log'))
test/functional/mempool_compatibility.py:58: old_node_mempool = os.path.join(old_node.datadir, self.chain, 'mempool.dat')
test/functional/mempool_compatibility.py:59: new_node_mempool = os.path.join(new_node.datadir, self.chain, 'mempool.dat')
test/functional/mempool_persist.py:146: mempooldat0 = os.path.join(self.nodes[0].datadir, self.chain, 'mempool.dat')
test/functional/mempool_persist.py:147: mempooldat1 = os.path.join(self.nodes[1].datadir, self.chain, 'mempool.dat')
test/functional/test_framework/test_framework.py:826: return os.path.join(cache_node_dir, self.chain, *paths)
test/functional/tool_wallet.py:404: self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)
test/functional/wallet_backup.py:112: os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
test/functional/wallet_backup.py:113: os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
test/functional/wallet_backup.py:114: os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
test/functional/wallet_backup.py:121: not_created_wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name)
test/functional/wallet_backup.py:131: not_created_wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name)
test/functional/wallet_backup.py:138: wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name)
test/functional/wallet_backup.py:209: assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res0"))
test/functional/wallet_backup.py:210: assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res1"))
test/functional/wallet_backup.py:211: assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res2"))
test/functional/wallet_backup.py:229: shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
test/functional/wallet_backup.py:230: shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
test/functional/wallet_backup.py:251: os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename),
test/functional/wallet_backup.py:252: os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', self.default_wallet_name, self.wallet_data_filename),
test/functional/wallet_backup.py:253: os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name),
test/functional/wallet_backup.py:254: os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]
test/functional/wallet_descriptor.py:237: wallet_db = os.path.join(self.nodes[0].datadir, self.chain, "wallets", "crashme", self.wallet_data_filename)
test/functional/wallet_hd.py:90: shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
test/functional/wallet_hd.py:91: shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
test/functional/wallet_hd.py:94: os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename),
test/functional/wallet_hd.py:118: shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
test/functional/wallet_hd.py:119: shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
test/functional/wallet_hd.py:122: os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename),
test/functional/wallet_keypool_topup.py:36: wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename)
test/functional/wallet_listtransactions.py:237: wallet0 = os.path.join(self.nodes[0].datadir, self.chain, self.default_wallet_name, "wallet.dat")
test/functional/wallet_listtransactions.py:238: wallet2 = os.path.join(self.nodes[2].datadir, self.chain, self.default_wallet_name, "wallet.dat")
test/functional/wallet_multiwallet.py:65: data_dir = lambda *p: os.path.join(node.datadir, self.chain, *p)
test/functional/wallet_pruning.py:109: return os.path.isfile(os.path.join(self.nodes[1].datadir, self.chain, "blocks", f"blk{block_index:05}.dat"))
test/functional/wallet_reorgsrestore.py:92: 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))...although, changing some of these occurences does require additional changes for example when watching logs. Are we looking to change all of these out and switch to the os.Path operator syntax throughout? |
fad335e to
fad1583
Compare
Thanks, added a scripted-diff as second commit
Thanks, modified the last commit |
|
Light crACK fa7f1251f8 Looks good to me. There are still instances in tests (outside of test_framework/) where we are using |
Thanks, fixed the remaining join calls that used |
theStack
left a comment
There was a problem hiding this comment.
LGTM, found only one more instance where chain_path could be used:
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)
As a follow-up, a new TestNode property wallets_path might also make sense, to deduplicate even more?
|
Same, looks good here. Will ack if you want to make the anchors change. Question: Now that we use more |
Thanks, added and updated the scripted-diff to avoid touching the same lines twice. |
Seems odd to hardcode all parent directory names in the path for no good reason. Also, add wallet_path property to TestNode. Also, rework wallet_backup.py test for scripted-diff in the next commit.
Instead of passing the datadir and chain name to os.path.join, just use the existing properties, which are the same. -BEGIN VERIFY SCRIPT- sed -i --regexp-extended 's|\.datadir, self\.chain, .wallets.|.wallets_path|g' $(git grep -l '\.datadir, self\.chain,') sed -i --regexp-extended 's|\.datadir, self\.chain,|.chain_path,|g' $(git grep -l '\.datadir, self\.chain,') -END VERIFY SCRIPT-
Also, add datadir_path property to TestNode
Seems odd to place the burden on test writers to hardcode the chain or datadir path for the nodes under test.
| if isinstance(o, pathlib.Path): | ||
| return str(o) |
There was a problem hiding this comment.
nit (feel free to ignore for now, probably follow-up material): Now that this function is not handling decimals only anymore, I think it should be renamed from EncodeDecimal to something generic?
There was a problem hiding this comment.
Yeah, it should have been called serialization_fallback? May do on the next push or leave for a follow-up.
|
Is this rfm or does it need more review? |
|
re-ACK aaaa3ae LGTM with the wallets_path added. |
It seems inconsistent, fragile and verbose to:
get_datadir_pathto recreate the path that already exists as field in TestNodeos.path.joinwith the hardcoded chain name orself.chainto recreate the TestNodechain_pathproperty"node0")Fix all issues by using the TestNode properties.