Skip to content

Commit 86e1111

Browse files
committed
test: verify node skips loading legacy wallets during startup
1 parent 9f94de5 commit 86e1111

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/functional/wallet_backwards_compatibility.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
needs an older patch version.
1515
"""
1616

17+
import json
1718
import os
1819
import shutil
1920

@@ -161,6 +162,38 @@ def test_v22_inactivehdchain_path(self):
161162
except ImportError:
162163
self.log.warning("sqlite3 module not available, skipping lack of keymeta records check")
163164

165+
def test_ignore_legacy_during_startup(self, legacy_nodes, node_master):
166+
self.log.info("Test that legacy wallets are ignored during startup on v29+")
167+
168+
legacy_node = legacy_nodes[0]
169+
wallet_name = f"legacy_up_{legacy_node.version}"
170+
legacy_node.loadwallet(wallet_name)
171+
legacy_wallet = legacy_node.get_wallet_rpc(wallet_name)
172+
173+
# Move legacy wallet to latest node
174+
wallet_path = node_master.wallets_path / wallet_name
175+
wallet_path.mkdir()
176+
legacy_wallet.backupwallet(wallet_path / "wallet.dat")
177+
legacy_wallet.unloadwallet()
178+
179+
# Write wallet so it is automatically loaded during init
180+
settings_path = node_master.chain_path / "settings.json"
181+
with settings_path.open("w") as fp:
182+
json.dump({"wallet": [wallet_name]}, fp)
183+
184+
# Restart latest node and verify that the legacy wallet load is skipped without exiting early during init.
185+
self.restart_node(node_master.index, extra_args=[])
186+
# Ensure we receive the warning message and clear the stderr pipe.
187+
node_master.stderr.seek(0)
188+
warning_msg = node_master.stderr.read().decode('utf-8').strip()
189+
assert "The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC or the GUI option)" in warning_msg
190+
node_master.stderr.truncate(0), node_master.stderr.seek(0) # reset buffer
191+
192+
# Verify the node is still running (no shutdown occurred during startup)
193+
node_master.getblockcount()
194+
# Reset settings for any subsequent test
195+
os.remove(settings_path)
196+
164197
def run_test(self):
165198
node_miner = self.nodes[0]
166199
node_master = self.nodes[1]
@@ -381,6 +414,7 @@ def run_test(self):
381414
assert_raises_rpc_error(-18, "The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC or the GUI option)", node_master.restorewallet, wallet_name, backup_path)
382415

383416
self.test_v22_inactivehdchain_path()
417+
self.test_ignore_legacy_during_startup(legacy_nodes, node_master)
384418

385419
if __name__ == '__main__':
386420
BackwardsCompatibilityTest(__file__).main()

0 commit comments

Comments
 (0)