Skip to content

Commit 0312cff

Browse files
committed
test: Check that no unencrypted records persist after encrypting
1 parent 5351df3 commit 0312cff

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/functional/wallet_encryption.py

+21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test Wallet encryption"""
66

7+
import os
8+
import subprocess
79
import time
810

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

52+
# Make sure there are no unencrypted key records
53+
# Use the wallet tool's dump mechanism to get all of the records to inspect them.
54+
self.nodes[0].unloadwallet(self.default_wallet_name)
55+
dump_file = os.path.join(self.nodes[0].datadir_path, "wallet.dump")
56+
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)
57+
self.nodes[0].loadwallet(self.default_wallet_name)
58+
# Look for records that contain the hex for 'key' but not 'ckey'
59+
key_hex = b"key".hex()
60+
ckey_hex = b"ckey".hex()
61+
# Hex for records to skip
62+
skip_records = [b"mkey".hex(), b"activehdkey".hex(), b"defaultkey".hex(), b"keymeta".hex()]
63+
with open(dump_file, "r", encoding="utf8") as f:
64+
for row in f:
65+
k, v = row.split(",")
66+
# Skip 'mkey' records. These aren't private key records.
67+
if any([skip in k for skip in skip_records]):
68+
continue
69+
assert ckey_hex in k or key_hex not in k, "Unexpected unencrypted key record"
70+
5071
# Check that walletpassphrase works
5172
self.nodes[0].walletpassphrase(passphrase, 2)
5273
sig = self.nodes[0].signmessage(address, msg)

0 commit comments

Comments
 (0)