forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathfeature_help.py
More file actions
executable file
·80 lines (65 loc) · 3.26 KB
/
Copy pathfeature_help.py
File metadata and controls
executable file
·80 lines (65 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
# Copyright (c) 2018-2020 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 dashd with -h works as expected."""
from pathlib import Path
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
def get_node_output(self, *, ret_code_expected):
ret_code = self.nodes[0].process.wait(timeout=60)
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
def run_test(self):
self.log.info("Start dashd with -h for help text")
self.nodes[0].start(extra_args=['-h'])
# Node should exit immediately and output help to stdout.
output, _ = self.get_node_output(ret_code_expected=0)
assert b'Options' in output
self.log.info(f"Help text received: {output[0:60]} (...)")
self.log.info("Start dashd with -version for version information")
self.nodes[0].start(extra_args=['-version'])
# Node should exit immediately and output version to stdout.
output, _ = self.get_node_output(ret_code_expected=0)
assert b'version' in output
self.log.info(f"Version text received: {output[0:60]} (...)")
missing_datadir = Path(self.options.tmpdir) / "missing_crashinfo_datadir"
assert not missing_datadir.exists()
self.log.info("Start dashd with -printcrashinfo and a nonexistent datadir")
self.nodes[0].start(extra_args=["-printcrashinfo=invalid", f"-datadir={missing_datadir}"])
output, error = self.get_node_output(ret_code_expected=0)
assert b'Error while deserializing crash info' in output
assert_equal(error, b'')
assert not missing_datadir.exists()
self.log.info("Start dashd with a nonexistent datadir and no -printcrashinfo")
self.nodes[0].start(extra_args=[f"-datadir={missing_datadir}"])
_, error = self.get_node_output(ret_code_expected=1)
assert b'Specified data directory' in error
assert not missing_datadir.exists()
# Test that arguments not in the help results in an error
self.log.info("Start dashdd with -fakearg to make sure it does not start")
self.nodes[0].start(extra_args=['-fakearg'])
# Node should exit immediately and output an error to stderr
_, output = self.get_node_output(ret_code_expected=1)
assert b'Error parsing command line arguments' in output
self.log.info(f"Error message received: {output[0:60]} (...)")
if __name__ == '__main__':
HelpTest().main()