aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-04-22 16:42:44 -0400
committerAva Chow <github@achow101.com>2024-05-16 15:03:13 -0400
commit0b753156ce60c29efb2386954ba7555ad8f642f5 (patch)
tree8e38413739349490b97b9068eb62aefc7a492be2 /test
parentc1984f128284589423b7e0cc06c9a3b23a242d95 (diff)
downloadbitcoin-0b753156ce60c29efb2386954ba7555ad8f642f5.tar.xz
test: Test bdb_ro dump of wallet without reset LSNs
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/test_framework/test_node.py5
-rwxr-xr-xtest/functional/tool_wallet.py37
2 files changed, 38 insertions, 4 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 67e0be5280..534f25e535 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -419,8 +419,9 @@ class TestNode():
return True
def wait_until_stopped(self, *, timeout=BITCOIND_PROC_WAIT_TIMEOUT, expect_error=False, **kwargs):
- expected_ret_code = 1 if expect_error else 0 # Whether node shutdown return EXIT_FAILURE or EXIT_SUCCESS
- self.wait_until(lambda: self.is_node_stopped(expected_ret_code=expected_ret_code, **kwargs), timeout=timeout)
+ if "expected_ret_code" not in kwargs:
+ kwargs["expected_ret_code"] = 1 if expect_error else 0 # Whether node shutdown return EXIT_FAILURE or EXIT_SUCCESS
+ self.wait_until(lambda: self.is_node_stopped(**kwargs), timeout=timeout)
def replace_in_config(self, replacements):
"""
diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py
index 92da687b02..51239831cc 100755
--- a/test/functional/tool_wallet.py
+++ b/test/functional/tool_wallet.py
@@ -5,6 +5,7 @@
"""Test bitcoin-wallet."""
import os
+import platform
import stat
import subprocess
import textwrap
@@ -45,9 +46,13 @@ class ToolWalletTest(BitcoinTestFramework):
def assert_raises_tool_error(self, error, *args):
p = self.bitcoin_wallet_process(*args)
stdout, stderr = p.communicate()
- assert_equal(p.poll(), 1)
assert_equal(stdout, '')
- assert_equal(stderr.strip(), error)
+ if isinstance(error, tuple):
+ assert_equal(p.poll(), error[0])
+ assert error[1] in stderr.strip()
+ else:
+ assert_equal(p.poll(), 1)
+ assert error in stderr.strip()
def assert_tool_output(self, output, *args):
p = self.bitcoin_wallet_process(*args)
@@ -510,6 +515,33 @@ class ToolWalletTest(BitcoinTestFramework):
else:
assert False, "Big transaction was not found in wallet dump"
+ def test_dump_unclean_lsns(self):
+ if not self.options.bdbro:
+ return
+ self.log.info("Test that a legacy wallet that has not been compacted is not dumped by bdbro")
+
+ self.start_node(0, extra_args=["-flushwallet=0"])
+ self.nodes[0].createwallet("unclean_lsn")
+ wallet = self.nodes[0].get_wallet_rpc("unclean_lsn")
+ # First unload and load normally to make sure everything is written
+ wallet.unloadwallet()
+ self.nodes[0].loadwallet("unclean_lsn")
+ # Next cause a bunch of writes by filling the keypool
+ wallet.keypoolrefill(wallet.getwalletinfo()["keypoolsize"] + 100)
+ # Lastly kill bitcoind so that the LSNs don't get reset
+ self.nodes[0].process.kill()
+ self.nodes[0].wait_until_stopped(expected_ret_code=1 if platform.system() == "Windows" else -9)
+ assert self.nodes[0].is_node_stopped()
+
+ wallet_dump = self.nodes[0].datadir_path / "unclean_lsn.dump"
+ 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")
+
+ # File can be dumped after reload it normally
+ self.start_node(0)
+ self.nodes[0].loadwallet("unclean_lsn")
+ self.stop_node(0)
+ 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")
+
def run_test(self):
self.wallet_path = self.nodes[0].wallets_path / self.default_wallet_name / self.wallet_data_filename
self.test_invalid_tool_commands_and_args()
@@ -522,6 +554,7 @@ class ToolWalletTest(BitcoinTestFramework):
# Salvage is a legacy wallet only thing
self.test_salvage()
self.test_dump_endianness()
+ self.test_dump_unclean_lsns()
self.test_dump_createfromdump()
self.test_chainless_conflicts()
self.test_dump_very_large_records()