From 8be5ee554bb9c8053de2e6addc6abed950555654 Mon Sep 17 00:00:00 2001 From: David Gumberg Date: Wed, 22 Apr 2026 18:14:17 -0700 Subject: [PATCH] test: wallet: Check that loading wallet with both unencrypted and encrypted keys fails. --- test/functional/wallet_descriptor.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/functional/wallet_descriptor.py b/test/functional/wallet_descriptor.py index 39b80bf79bf..ee8ea1927a0 100755 --- a/test/functional/wallet_descriptor.py +++ b/test/functional/wallet_descriptor.py @@ -12,6 +12,7 @@ except ImportError: import re from test_framework.blocktools import COINBASE_MATURITY +from test_framework.messages import ser_string from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_not_equal, @@ -268,6 +269,25 @@ class WalletDescriptorTest(BitcoinTestFramework): conn.close() assert_raises_rpc_error(-4, "Unexpected legacy entry in descriptor wallet found.", self.nodes[0].loadwallet, "crashme") + self.log.info("Test that loading descriptor wallet containing both unencrypted and encrypted keys for same descriptor fails to load") + wallet_name = "mixed_crypt" + self.nodes[0].createwallet(wallet_name) + self.nodes[0].unloadwallet(wallet_name) + wallet_db = self.nodes[0].wallets_path / wallet_name / self.wallet_data_filename + conn = sqlite3.connect(wallet_db) + with conn: + key_prefix = ser_string(b"walletdescriptorkey") + ckey_prefix = ser_string(b"walletdescriptorckey") + rows = conn.execute('SELECT key, value FROM main').fetchall() + key_rows = [(k, v) for k, v in rows if k.startswith(key_prefix)] + # Test the test, want to be sure there is at least one unencrypted key. + assert len(key_rows) >= 1 + k, v = key_rows[0] + conn.execute('INSERT INTO main VALUES(?, ?)', (k.replace(key_prefix, ckey_prefix), v)) + conn.close() + with self.nodes[0].assert_debug_log(["Wallet contains both unencrypted and encrypted keys"]): + assert_raises_rpc_error(-4, "Wallet corrupted", self.nodes[0].loadwallet, wallet_name) + self.test_parent_descriptors() if __name__ == '__main__':