rpc_getgeneralinfo.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2020-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 getgeneralinfo RPC."""
   6  
   7  import os.path
   8  import time
   9  
  10  from test_framework.test_framework import LimenkaTestFramework
  11  from test_framework.util import assert_equal
  12  
  13  class GetGeneralInfoTest(LimenkaTestFramework):
  14      def set_test_params(self):
  15          self.setup_clean_chain = False
  16          self.num_nodes = 1
  17          self.min_starttime = int(time.time())
  18  
  19      def run_test(self):
  20          """Test getgeneralinfo."""
  21          max_starttime = int(time.time()) + 1
  22  
  23          """Check if 'getgeneralinfo' is idempotent (multiple requests return same data)."""
  24          json1 = self.nodes[0].getgeneralinfo()
  25          json2 = self.nodes[0].getgeneralinfo()
  26          assert_equal(json1, json2)
  27  
  28          """Check 'getgeneralinfo' result is correct."""
  29          ver_search = f'version {json1["clientversion"]} ('
  30          with open(self.nodes[0].debug_log_path, encoding='utf-8') as dl:
  31              for line in dl:
  32                  if line.find(ver_search) >= 0:
  33                      break
  34              else:
  35                  raise AssertionError(f"Failed to find clientversion '{json1['clientversion']}' in debug log")
  36  
  37          assert_equal(json1['useragent'], self.nodes[0].getnetworkinfo()['subversion'])
  38  
  39          net_datadir = str(self.nodes[0].chain_path)
  40          assert_equal(json1['datadir'], net_datadir)
  41          assert_equal(json1['blocksdir'], os.path.join(net_datadir, "blocks"))
  42          # startuptime is set before mocktime param is loaded
  43          assert json1['startuptime'] >= self.min_starttime and json1['startuptime'] <= max_starttime
  44  
  45  if __name__ == '__main__':
  46      GetGeneralInfoTest(__file__).main()
  47