|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Test Wallet encryption"""
|
6 | 6 |
|
| 7 | +import os |
| 8 | +import subprocess |
7 | 9 | import time
|
8 | 10 |
|
9 | 11 | from test_framework.test_framework import BitcoinTestFramework
|
@@ -47,6 +49,25 @@ def run_test(self):
|
47 | 49 | assert_raises_rpc_error(-8, "passphrase cannot be empty", self.nodes[0].walletpassphrase, '', 1)
|
48 | 50 | assert_raises_rpc_error(-8, "passphrase cannot be empty", self.nodes[0].walletpassphrasechange, '', 'ff')
|
49 | 51 |
|
| 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 | + |
50 | 71 | # Check that walletpassphrase works
|
51 | 72 | self.nodes[0].walletpassphrase(passphrase, 2)
|
52 | 73 | sig = self.nodes[0].signmessage(address, msg)
|
|
0 commit comments