diff options
author | MacroFake <falke.marco@gmail.com> | 2022-08-20 08:50:16 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-08-20 08:50:19 +0200 |
commit | c73c8d53fe27956faacb3e8ca0e94adf071de6ec (patch) | |
tree | 4e7efd21b862e32c5e3836fcc4ebb989c63dea97 | |
parent | 6b56873b41974ced7aad87a4b38abe360c34eed3 (diff) | |
parent | 02dea9a47fa17e977c9de72233ebd74e913fa30a (diff) |
Merge bitcoin/bitcoin#25878: tests: Use mocktime for wallet encryption timeout
02dea9a47fa17e977c9de72233ebd74e913fa30a 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 02dea9a47fa17e977c9de72233ebd74e913fa30a
vasild:
ACK 02dea9a47fa17e977c9de72233ebd74e913fa30a
Tree-SHA512: 5a5489f5cd2569c824bf5b3d839be0c632ed27627c0eff65dda63c143a8d1174fe3252acba8102b4242a9ddf42d82bfe79babad68f1beeb83eb251386058e039
-rwxr-xr-x | test/functional/wallet_encryption.py | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/test/functional/wallet_encryption.py b/test/functional/wallet_encryption.py index 0c9106f800..37c1c4bff3 100755 --- a/test/functional/wallet_encryption.py +++ b/test/functional/wallet_encryption.py @@ -9,8 +9,7 @@ import time from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_raises_rpc_error, - assert_greater_than, - assert_greater_than_or_equal, + assert_equal, ) @@ -76,21 +75,18 @@ class WalletEncryptionTest(BitcoinTestFramework): self.log.info('Check a timeout less than the limit') MAX_VALUE = 100000000 - expected_time = int(time.time()) + MAX_VALUE - 600 + now = int(time.time()) + self.nodes[0].setmocktime(now) + expected_time = now + MAX_VALUE - 600 self.nodes[0].walletpassphrase(passphrase2, MAX_VALUE - 600) - # give buffer for walletpassphrase, since it iterates over all encrypted keys - expected_time_with_buffer = time.time() + MAX_VALUE - 600 actual_time = self.nodes[0].getwalletinfo()['unlocked_until'] - assert_greater_than_or_equal(actual_time, expected_time) - assert_greater_than(expected_time_with_buffer, actual_time) + assert_equal(actual_time, expected_time) self.log.info('Check a timeout greater than the limit') - expected_time = int(time.time()) + MAX_VALUE - 1 + expected_time = now + MAX_VALUE self.nodes[0].walletpassphrase(passphrase2, MAX_VALUE + 1000) - expected_time_with_buffer = time.time() + MAX_VALUE actual_time = self.nodes[0].getwalletinfo()['unlocked_until'] - assert_greater_than_or_equal(actual_time, expected_time) - assert_greater_than(expected_time_with_buffer, actual_time) + assert_equal(actual_time, expected_time) if __name__ == '__main__': |