MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / run_test

Method run_test

test/functional/wallet_encryption.py:25–81  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

23 self.skip_if_no_wallet()
24
25 def run_test(self):
26 passphrase = "WalletPassphrase"
27 passphrase2 = "SecondWalletPassphrase"
28
29 # Make sure the wallet isn't encrypted first
30 address = self.nodes[0].getnewaddress()
31 privkey = self.nodes[0].dumpprivkey(address)
32 assert_equal(privkey[:1], "c")
33 assert_equal(len(privkey), 52)
34
35 # Encrypt the wallet
36 self.nodes[0].node_encrypt_wallet(passphrase)
37 self.start_node(0)
38
39 # Test that the wallet is encrypted
40 assert_raises_rpc_error(-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_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].dumpprivkey, address)
49
50 # Test wrong passphrase
51 assert_raises_rpc_error(-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_rpc_error(-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_rpc_error(-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 self.nodes[0].walletlock()
65
66 # Test timeout bounds
67 assert_raises_rpc_error(-8, "Timeout cannot be negative.", self.nodes[0].walletpassphrase, passphrase2, -10)
68 # Check the timeout
69 # Check a time less than the limit
70 MAX_VALUE = 100000000
71 expected_time = int(time.time()) + MAX_VALUE - 600
72 self.nodes[0].walletpassphrase(passphrase2, MAX_VALUE - 600)
73 actual_time = self.nodes[0].getwalletinfo()['unlocked_until']
74 assert_greater_than_or_equal(actual_time, expected_time)
75 assert_greater_than(expected_time + 5, actual_time) # 5 second buffer
76 # Check a time greater than the limit
77 expected_time = int(time.time()) + MAX_VALUE - 1
78 self.nodes[0].walletpassphrase(passphrase2, MAX_VALUE + 1000)
79 actual_time = self.nodes[0].getwalletinfo()['unlocked_until']
80 assert_greater_than_or_equal(actual_time, expected_time)
81 assert_greater_than(expected_time + 5, actual_time) # 5 second buffer
82

Callers

nothing calls this directly

Calls 6

assert_equalFunction · 0.90
assert_raises_rpc_errorFunction · 0.90
assert_greater_thanFunction · 0.90
node_encrypt_walletMethod · 0.80
start_nodeMethod · 0.80

Tested by

no test coverage detected