Skip to content

Commit

Permalink
scripted-diff: Use wallets_path and chain_path where possible
Browse files Browse the repository at this point in the history
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-
  • Loading branch information
MarcoFalke authored and janus committed Sep 6, 2023
1 parent 332a0d2 commit f528150
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion test/functional/feature_addrman.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def set_test_params(self):
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']}. "
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_blocksdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def set_test_params(self):

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)
Expand All @@ -31,7 +31,7 @@ def run_test(self):
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__':
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_fee_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def run_test(self):

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)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def set_test_params(self):
self.setup_clean_chain = True

def relative_log_path(self, name):
return os.path.join(self.nodes[0].datadir, "regtest", name)
return os.path.join(self.nodes[0].chain_path, name)

def run_test(self):
# test default log file name
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def set_test_params(self):
def setup_network(self):
self.setup_nodes()

self.prunedir = os.path.join(self.nodes[2].datadir, 'regtest', 'blocks', '')
self.prunedir = os.path.join(self.nodes[2].chain_path, 'blocks', '')

self.connect_nodes(0, 1)
self.connect_nodes(1, 2)
Expand Down Expand Up @@ -286,7 +286,7 @@ def prune(index):
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))
Expand Down
3 changes: 2 additions & 1 deletion test/functional/feature_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def set_test_params(self):

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, "BGL.conf")


# Assert empty settings file was created
self.stop_node(0)
with settings.open() as fp:
Expand Down
2 changes: 1 addition & 1 deletion test/functional/interface_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_getrpcinfo(self):
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, 'regtest', '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...")
Expand Down
4 changes: 2 additions & 2 deletions test/functional/mempool_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def run_test(self):
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")
Expand Down
4 changes: 2 additions & 2 deletions test/functional/mempool_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def run_test(self):
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)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/tool_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def test_dump_createfromdump(self):


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()
Expand Down
30 changes: 15 additions & 15 deletions test/functional/wallet_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ def stop_three(self):
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)
Expand All @@ -128,14 +128,14 @@ def restore_nonexistent_wallet(self):
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)

Expand Down Expand Up @@ -205,9 +205,9 @@ def run_test(self):
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")
Expand All @@ -226,8 +226,8 @@ def run_test(self):


#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()
Expand All @@ -248,10 +248,10 @@ def run_test(self):

# 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)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def run_test(self):
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'))
Expand Down
12 changes: 6 additions & 6 deletions test/functional/wallet_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def run_test(self):
self.stop_node(1)
# we need to delete the complete regtest 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)

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

# 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)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_keypool_topup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def skip_test_if_missing_module(self):
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)

Expand Down
4 changes: 2 additions & 2 deletions test/functional/wallet_listtransactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ def run_externally_generated_address_test(self):
# 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
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_multiwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def add_options(self, parser):
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)

Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_birthheight(self, wallet_file):

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"""
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_reorgsrestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def run_test(self):
# 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
Expand Down

0 comments on commit f528150

Please sign in to comment.