Skip to content

Commit c73c8d5

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25878: tests: Use mocktime for wallet encryption timeout
02dea9a tests: Use mocktime for wallet encryption timeout (Andrew Chow) Pull request description: The intermittent wallet_encryption.py failures are related to differences in time between python and std::chrono. We can avoid this entirely by using mocktime. This also allows us to test for the exact unlocking time rather than that it is greater than expected. Fixes #25482 ACKs for top commit: MarcoFalke: review ACK 02dea9a vasild: ACK 02dea9a Tree-SHA512: 5a5489f5cd2569c824bf5b3d839be0c632ed27627c0eff65dda63c143a8d1174fe3252acba8102b4242a9ddf42d82bfe79babad68f1beeb83eb251386058e039
2 parents 6b56873 + 02dea9a commit c73c8d5

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

test/functional/wallet_encryption.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import (
1111
assert_raises_rpc_error,
12-
assert_greater_than,
13-
assert_greater_than_or_equal,
12+
assert_equal,
1413
)
1514

1615

@@ -76,21 +75,18 @@ def run_test(self):
7675

7776
self.log.info('Check a timeout less than the limit')
7877
MAX_VALUE = 100000000
79-
expected_time = int(time.time()) + MAX_VALUE - 600
78+
now = int(time.time())
79+
self.nodes[0].setmocktime(now)
80+
expected_time = now + MAX_VALUE - 600
8081
self.nodes[0].walletpassphrase(passphrase2, MAX_VALUE - 600)
81-
# give buffer for walletpassphrase, since it iterates over all encrypted keys
82-
expected_time_with_buffer = time.time() + MAX_VALUE - 600
8382
actual_time = self.nodes[0].getwalletinfo()['unlocked_until']
84-
assert_greater_than_or_equal(actual_time, expected_time)
85-
assert_greater_than(expected_time_with_buffer, actual_time)
83+
assert_equal(actual_time, expected_time)
8684

8785
self.log.info('Check a timeout greater than the limit')
88-
expected_time = int(time.time()) + MAX_VALUE - 1
86+
expected_time = now + MAX_VALUE
8987
self.nodes[0].walletpassphrase(passphrase2, MAX_VALUE + 1000)
90-
expected_time_with_buffer = time.time() + MAX_VALUE
9188
actual_time = self.nodes[0].getwalletinfo()['unlocked_until']
92-
assert_greater_than_or_equal(actual_time, expected_time)
93-
assert_greater_than(expected_time_with_buffer, actual_time)
89+
assert_equal(actual_time, expected_time)
9490

9591

9692
if __name__ == '__main__':

0 commit comments

Comments
 (0)