2018-03-30 17:36:38 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2018 The Bitcoin Core developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
"""Verify that starting bitcoin with -h works as expected."""
|
|
|
|
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
from test_framework.util import assert_equal
|
|
|
|
|
|
|
|
class HelpTest(BitcoinTestFramework):
|
|
|
|
def set_test_params(self):
|
|
|
|
self.setup_clean_chain = True
|
|
|
|
self.num_nodes = 1
|
|
|
|
|
|
|
|
def setup_network(self):
|
|
|
|
self.add_nodes(self.num_nodes)
|
|
|
|
# Don't start the node
|
|
|
|
|
2018-08-03 23:23:33 +02:00
|
|
|
def get_node_output(self, *, ret_code_expected):
|
2018-08-03 23:50:33 +02:00
|
|
|
ret_code = self.nodes[0].process.wait(timeout=5)
|
2018-08-03 23:23:33 +02:00
|
|
|
assert_equal(ret_code, ret_code_expected)
|
|
|
|
self.nodes[0].stdout.seek(0)
|
|
|
|
self.nodes[0].stderr.seek(0)
|
|
|
|
out = self.nodes[0].stdout.read()
|
|
|
|
err = self.nodes[0].stderr.read()
|
|
|
|
self.nodes[0].stdout.close()
|
|
|
|
self.nodes[0].stderr.close()
|
|
|
|
|
|
|
|
# Clean up TestNode state
|
|
|
|
self.nodes[0].running = False
|
|
|
|
self.nodes[0].process = None
|
|
|
|
self.nodes[0].rpc_connected = False
|
|
|
|
self.nodes[0].rpc = None
|
|
|
|
|
|
|
|
return out, err
|
|
|
|
|
2018-03-30 17:36:38 +02:00
|
|
|
def run_test(self):
|
|
|
|
self.log.info("Start bitcoin with -h for help text")
|
2018-08-03 23:23:33 +02:00
|
|
|
self.nodes[0].start(extra_args=['-h'])
|
2018-03-30 17:36:38 +02:00
|
|
|
# Node should exit immediately and output help to stdout.
|
2018-08-03 23:23:33 +02:00
|
|
|
output, _ = self.get_node_output(ret_code_expected=0)
|
2018-03-30 17:36:38 +02:00
|
|
|
assert b'Options' in output
|
|
|
|
self.log.info("Help text received: {} (...)".format(output[0:60]))
|
|
|
|
|
|
|
|
self.log.info("Start bitcoin with -version for version information")
|
2018-08-03 23:23:33 +02:00
|
|
|
self.nodes[0].start(extra_args=['-version'])
|
2018-03-30 17:36:38 +02:00
|
|
|
# Node should exit immediately and output version to stdout.
|
2018-08-03 23:23:33 +02:00
|
|
|
output, _ = self.get_node_output(ret_code_expected=0)
|
2018-03-30 17:36:38 +02:00
|
|
|
assert b'version' in output
|
|
|
|
self.log.info("Version text received: {} (...)".format(output[0:60]))
|
2018-04-29 05:13:56 +02:00
|
|
|
|
|
|
|
# Test that arguments not in the help results in an error
|
|
|
|
self.log.info("Start bitcoind with -fakearg to make sure it does not start")
|
2018-08-03 23:23:33 +02:00
|
|
|
self.nodes[0].start(extra_args=['-fakearg'])
|
2018-04-29 05:13:56 +02:00
|
|
|
# Node should exit immediately and output an error to stderr
|
2018-08-03 23:23:33 +02:00
|
|
|
_, output = self.get_node_output(ret_code_expected=1)
|
2018-04-29 05:13:56 +02:00
|
|
|
assert b'Error parsing command line arguments' in output
|
|
|
|
self.log.info("Error message received: {} (...)".format(output[0:60]))
|
|
|
|
|
2018-03-30 17:36:38 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
HelpTest().main()
|