1 #!/usr/bin/env python3
2 # Copyright (c) 2017-2022 The Limenka developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test the RPC call related to the uptime command.
6 7 Test corresponds to code in rpc/server.cpp.
8 """
9 10 import time
11 12 from test_framework.test_framework import LimenkaTestFramework
13 from test_framework.util import assert_raises_rpc_error
14 15 16 class UptimeTest(LimenkaTestFramework):
17 def set_test_params(self):
18 self.num_nodes = 1
19 self.setup_clean_chain = True
20 21 def run_test(self):
22 self._test_negative_time()
23 self._test_uptime()
24 25 def _test_negative_time(self):
26 assert_raises_rpc_error(-8, "Mocktime must be in the range [0, 9223372036], not -1.", self.nodes[0].setmocktime, -1)
27 28 def _test_uptime(self):
29 time.sleep(1) # Do some work before checking uptime
30 uptime_before = self.nodes[0].uptime()
31 assert uptime_before > 0, "uptime should begin at app start"
32 33 wait_time = 20_000
34 self.nodes[0].setmocktime(int(time.time()) + wait_time)
35 uptime_after = self.nodes[0].uptime()
36 self.nodes[0].setmocktime(0)
37 assert uptime_after - uptime_before < wait_time, "uptime should not jump with wall clock"
38 39 40 if __name__ == '__main__':
41 UptimeTest(__file__).main()
42