Skip to content

Commit 0f0badd

Browse files
committed
test: Test includeconf parameter.
1 parent 629ff8c commit 0f0badd

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 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+
"""Tests the includeconf argument
6+
7+
Verify that:
8+
9+
1. adding includeconf to the configuration file causes the includeconf
10+
file to be loaded in the correct order.
11+
2. includeconf cannot be used as a command line argument.
12+
3. includeconf cannot be used recursively (ie includeconf can only
13+
be used from the base config file).
14+
4. multiple includeconf arguments can be specified in the main config
15+
file.
16+
"""
17+
import os
18+
import tempfile
19+
20+
from test_framework.test_framework import BitcoinTestFramework, assert_equal
21+
22+
class IncludeConfTest(BitcoinTestFramework):
23+
def set_test_params(self):
24+
self.setup_clean_chain = False
25+
self.num_nodes = 1
26+
27+
def setup_chain(self):
28+
super().setup_chain()
29+
# Create additional config files
30+
# - tmpdir/node0/relative.conf
31+
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f:
32+
f.write("uacomment=relative\n")
33+
# - tmpdir/node0/relative2.conf
34+
with open(os.path.join(self.options.tmpdir, "node0", "relative2.conf"), "w", encoding="utf8") as f:
35+
f.write("uacomment=relative2\n")
36+
with open(os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), "a", encoding='utf8') as f:
37+
f.write("uacomment=main\nincludeconf=relative.conf\n")
38+
39+
def run_test(self):
40+
self.log.info("-includeconf works from config file. subversion should end with 'main; relative)/'")
41+
42+
subversion = self.nodes[0].getnetworkinfo()["subversion"]
43+
assert subversion.endswith("main; relative)/")
44+
45+
self.log.info("-includeconf cannot be used as command-line arg. subversion should still end with 'main; relative)/'")
46+
self.stop_node(0)
47+
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
48+
self.start_node(0, extra_args=["-includeconf=relative2.conf"], stderr=log_stderr)
49+
50+
subversion = self.nodes[0].getnetworkinfo()["subversion"]
51+
assert subversion.endswith("main; relative)/")
52+
log_stderr.seek(0)
53+
stderr = log_stderr.read().decode('utf-8').strip()
54+
assert_equal(stderr, 'warning: -includeconf cannot be used from commandline; ignoring -includeconf=relative2.conf')
55+
56+
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
57+
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:
58+
f.write("includeconf=relative2.conf\n")
59+
60+
self.restart_node(0)
61+
62+
subversion = self.nodes[0].getnetworkinfo()["subversion"]
63+
assert subversion.endswith("main; relative)/")
64+
65+
self.log.info("multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'")
66+
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f:
67+
f.write("uacomment=relative\n")
68+
69+
with open(os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), "a", encoding='utf8') as f:
70+
f.write("includeconf=relative2.conf\n")
71+
72+
self.restart_node(0)
73+
74+
subversion = self.nodes[0].getnetworkinfo()["subversion"]
75+
assert subversion.endswith("main; relative; relative2)/")
76+
77+
if __name__ == '__main__':
78+
IncludeConfTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
'p2p_fingerprint.py',
139139
'feature_uacomment.py',
140140
'p2p_unrequested_blocks.py',
141+
'feature_includeconf.py',
141142
'feature_logging.py',
142143
'p2p_node_network_limited.py',
143144
'feature_blocksdir.py',

0 commit comments

Comments
 (0)