scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal instead...
[bitcoinplatinum.git] / test / functional / wallet-encryption.py
blobba72918fe1564dcf09153c5711ef9e9e8c373fc4
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"""
7 import time
9 from test_framework.test_framework import BitcoinTestFramework, BITCOIND_PROC_WAIT_TIMEOUT
10 from test_framework.util import (
11 assert_equal,
12 assert_raises_jsonrpc,
15 class WalletEncryptionTest(BitcoinTestFramework):
17 def __init__(self):
18 super().__init__()
19 self.setup_clean_chain = True
20 self.num_nodes = 1
22 def run_test(self):
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)
32 # Encrypt the wallet
33 self.nodes[0].encryptwallet(passphrase)
34 self.bitcoind_processes[0].wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT)
35 self.nodes[0] = self.start_node(0, self.options.tmpdir)
37 # Test that the wallet is encrypted
38 assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
40 # Check that walletpassphrase works
41 self.nodes[0].walletpassphrase(passphrase, 2)
42 assert_equal(privkey, self.nodes[0].dumpprivkey(address))
44 # Check that the timeout is right
45 time.sleep(2)
46 assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
48 # Test wrong passphrase
49 assert_raises_jsonrpc(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase + "wrong", 10)
51 # Test walletlock
52 self.nodes[0].walletpassphrase(passphrase, 84600)
53 assert_equal(privkey, self.nodes[0].dumpprivkey(address))
54 self.nodes[0].walletlock()
55 assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
57 # Test passphrase changes
58 self.nodes[0].walletpassphrasechange(passphrase, passphrase2)
59 assert_raises_jsonrpc(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase, 10)
60 self.nodes[0].walletpassphrase(passphrase2, 10)
61 assert_equal(privkey, self.nodes[0].dumpprivkey(address))
63 if __name__ == '__main__':
64 WalletEncryptionTest().main()