/ test / functional / rpc_uptime.py
rpc_uptime.py
 1  #!/usr/bin/env python3
 2  # Copyright (c) 2017-2022 The Bitcoin Core 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 BitcoinTestFramework
13  from test_framework.util import assert_raises_rpc_error
14  
15  
16  class UptimeTest(BitcoinTestFramework):
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          wait_time = 10
30          self.nodes[0].setmocktime(int(time.time() + wait_time))
31          assert self.nodes[0].uptime() >= wait_time
32  
33  
34  if __name__ == '__main__':
35      UptimeTest(__file__).main()