Skip to content

Commit fa41614

Browse files
author
MarcoFalke
committed
scripted-diff: Use wallets_path and chain_path where possible
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-
1 parent fa493fa commit fa41614

18 files changed

+42
-42
lines changed

test/functional/feature_addrman.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def set_test_params(self):
5353
self.num_nodes = 1
5454

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

test/functional/feature_blocksdir.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def set_test_params(self):
1818

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

3636

3737
if __name__ == '__main__':

test/functional/feature_fee_estimation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def run_test(self):
421421

422422
self.log.info("Restarting node with fresh estimation")
423423
self.stop_node(0)
424-
fee_dat = os.path.join(self.nodes[0].datadir, self.chain, "fee_estimates.dat")
424+
fee_dat = os.path.join(self.nodes[0].chain_path, "fee_estimates.dat")
425425
os.remove(fee_dat)
426426
self.start_node(0)
427427
self.connect_nodes(0, 1)

test/functional/feature_logging.py

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

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

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

test/functional/feature_pruning.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def set_test_params(self):
9191
def setup_network(self):
9292
self.setup_nodes()
9393

94-
self.prunedir = os.path.join(self.nodes[2].datadir, self.chain, 'blocks', '')
94+
self.prunedir = os.path.join(self.nodes[2].chain_path, 'blocks', '')
9595

9696
self.connect_nodes(0, 1)
9797
self.connect_nodes(1, 2)
@@ -290,7 +290,7 @@ def prune(index):
290290
assert_equal(ret + 1, node.getblockchaininfo()['pruneheight'])
291291

292292
def has_block(index):
293-
return os.path.isfile(os.path.join(self.nodes[node_number].datadir, self.chain, "blocks", f"blk{index:05}.dat"))
293+
return os.path.isfile(os.path.join(self.nodes[node_number].chain_path, "blocks", f"blk{index:05}.dat"))
294294

295295
# should not prune because chain tip of node 3 (995) < PruneAfterHeight (1000)
296296
assert_raises_rpc_error(-1, "Blockchain is too short for pruning", node.pruneblockchain, height(500))

test/functional/feature_settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def set_test_params(self):
2121

2222
def run_test(self):
2323
node, = self.nodes
24-
settings = Path(node.datadir, self.chain, "settings.json")
24+
settings = Path(node.chain_path, "settings.json")
2525
conf = Path(node.datadir, "bitcoin.conf")
2626

2727
# Assert empty settings file was created

test/functional/interface_rpc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_getrpcinfo(self):
4646
command = info['active_commands'][0]
4747
assert_equal(command['method'], 'getrpcinfo')
4848
assert_greater_than_or_equal(command['duration'], 0)
49-
assert_equal(info['logpath'], os.path.join(self.nodes[0].datadir, self.chain, 'debug.log'))
49+
assert_equal(info['logpath'], os.path.join(self.nodes[0].chain_path, 'debug.log'))
5050

5151
def test_batch_request(self):
5252
self.log.info("Testing basic JSON-RPC batch request...")

test/functional/mempool_compatibility.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def run_test(self):
5555
self.stop_node(1)
5656

5757
self.log.info("Move mempool.dat from old to new node")
58-
old_node_mempool = os.path.join(old_node.datadir, self.chain, 'mempool.dat')
59-
new_node_mempool = os.path.join(new_node.datadir, self.chain, 'mempool.dat')
58+
old_node_mempool = os.path.join(old_node.chain_path, 'mempool.dat')
59+
new_node_mempool = os.path.join(new_node.chain_path, 'mempool.dat')
6060
os.rename(old_node_mempool, new_node_mempool)
6161

6262
self.log.info("Start new node and verify mempool contains the tx")

test/functional/mempool_persist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ def run_test(self):
143143
self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet
144144
assert_equal(node2_balance, wallet_watch.getbalance())
145145

146-
mempooldat0 = os.path.join(self.nodes[0].datadir, self.chain, 'mempool.dat')
147-
mempooldat1 = os.path.join(self.nodes[1].datadir, self.chain, 'mempool.dat')
146+
mempooldat0 = os.path.join(self.nodes[0].chain_path, 'mempool.dat')
147+
mempooldat1 = os.path.join(self.nodes[1].chain_path, 'mempool.dat')
148148

149149
self.log.debug("Force -persistmempool=0 node1 to savemempool to disk via RPC")
150150
assert not os.path.exists(mempooldat1)

test/functional/tool_wallet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def test_dump_createfromdump(self):
401401

402402

403403
def run_test(self):
404-
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)
404+
self.wallet_path = os.path.join(self.nodes[0].wallets_path, self.default_wallet_name, self.wallet_data_filename)
405405
self.test_invalid_tool_commands_and_args()
406406
# Warning: The following tests are order-dependent.
407407
self.test_tool_wallet_info()

test/functional/wallet_backup.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ def stop_three(self):
109109
self.stop_node(2)
110110

111111
def erase_three(self):
112-
os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
113-
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
114-
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
112+
os.remove(os.path.join(self.nodes[0].wallets_path, self.default_wallet_name, self.wallet_data_filename))
113+
os.remove(os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename))
114+
os.remove(os.path.join(self.nodes[2].wallets_path, self.default_wallet_name, self.wallet_data_filename))
115115

116116
def restore_invalid_wallet(self):
117117
node = self.nodes[3]
118118
invalid_wallet_file = os.path.join(self.nodes[0].datadir, 'invalid_wallet_file.bak')
119119
open(invalid_wallet_file, 'a', encoding="utf8").write('invald wallet')
120120
wallet_name = "res0"
121-
not_created_wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name)
121+
not_created_wallet_file = os.path.join(node.wallets_path, wallet_name)
122122
error_message = "Wallet file verification failed. Failed to load database path '{}'. Data is not in recognized format.".format(not_created_wallet_file)
123123
assert_raises_rpc_error(-18, error_message, node.restorewallet, wallet_name, invalid_wallet_file)
124124
assert not os.path.exists(not_created_wallet_file)
@@ -128,14 +128,14 @@ def restore_nonexistent_wallet(self):
128128
nonexistent_wallet_file = os.path.join(self.nodes[0].datadir, 'nonexistent_wallet.bak')
129129
wallet_name = "res0"
130130
assert_raises_rpc_error(-8, "Backup file does not exist", node.restorewallet, wallet_name, nonexistent_wallet_file)
131-
not_created_wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name)
131+
not_created_wallet_file = os.path.join(node.wallets_path, wallet_name)
132132
assert not os.path.exists(not_created_wallet_file)
133133

134134
def restore_wallet_existent_name(self):
135135
node = self.nodes[3]
136136
backup_file = os.path.join(self.nodes[0].datadir, 'wallet.bak')
137137
wallet_name = "res0"
138-
wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name)
138+
wallet_file = os.path.join(node.wallets_path, wallet_name)
139139
error_message = "Failed to create database path '{}'. Database already exists.".format(wallet_file)
140140
assert_raises_rpc_error(-36, error_message, node.restorewallet, wallet_name, backup_file)
141141
assert os.path.exists(wallet_file)
@@ -206,9 +206,9 @@ def run_test(self):
206206
self.nodes[3].restorewallet("res1", backup_file_1)
207207
self.nodes[3].restorewallet("res2", backup_file_2)
208208

209-
assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res0"))
210-
assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res1"))
211-
assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res2"))
209+
assert os.path.exists(os.path.join(self.nodes[3].wallets_path, "res0"))
210+
assert os.path.exists(os.path.join(self.nodes[3].wallets_path, "res1"))
211+
assert os.path.exists(os.path.join(self.nodes[3].wallets_path, "res2"))
212212

213213
res0_rpc = self.nodes[3].get_wallet_rpc("res0")
214214
res1_rpc = self.nodes[3].get_wallet_rpc("res1")
@@ -226,8 +226,8 @@ def run_test(self):
226226
self.erase_three()
227227

228228
#start node2 with no chain
229-
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks'))
230-
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
229+
shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'blocks'))
230+
shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'chainstate'))
231231

232232
self.start_three(["-nowallet"])
233233
self.init_three()
@@ -248,10 +248,10 @@ def run_test(self):
248248

249249
# Backup to source wallet file must fail
250250
sourcePaths = [
251-
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename),
252-
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', '.', self.default_wallet_name, self.wallet_data_filename),
253-
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name),
254-
os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]
251+
os.path.join(self.nodes[0].wallets_path, self.default_wallet_name, self.wallet_data_filename),
252+
os.path.join(self.nodes[0].wallets_path, '.', self.default_wallet_name, self.wallet_data_filename),
253+
os.path.join(self.nodes[0].wallets_path, self.default_wallet_name),
254+
os.path.join(self.nodes[0].wallets_path)]
255255

256256
for sourcePath in sourcePaths:
257257
assert_raises_rpc_error(-4, "backup failed", self.nodes[0].backupwallet, sourcePath)

test/functional/wallet_descriptor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def run_test(self):
234234
self.log.info("Test that loading descriptor wallet containing legacy key types throws error")
235235
self.nodes[0].createwallet(wallet_name="crashme", descriptors=True)
236236
self.nodes[0].unloadwallet("crashme")
237-
wallet_db = os.path.join(self.nodes[0].datadir, self.chain, "wallets", "crashme", self.wallet_data_filename)
237+
wallet_db = os.path.join(self.nodes[0].wallets_path, "crashme", self.wallet_data_filename)
238238
with sqlite3.connect(wallet_db) as conn:
239239
# add "cscript" entry: key type is uint160 (20 bytes), value type is CScript (zero-length here)
240240
conn.execute('INSERT INTO main VALUES(?, ?)', (b'\x07cscript' + b'\x00'*20, b'\x00'))

test/functional/wallet_hd.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ def run_test(self):
8787
self.stop_node(1)
8888
# we need to delete the complete chain directory
8989
# otherwise node1 would auto-recover all funds in flag the keypool keys as used
90-
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
91-
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
90+
shutil.rmtree(os.path.join(self.nodes[1].chain_path, "blocks"))
91+
shutil.rmtree(os.path.join(self.nodes[1].chain_path, "chainstate"))
9292
shutil.copyfile(
9393
os.path.join(self.nodes[1].datadir, "hd.bak"),
94-
os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename),
94+
os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename),
9595
)
9696
self.start_node(1)
9797

@@ -115,11 +115,11 @@ def run_test(self):
115115

116116
# Try a RPC based rescan
117117
self.stop_node(1)
118-
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks"))
119-
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
118+
shutil.rmtree(os.path.join(self.nodes[1].chain_path, "blocks"))
119+
shutil.rmtree(os.path.join(self.nodes[1].chain_path, "chainstate"))
120120
shutil.copyfile(
121121
os.path.join(self.nodes[1].datadir, "hd.bak"),
122-
os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename),
122+
os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename),
123123
)
124124
self.start_node(1, extra_args=self.extra_args[1])
125125
self.connect_nodes(0, 1)

test/functional/wallet_keypool_topup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def skip_test_if_missing_module(self):
3333
self.skip_if_no_wallet()
3434

3535
def run_test(self):
36-
wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename)
36+
wallet_path = os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename)
3737
wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak")
3838
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
3939

test/functional/wallet_listtransactions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ def run_externally_generated_address_test(self):
234234
# refill keypool otherwise the second node wouldn't recognize addresses generated on the first nodes
235235
self.nodes[0].keypoolrefill(1000)
236236
self.stop_nodes()
237-
wallet0 = os.path.join(self.nodes[0].datadir, self.chain, self.default_wallet_name, "wallet.dat")
238-
wallet2 = os.path.join(self.nodes[2].datadir, self.chain, self.default_wallet_name, "wallet.dat")
237+
wallet0 = os.path.join(self.nodes[0].chain_path, self.default_wallet_name, "wallet.dat")
238+
wallet2 = os.path.join(self.nodes[2].chain_path, self.default_wallet_name, "wallet.dat")
239239
shutil.copyfile(wallet0, wallet2)
240240
self.start_nodes()
241241
# reconnect nodes

test/functional/wallet_multiwallet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def add_options(self, parser):
6262
def run_test(self):
6363
node = self.nodes[0]
6464

65-
data_dir = lambda *p: os.path.join(node.datadir, self.chain, *p)
65+
data_dir = lambda *p: os.path.join(node.chain_path, *p)
6666
wallet_dir = lambda *p: data_dir('wallets', *p)
6767
wallet = lambda name: node.get_wallet_rpc(name)
6868

test/functional/wallet_pruning.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def get_birthheight(self, wallet_file):
106106

107107
def has_block(self, block_index):
108108
"""Checks if the pruned node has the specific blk0000*.dat file"""
109-
return os.path.isfile(os.path.join(self.nodes[1].datadir, self.chain, "blocks", f"blk{block_index:05}.dat"))
109+
return os.path.isfile(os.path.join(self.nodes[1].chain_path, "blocks", f"blk{block_index:05}.dat"))
110110

111111
def create_wallet(self, wallet_name, *, unload=False):
112112
"""Creates and dumps a wallet on the non-pruned node0 to be later import by the pruned node"""

test/functional/wallet_reorgsrestore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def run_test(self):
8989
# Node0 wallet file is loaded on longest sync'ed node1
9090
self.stop_node(1)
9191
self.nodes[0].backupwallet(os.path.join(self.nodes[0].datadir, 'wallet.bak'))
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))
92+
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))
9393
self.start_node(1)
9494
tx_after_reorg = self.nodes[1].gettransaction(txid)
9595
# Check that normal confirmed tx is confirmed again but with different blockhash

0 commit comments

Comments
 (0)