|
10 | 10 | from test_framework.util import (
|
11 | 11 | assert_equal,
|
12 | 12 | assert_raises_rpc_error,
|
| 13 | + assert_greater_than, |
| 14 | + assert_greater_than_or_equal, |
13 | 15 | )
|
14 | 16 |
|
15 | 17 | class WalletEncryptionTest(BitcoinTestFramework):
|
@@ -56,6 +58,23 @@ def run_test(self):
|
56 | 58 | assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase, 10)
|
57 | 59 | self.nodes[0].walletpassphrase(passphrase2, 10)
|
58 | 60 | assert_equal(privkey, self.nodes[0].dumpprivkey(address))
|
| 61 | + self.nodes[0].walletlock() |
| 62 | + |
| 63 | + # Test timeout bounds |
| 64 | + assert_raises_rpc_error(-8, "Timeout cannot be negative.", self.nodes[0].walletpassphrase, passphrase2, -10) |
| 65 | + # Check the timeout |
| 66 | + # Check a time less than the limit |
| 67 | + expected_time = int(time.time()) + (1 << 30) - 600 |
| 68 | + self.nodes[0].walletpassphrase(passphrase2, (1 << 30) - 600) |
| 69 | + actual_time = self.nodes[0].getwalletinfo()['unlocked_until'] |
| 70 | + assert_greater_than_or_equal(actual_time, expected_time) |
| 71 | + assert_greater_than(expected_time + 5, actual_time) # 5 second buffer |
| 72 | + # Check a time greater than the limit |
| 73 | + expected_time = int(time.time()) + (1 << 30) - 1 |
| 74 | + self.nodes[0].walletpassphrase(passphrase2, (1 << 33)) |
| 75 | + actual_time = self.nodes[0].getwalletinfo()['unlocked_until'] |
| 76 | + assert_greater_than_or_equal(actual_time, expected_time) |
| 77 | + assert_greater_than(expected_time + 5, actual_time) # 5 second buffer |
59 | 78 |
|
60 | 79 | if __name__ == '__main__':
|
61 | 80 | WalletEncryptionTest().main()
|
0 commit comments