test: wallet: Check that loading wallet with both unencrypted and encrypted keys fails.

This commit is contained in:
David Gumberg
2026-04-22 18:14:17 -07:00
committed by Ava Chow
parent 80b0c25992
commit 8be5ee554b

View File

@@ -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__':