Skip to content

Commit b7c34d0

Browse files
committed
test: coverage for migration failure when last sync is beyond prune height
1 parent 82caa81 commit b7c34d0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/functional/wallet_migration.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,37 @@ def test_loading_failure_after_migration(self):
16031603
self.start_node(self.old_node.index)
16041604
self.connect_nodes(1, 0)
16051605

1606+
def unsynced_wallet_on_pruned_node_fails(self):
1607+
self.log.info("Test migration of an unsynced wallet on a pruned node fails gracefully")
1608+
wallet = self.create_legacy_wallet("", load_on_startup=False)
1609+
last_wallet_synced_block = wallet.getwalletinfo()['lastprocessedblock']['height']
1610+
wallet.unloadwallet()
1611+
1612+
shutil.copyfile(self.old_node.wallets_path / "wallet.dat", self.master_node.wallets_path / "wallet.dat")
1613+
1614+
# Generate blocks just so the wallet best block is pruned
1615+
self.restart_node(0, ["-fastprune", "-prune=1", "-nowallet"])
1616+
self.connect_nodes(0, 1)
1617+
self.generate(self.master_node, 450, sync_fun=self.no_op)
1618+
self.master_node.pruneblockchain(250)
1619+
# Ensure next block to sync is unavailable
1620+
assert_raises_rpc_error(-1, "Block not available (pruned data)", self.master_node.getblock, self.master_node.getblockhash(last_wallet_synced_block + 1))
1621+
1622+
# Check migration failure
1623+
mocked_time = int(time.time())
1624+
self.master_node.setmocktime(mocked_time)
1625+
assert_raises_rpc_error(-4, "last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of a pruned node)", self.master_node.migratewallet, wallet_name="")
1626+
self.master_node.setmocktime(0)
1627+
1628+
# Verify the /wallets/ path exists, the wallet is still BDB and the backup file is there.
1629+
assert self.master_node.wallets_path.exists()
1630+
self.assert_is_bdb("")
1631+
backup_path = self.master_node.wallets_path / f"default_wallet_{mocked_time}.legacy.bak"
1632+
assert backup_path.exists()
1633+
1634+
self.clear_default_wallet(backup_path)
1635+
1636+
16061637
def run_test(self):
16071638
self.master_node = self.nodes[0]
16081639
self.old_node = self.nodes[1]
@@ -1643,5 +1674,8 @@ def run_test(self):
16431674
self.test_solvable_no_privs()
16441675
self.test_loading_failure_after_migration()
16451676

1677+
# Note: After this test the first 250 blocks of 'master_node' are pruned
1678+
self.unsynced_wallet_on_pruned_node_fails()
1679+
16461680
if __name__ == '__main__':
16471681
WalletMigrationTest(__file__).main()

0 commit comments

Comments
 (0)