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"""
9 from test_framework
.test_framework
import BitcoinTestFramework
, BITCOIND_PROC_WAIT_TIMEOUT
10 from test_framework
.util
import (
12 assert_raises_jsonrpc
,
15 class WalletEncryptionTest(BitcoinTestFramework
):
19 self
.setup_clean_chain
= True
23 passphrase
= "WalletPassphrase"
24 passphrase2
= "SecondWalletPassphrase"
26 # Make sure the wallet isn't encrypted first
27 address
= self
.nodes
[0].getnewaddress()
28 privkey
= self
.nodes
[0].dumpprivkey(address
)
29 assert_equal(privkey
[:1], "c")
30 assert_equal(len(privkey
), 52)
33 self
.nodes
[0].node_encrypt_wallet(passphrase
)
34 self
.nodes
[0] = self
.start_node(0, self
.options
.tmpdir
)
36 # Test that the wallet is encrypted
37 assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self
.nodes
[0].dumpprivkey
, address
)
39 # Check that walletpassphrase works
40 self
.nodes
[0].walletpassphrase(passphrase
, 2)
41 assert_equal(privkey
, self
.nodes
[0].dumpprivkey(address
))
43 # Check that the timeout is right
45 assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self
.nodes
[0].dumpprivkey
, address
)
47 # Test wrong passphrase
48 assert_raises_jsonrpc(-14, "wallet passphrase entered was incorrect", self
.nodes
[0].walletpassphrase
, passphrase
+ "wrong", 10)
51 self
.nodes
[0].walletpassphrase(passphrase
, 84600)
52 assert_equal(privkey
, self
.nodes
[0].dumpprivkey(address
))
53 self
.nodes
[0].walletlock()
54 assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self
.nodes
[0].dumpprivkey
, address
)
56 # Test passphrase changes
57 self
.nodes
[0].walletpassphrasechange(passphrase
, passphrase2
)
58 assert_raises_jsonrpc(-14, "wallet passphrase entered was incorrect", self
.nodes
[0].walletpassphrase
, passphrase
, 10)
59 self
.nodes
[0].walletpassphrase(passphrase2
, 10)
60 assert_equal(privkey
, self
.nodes
[0].dumpprivkey(address
))
62 if __name__
== '__main__':
63 WalletEncryptionTest().main()