Skip to content

Commit 0b75315

Browse files
committed
test: Test bdb_ro dump of wallet without reset LSNs
1 parent c1984f1 commit 0b75315

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

test/functional/test_framework/test_node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,9 @@ def is_node_stopped(self, *, expected_stderr="", expected_ret_code=0):
419419
return True
420420

421421
def wait_until_stopped(self, *, timeout=BITCOIND_PROC_WAIT_TIMEOUT, expect_error=False, **kwargs):
422-
expected_ret_code = 1 if expect_error else 0 # Whether node shutdown return EXIT_FAILURE or EXIT_SUCCESS
423-
self.wait_until(lambda: self.is_node_stopped(expected_ret_code=expected_ret_code, **kwargs), timeout=timeout)
422+
if "expected_ret_code" not in kwargs:
423+
kwargs["expected_ret_code"] = 1 if expect_error else 0 # Whether node shutdown return EXIT_FAILURE or EXIT_SUCCESS
424+
self.wait_until(lambda: self.is_node_stopped(**kwargs), timeout=timeout)
424425

425426
def replace_in_config(self, replacements):
426427
"""

test/functional/tool_wallet.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""Test bitcoin-wallet."""
66

77
import os
8+
import platform
89
import stat
910
import subprocess
1011
import textwrap
@@ -45,9 +46,13 @@ def bitcoin_wallet_process(self, *args):
4546
def assert_raises_tool_error(self, error, *args):
4647
p = self.bitcoin_wallet_process(*args)
4748
stdout, stderr = p.communicate()
48-
assert_equal(p.poll(), 1)
4949
assert_equal(stdout, '')
50-
assert_equal(stderr.strip(), error)
50+
if isinstance(error, tuple):
51+
assert_equal(p.poll(), error[0])
52+
assert error[1] in stderr.strip()
53+
else:
54+
assert_equal(p.poll(), 1)
55+
assert error in stderr.strip()
5156

5257
def assert_tool_output(self, output, *args):
5358
p = self.bitcoin_wallet_process(*args)
@@ -510,6 +515,33 @@ def test_dump_very_large_records(self):
510515
else:
511516
assert False, "Big transaction was not found in wallet dump"
512517

518+
def test_dump_unclean_lsns(self):
519+
if not self.options.bdbro:
520+
return
521+
self.log.info("Test that a legacy wallet that has not been compacted is not dumped by bdbro")
522+
523+
self.start_node(0, extra_args=["-flushwallet=0"])
524+
self.nodes[0].createwallet("unclean_lsn")
525+
wallet = self.nodes[0].get_wallet_rpc("unclean_lsn")
526+
# First unload and load normally to make sure everything is written
527+
wallet.unloadwallet()
528+
self.nodes[0].loadwallet("unclean_lsn")
529+
# Next cause a bunch of writes by filling the keypool
530+
wallet.keypoolrefill(wallet.getwalletinfo()["keypoolsize"] + 100)
531+
# Lastly kill bitcoind so that the LSNs don't get reset
532+
self.nodes[0].process.kill()
533+
self.nodes[0].wait_until_stopped(expected_ret_code=1 if platform.system() == "Windows" else -9)
534+
assert self.nodes[0].is_node_stopped()
535+
536+
wallet_dump = self.nodes[0].datadir_path / "unclean_lsn.dump"
537+
self.assert_raises_tool_error("LSNs are not reset, this database is not completely flushed. Please reopen then close the database with a version that has BDB support", "-wallet=unclean_lsn", f"-dumpfile={wallet_dump}", "dump")
538+
539+
# File can be dumped after reload it normally
540+
self.start_node(0)
541+
self.nodes[0].loadwallet("unclean_lsn")
542+
self.stop_node(0)
543+
self.assert_tool_output("The dumpfile may contain private keys. To ensure the safety of your Bitcoin, do not share the dumpfile.\n", "-wallet=unclean_lsn", f"-dumpfile={wallet_dump}", "dump")
544+
513545
def run_test(self):
514546
self.wallet_path = self.nodes[0].wallets_path / self.default_wallet_name / self.wallet_data_filename
515547
self.test_invalid_tool_commands_and_args()
@@ -522,6 +554,7 @@ def run_test(self):
522554
# Salvage is a legacy wallet only thing
523555
self.test_salvage()
524556
self.test_dump_endianness()
557+
self.test_dump_unclean_lsns()
525558
self.test_dump_createfromdump()
526559
self.test_chainless_conflicts()
527560
self.test_dump_very_large_records()

0 commit comments

Comments
 (0)