mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
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.
Github-Pull: #34156
Rebased-From: 36093bde63
This commit is contained in:
@@ -654,6 +654,38 @@ class WalletMigrationTest(BitcoinTestFramework):
|
||||
# migrate_and_get_rpc already checks for backup file existence
|
||||
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):
|
||||
self.log.info("Test migration of a wallet that is not in a wallet directory")
|
||||
wallet = self.create_legacy_wallet("plainfile")
|
||||
@@ -1539,6 +1571,7 @@ class WalletMigrationTest(BitcoinTestFramework):
|
||||
self.test_wallet_with_relative_path()
|
||||
self.test_wallet_with_path("path/to/mywallet/")
|
||||
self.test_wallet_with_path("path/that/ends/in/..")
|
||||
self.test_default_wallet_failure()
|
||||
self.test_default_wallet()
|
||||
self.test_direct_file()
|
||||
self.test_addressbook()
|
||||
|
||||
Reference in New Issue
Block a user