Skip to content

Commit 134cdc7

Browse files
committed
Test walletpassphrase timeout bounds and clamping
1 parent 0b63e3c commit 134cdc7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/functional/wallet-encryption.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from test_framework.util import (
1111
assert_equal,
1212
assert_raises_rpc_error,
13+
assert_greater_than,
14+
assert_greater_than_or_equal,
1315
)
1416

1517
class WalletEncryptionTest(BitcoinTestFramework):
@@ -56,6 +58,23 @@ def run_test(self):
5658
assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase, 10)
5759
self.nodes[0].walletpassphrase(passphrase2, 10)
5860
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
5978

6079
if __name__ == '__main__':
6180
WalletEncryptionTest().main()

0 commit comments

Comments
 (0)