33# Distributed under the MIT software license, see the accompanying
44# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55"""Verify that starting bitcoin with -h works as expected."""
6- import subprocess
76
87from test_framework .test_framework import BitcoinTestFramework
98from test_framework .util import assert_equal
@@ -17,41 +16,47 @@ def setup_network(self):
1716 self .add_nodes (self .num_nodes )
1817 # Don't start the node
1918
19+ def get_node_output (self , * , ret_code_expected ):
20+ ret_code = self .nodes [0 ].process .wait (timeout = 1 )
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+
2037 def run_test (self ):
2138 self .log .info ("Start bitcoin with -h for help text" )
22- self .nodes [0 ].start (extra_args = ['-h' ], stderr = subprocess . PIPE , stdout = subprocess . PIPE )
39+ self .nodes [0 ].start (extra_args = ['-h' ])
2340 # Node should exit immediately and output help to stdout.
24- ret_code = self .nodes [0 ].process .wait (timeout = 1 )
25- assert_equal (ret_code , 0 )
26- output = self .nodes [0 ].process .stdout .read ()
41+ output , _ = self .get_node_output (ret_code_expected = 0 )
2742 assert b'Options' in output
2843 self .log .info ("Help text received: {} (...)" .format (output [0 :60 ]))
29- self .nodes [0 ].running = False
3044
3145 self .log .info ("Start bitcoin with -version for version information" )
32- self .nodes [0 ].start (extra_args = ['-version' ], stderr = subprocess . PIPE , stdout = subprocess . PIPE )
46+ self .nodes [0 ].start (extra_args = ['-version' ])
3347 # Node should exit immediately and output version to stdout.
34- ret_code = self .nodes [0 ].process .wait (timeout = 1 )
35- assert_equal (ret_code , 0 )
36- output = self .nodes [0 ].process .stdout .read ()
48+ output , _ = self .get_node_output (ret_code_expected = 0 )
3749 assert b'version' in output
3850 self .log .info ("Version text received: {} (...)" .format (output [0 :60 ]))
3951
4052 # Test that arguments not in the help results in an error
4153 self .log .info ("Start bitcoind with -fakearg to make sure it does not start" )
42- self .nodes [0 ].start (extra_args = ['-fakearg' ], stderr = subprocess . PIPE , stdout = subprocess . PIPE )
54+ self .nodes [0 ].start (extra_args = ['-fakearg' ])
4355 # Node should exit immediately and output an error to stderr
44- ret_code = self .nodes [0 ].process .wait (timeout = 1 )
45- assert_equal (ret_code , 1 )
46- output = self .nodes [0 ].process .stderr .read ()
56+ _ , output = self .get_node_output (ret_code_expected = 1 )
4757 assert b'Error parsing command line arguments' in output
4858 self .log .info ("Error message received: {} (...)" .format (output [0 :60 ]))
4959
50- # Clean up TestNode state
51- self .nodes [0 ].running = False
52- self .nodes [0 ].process = None
53- self .nodes [0 ].rpc_connected = False
54- self .nodes [0 ].rpc = None
5560
5661if __name__ == '__main__' :
5762 HelpTest ().main ()
0 commit comments