feature_help.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2018-present 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  """Verify that starting bitcoin with -h works as expected."""
   6  
   7  from test_framework.test_framework import BitcoinTestFramework
   8  from test_framework.util import assert_equal
   9  
  10  class HelpTest(BitcoinTestFramework):
  11      def set_test_params(self):
  12          self.setup_clean_chain = True
  13          self.num_nodes = 1
  14  
  15      def setup_network(self):
  16          self.add_nodes(self.num_nodes)
  17          # Don't start the node
  18  
  19      def get_node_output(self, *, ret_code_expected):
  20          ret_code = self.nodes[0].process.wait(timeout=60)
  21          assert_equal(ret_code, ret_code_expected)
  22          self.nodes[0].stdout.seek(0)
  23          self.nodes[0].stderr.seek(0)
  24          out = self.nodes[0].stdout.read()
  25          err = self.nodes[0].stderr.read()
  26          self.nodes[0].stdout.close()
  27          self.nodes[0].stderr.close()
  28  
  29          # Clean up TestNode state
  30          self.nodes[0].running = False
  31          self.nodes[0].process = None
  32          self.nodes[0].rpc_connected = False
  33          self.nodes[0].rpc = None
  34  
  35          return out, err
  36  
  37      def run_test(self):
  38          self.log.info("Start bitcoin with -h for help text")
  39          self.nodes[0].start(extra_args=['-h'])
  40          # Node should exit immediately and output help to stdout.
  41          output, _ = self.get_node_output(ret_code_expected=0)
  42          assert b'Options' in output
  43          self.log.info(f"Help text received: {output[0:60]} (...)")
  44  
  45          self.log.info("Start bitcoin with -version for version information")
  46          self.nodes[0].start(extra_args=['-version'])
  47          # Node should exit immediately and output version to stdout.
  48          output, _ = self.get_node_output(ret_code_expected=0)
  49          assert b'version' in output
  50          self.log.info(f"Version text received: {output[0:60]} (...)")
  51  
  52          # Test that arguments not in the help results in an error
  53          self.log.info("Start bitcoind with -fakearg to make sure it does not start")
  54          self.nodes[0].start(extra_args=['-fakearg'])
  55          # Node should exit immediately and output an error to stderr
  56          _, output = self.get_node_output(ret_code_expected=1)
  57          assert b'Error parsing command line arguments' in output
  58          self.log.info(f"Error message received: {output[0:60]} (...)")
  59  
  60  
  61  if __name__ == '__main__':
  62      HelpTest(__file__).main()
  63