3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Verify that starting bitcoin with -h works as expected."""
6
- import subprocess
7
6
8
7
from test_framework .test_framework import BitcoinTestFramework
9
8
from test_framework .util import assert_equal
@@ -17,41 +16,47 @@ def setup_network(self):
17
16
self .add_nodes (self .num_nodes )
18
17
# Don't start the node
19
18
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
+
20
37
def run_test (self ):
21
38
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' ])
23
40
# 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 )
27
42
assert b'Options' in output
28
43
self .log .info ("Help text received: {} (...)" .format (output [0 :60 ]))
29
- self .nodes [0 ].running = False
30
44
31
45
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' ])
33
47
# 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 )
37
49
assert b'version' in output
38
50
self .log .info ("Version text received: {} (...)" .format (output [0 :60 ]))
39
51
40
52
# Test that arguments not in the help results in an error
41
53
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' ])
43
55
# 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 )
47
57
assert b'Error parsing command line arguments' in output
48
58
self .log .info ("Error message received: {} (...)" .format (output [0 :60 ]))
49
59
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
55
60
56
61
if __name__ == '__main__' :
57
62
HelpTest ().main ()
0 commit comments