Merge #10859: RPC: gettxout: Slightly improve doc and tests
[bitcoinplatinum.git] / test / functional / wallet-encryption.py
blob8fea4140db7591b32800de4e82471fcd44fe9228
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].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
44 time.sleep(2)
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)
50 # Test walletlock
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()