Skip to content

Commit

Permalink
test: Check that no unencrypted records persist after encrypting
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Dec 11, 2023
1 parent 1bbbb73 commit 291cb32
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/functional/wallet_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test Wallet encryption"""

import os
import subprocess
import time

from test_framework.test_framework import BitcoinTestFramework
Expand Down Expand Up @@ -47,6 +49,25 @@ def run_test(self):
assert_raises_rpc_error(-8, "passphrase cannot be empty", self.nodes[0].walletpassphrase, '', 1)
assert_raises_rpc_error(-8, "passphrase cannot be empty", self.nodes[0].walletpassphrasechange, '', 'ff')

# Make sure there are no unencrypted key records
# Use the wallet tool's dump mechanism to get all of the records to inspect them.
self.nodes[0].unloadwallet(self.default_wallet_name)
dump_file = os.path.join(self.nodes[0].datadir_path, "wallet.dump")
subprocess.check_call([self.options.bitcoinwallet, f"-datadir={self.nodes[0].datadir_path}", f"-chain={self.chain}", f"-wallet={self.default_wallet_name}", f"-dumpfile={dump_file}", "dump"], stdout=subprocess.DEVNULL)
self.nodes[0].loadwallet(self.default_wallet_name)
# Look for records that contain the hex for 'key' but not 'ckey'
key_hex = b"key".hex()
ckey_hex = b"ckey".hex()
# Hex for records to skip
skip_records = [b"mkey".hex(), b"activehdkey".hex(), b"defaultkey".hex(), b"keymeta".hex()]
with open(dump_file, "r", encoding="utf8") as f:
for row in f:
k, v = row.split(",")
# Skip 'mkey' records. These aren't private key records.
if any([skip in k for skip in skip_records]):
continue
assert ckey_hex in k or key_hex not in k, "Unexpected unencrypted key record"

# Check that walletpassphrase works
self.nodes[0].walletpassphrase(passphrase, 2)
sig = self.nodes[0].signmessage(address, msg)
Expand Down

0 comments on commit 291cb32

Please sign in to comment.