Skip to content

Commit 037b101

Browse files
committed
test: Add coverage for best block locator write in wallet_backup
1 parent 31c0df0 commit 037b101

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/functional/wallet_backup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ def restore_wallet_existent_name(self):
140140
assert_raises_rpc_error(-36, error_message, node.restorewallet, wallet_name, backup_file)
141141
assert wallet_file.exists()
142142

143+
def test_pruned_wallet_backup(self):
144+
self.log.info("Test loading backup on a pruned node when the backup was created close to the prune height of the restoring node")
145+
node = self.nodes[3]
146+
self.restart_node(3, ["-prune=1", "-fastprune=1"])
147+
# Ensure the chain tip is at height 214, because this test assume it is.
148+
assert_equal(node.getchaintips()[0]["height"], 214)
149+
# We need a few more blocks so we can actually get above an realistic
150+
# minimal prune height
151+
self.generate(node, 50, sync_fun=self.no_op)
152+
# Backup created at block height 264
153+
node.backupwallet(node.datadir_path / 'wallet_pruned.bak')
154+
# Generate more blocks so we can actually prune the older blocks
155+
self.generate(node, 300, sync_fun=self.no_op)
156+
# This gives us an actual prune height roughly in the range of 220 - 240
157+
node.pruneblockchain(250)
158+
# The backup should be updated with the latest height (locator) for
159+
# the backup to load successfully this close to the prune height
160+
node.restorewallet(f'pruned', node.datadir_path / 'wallet_pruned.bak')
161+
143162
def run_test(self):
144163
self.log.info("Generating initial blockchain")
145164
self.generate(self.nodes[0], 1)
@@ -242,6 +261,8 @@ def run_test(self):
242261
for sourcePath in sourcePaths:
243262
assert_raises_rpc_error(-4, "backup failed", self.nodes[0].backupwallet, sourcePath)
244263

264+
self.test_pruned_wallet_backup()
265+
245266

246267
if __name__ == '__main__':
247268
WalletBackupTest(__file__).main()

0 commit comments

Comments
 (0)