Skip to content

Commit 41faef5

Browse files
committed
test: Migration fail recovery w/ ../ in path
1 parent 63c6d36 commit 41faef5

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/functional/wallet_migration.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,53 @@ def test_failed_migration_cleanup(self):
994994
_, _, magic = struct.unpack("QII", data)
995995
assert_equal(magic, BTREE_MAGIC)
996996

997+
def test_failed_migration_cleanup_relative_path(self):
998+
self.log.info("Test that a failed migration with a relative path is cleaned up")
999+
1000+
# Get the nearest common path of both nodes' wallet paths.
1001+
common_parent = os.path.commonpath([self.master_node.wallets_path, self.old_node.wallets_path])
1002+
1003+
# This test assumes that the relative path from each wallet directory to the common path is identical.
1004+
assert_equal(os.path.relpath(common_parent, start=self.master_node.wallets_path), os.path.relpath(common_parent, start=self.old_node.wallets_path))
1005+
1006+
wallet_name = "relativefailure"
1007+
absolute_path = os.path.abspath(os.path.join(common_parent, wallet_name))
1008+
relative_name = os.path.relpath(absolute_path, start=self.master_node.wallets_path)
1009+
1010+
wallet = self.create_legacy_wallet(relative_name)
1011+
1012+
# Make a copy of the wallet with the solvables wallet name so that we are unable
1013+
# to create the solvables wallet when migrating, thus failing to migrate
1014+
wallet.unloadwallet()
1015+
solvables_path = os.path.join(common_parent, f"{wallet_name}_solvables")
1016+
1017+
shutil.copytree(self.old_node.wallets_path / relative_name, solvables_path)
1018+
original_shasum = sha256sum_file(os.path.join(solvables_path, "wallet.dat"))
1019+
1020+
self.old_node.loadwallet(relative_name)
1021+
1022+
# Add a multisig so that a solvables wallet is created
1023+
wallet.addmultisigaddress(2, [wallet.getnewaddress(), get_generate_key().pubkey])
1024+
wallet.importaddress(get_generate_key().p2pkh_addr)
1025+
1026+
self.old_node.unloadwallet(relative_name)
1027+
assert_raises_rpc_error(-4, "Failed to create database", self.master_node.migratewallet, relative_name)
1028+
1029+
assert all(wallet not in self.master_node.listwallets() for wallet in [f"{wallet_name}", f"{wallet_name}_watchonly", f"{wallet_name}_solvables"])
1030+
1031+
assert not (self.master_node.wallets_path / f"{wallet_name}_watchonly").exists()
1032+
# Since the file in failed_solvables is one that we put there, migration shouldn't touch it
1033+
assert os.path.exists(solvables_path)
1034+
new_shasum = sha256sum_file(os.path.join(solvables_path , "wallet.dat"))
1035+
assert_equal(original_shasum, new_shasum)
1036+
1037+
# Check the wallet we tried to migrate is still BDB
1038+
datfile = os.path.join(absolute_path, "wallet.dat")
1039+
with open(datfile, "rb") as f:
1040+
data = f.read(16)
1041+
_, _, magic = struct.unpack("QII", data)
1042+
assert_equal(magic, BTREE_MAGIC)
1043+
9971044
def test_blank(self):
9981045
self.log.info("Test that a blank wallet is migrated")
9991046
wallet = self.create_legacy_wallet("blank", blank=True)
@@ -1468,6 +1515,7 @@ def run_test(self):
14681515
self.test_conflict_txs()
14691516
self.test_hybrid_pubkey()
14701517
self.test_failed_migration_cleanup()
1518+
self.test_failed_migration_cleanup_relative_path()
14711519
self.test_avoidreuse()
14721520
self.test_preserve_tx_extra_info()
14731521
self.test_blank()

0 commit comments

Comments
 (0)