test: add coverage for unnamed wallet migration failure
Verifies that a failed migration of the unnamed (default) wallet does not erase the main /wallets/ directory, and also that the backup file exists.
This commit is contained in:
1 file changed
+33
@@ -675,6 +675,38 @@ class WalletMigrationTest(BitcoinTestFramework):
|
|||||||
# migrate_and_get_rpc already checks for backup file existence
|
# migrate_and_get_rpc already checks for backup file existence
|
||||||
assert os.path.basename(res["backup_path"]).startswith("default_wallet")
|
assert os.path.basename(res["backup_path"]).startswith("default_wallet")
|
||||||
|
|
||||||
|
wallet.unloadwallet()
|
||||||
|
|
||||||
|
def test_default_wallet_failure(self):
|
||||||
|
self.log.info("Test failure during unnamed (default) wallet migration")
|
||||||
|
master_wallet = self.master_node.get_wallet_rpc(self.default_wallet_name)
|
||||||
|
wallet = self.create_legacy_wallet("", blank=True)
|
||||||
|
wallet.importaddress(master_wallet.getnewaddress(address_type="legacy"))
|
||||||
|
|
||||||
|
# Create wallet directory with the watch-only name and a wallet file.
|
||||||
|
# Because the wallet dir exists, this will cause migration to fail.
|
||||||
|
watch_only_dir = self.master_node.wallets_path / "_watchonly"
|
||||||
|
os.mkdir(watch_only_dir)
|
||||||
|
shutil.copyfile(self.old_node.wallets_path / "wallet.dat", watch_only_dir / "wallet.dat")
|
||||||
|
|
||||||
|
mocked_time = int(time.time())
|
||||||
|
self.master_node.setmocktime(mocked_time)
|
||||||
|
assert_raises_rpc_error(-4, "Failed to create database", self.migrate_and_get_rpc, "")
|
||||||
|
self.master_node.setmocktime(0)
|
||||||
|
|
||||||
|
# Verify the /wallets/ path exists
|
||||||
|
assert self.master_node.wallets_path.exists()
|
||||||
|
# Check backup file exists. Because the wallet has no name, the backup is prefixed with 'default_wallet'
|
||||||
|
backup_path = self.master_node.wallets_path / f"default_wallet_{mocked_time}.legacy.bak"
|
||||||
|
assert backup_path.exists()
|
||||||
|
# Verify the original unnamed wallet was restored
|
||||||
|
assert (self.master_node.wallets_path / "wallet.dat").exists()
|
||||||
|
# And verify it is still a BDB wallet
|
||||||
|
self.assert_is_bdb("")
|
||||||
|
|
||||||
|
# Test cleanup: clear default wallet for next test
|
||||||
|
os.remove(self.old_node.wallets_path / "wallet.dat")
|
||||||
|
|
||||||
def test_direct_file(self):
|
def test_direct_file(self):
|
||||||
self.log.info("Test migration of a wallet that is not in a wallet directory")
|
self.log.info("Test migration of a wallet that is not in a wallet directory")
|
||||||
wallet = self.create_legacy_wallet("plainfile")
|
wallet = self.create_legacy_wallet("plainfile")
|
||||||
@@ -1560,6 +1592,7 @@ class WalletMigrationTest(BitcoinTestFramework):
|
|||||||
self.test_wallet_with_relative_path()
|
self.test_wallet_with_relative_path()
|
||||||
self.test_wallet_with_path("path/to/mywallet/")
|
self.test_wallet_with_path("path/to/mywallet/")
|
||||||
self.test_wallet_with_path("path/that/ends/in/..")
|
self.test_wallet_with_path("path/that/ends/in/..")
|
||||||
|
self.test_default_wallet_failure()
|
||||||
self.test_default_wallet()
|
self.test_default_wallet()
|
||||||
self.test_direct_file()
|
self.test_direct_file()
|
||||||
self.test_addressbook()
|
self.test_addressbook()
|
||||||
|
|||||||
Reference in new issue
Block a user