Skip to content

Commit 6702617

Browse files
committed
Merge #10551: [Tests] Wallet encryption functional tests
ec98b78 Tests for wallet encryption stuff (Andrew Chow) Tree-SHA512: 176f146dee87f7eaf6de689598ddf257264bb77c2f8c0f9b00276e0dd956327463fb50403a32916f00765d2b2a588c1692a600b36bb3c9e7fa2f18d7cc3b4bc0
2 parents b63be2c + ec98b78 commit 6702617

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
'rpcnamedargs.py',
112112
'listsinceblock.py',
113113
'p2p-leaktests.py',
114+
'wallet-encryption.py',
114115
]
115116

116117
EXTENDED_SCRIPTS = [

test/functional/wallet-encryption.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2016 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test Wallet encryption"""
6+
7+
import time
8+
9+
from test_framework.test_framework import BitcoinTestFramework
10+
from test_framework.util import (
11+
assert_equal,
12+
assert_raises_jsonrpc,
13+
bitcoind_processes,
14+
BITCOIND_PROC_WAIT_TIMEOUT,
15+
)
16+
17+
class WalletEncryptionTest(BitcoinTestFramework):
18+
19+
def __init__(self):
20+
super().__init__()
21+
self.setup_clean_chain = True
22+
self.num_nodes = 1
23+
24+
def run_test(self):
25+
passphrase = "WalletPassphrase"
26+
passphrase2 = "SecondWalletPassphrase"
27+
28+
# Make sure the wallet isn't encrypted first
29+
address = self.nodes[0].getnewaddress()
30+
privkey = self.nodes[0].dumpprivkey(address)
31+
assert_equal(privkey[:1], "c")
32+
assert_equal(len(privkey), 52)
33+
34+
# Encrypt the wallet
35+
self.nodes[0].encryptwallet(passphrase)
36+
bitcoind_processes[0].wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT)
37+
self.nodes[0] = self.start_node(0, self.options.tmpdir)
38+
39+
# Test that the wallet is encrypted
40+
assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
41+
42+
# Check that walletpassphrase works
43+
self.nodes[0].walletpassphrase(passphrase, 2)
44+
assert_equal(privkey, self.nodes[0].dumpprivkey(address))
45+
46+
# Check that the timeout is right
47+
time.sleep(2)
48+
assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
49+
50+
# Test wrong passphrase
51+
assert_raises_jsonrpc(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase + "wrong", 10)
52+
53+
# Test walletlock
54+
self.nodes[0].walletpassphrase(passphrase, 84600)
55+
assert_equal(privkey, self.nodes[0].dumpprivkey(address))
56+
self.nodes[0].walletlock()
57+
assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
58+
59+
# Test passphrase changes
60+
self.nodes[0].walletpassphrasechange(passphrase, passphrase2)
61+
assert_raises_jsonrpc(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase, 10)
62+
self.nodes[0].walletpassphrase(passphrase2, 10)
63+
assert_equal(privkey, self.nodes[0].dumpprivkey(address))
64+
65+
if __name__ == '__main__':
66+
WalletEncryptionTest().main()

0 commit comments

Comments
 (0)