Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2018-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Tests the includeconf argument7Verify that:91. adding includeconf to the configuration file causes the includeconf10file to be loaded in the correct order.112. includeconf cannot be used as a command line argument.123. includeconf cannot be used recursively (ie includeconf can only13be used from the base config file).144. multiple includeconf arguments can be specified in the main config15file.16"""17from test_framework.test_framework import BitcoinTestFramework20class IncludeConfTest(BitcoinTestFramework):21def set_test_params(self):22self.num_nodes = 124def run_test(self):25# Create additional config files26# - tmpdir/node0/relative.conf27with open(self.nodes[0].datadir_path / "relative.conf", "w") as f:28f.write("uacomment=relative\n")29# - tmpdir/node0/relative2.conf30with open(self.nodes[0].datadir_path / "relative2.conf", "w") as f:31f.write("uacomment=relative2\n")32with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:33f.write("uacomment=main\nincludeconf=relative.conf\n")34self.restart_node(0)36self.log.info("-includeconf works from config file. subversion should end with 'main; relative)/'")38subversion = self.nodes[0].getnetworkinfo()["subversion"]39assert subversion.endswith("main; relative)/")41self.log.info("-includeconf cannot be used as command-line arg")42self.stop_node(0)43self.nodes[0].assert_start_raises_init_error(44extra_args=['-noincludeconf=0'],45expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=true',46)47self.nodes[0].assert_start_raises_init_error(48extra_args=['-includeconf=relative2.conf', '-includeconf=no_warn.conf'],49expected_msg='Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf="relative2.conf"',50)52self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")53with open(self.nodes[0].datadir_path / "relative.conf", "a") as f:54f.write("includeconf=relative2.conf\n")55self.start_node(0)57subversion = self.nodes[0].getnetworkinfo()["subversion"]58assert subversion.endswith("main; relative)/")59self.stop_node(0, expected_stderr="warning: -includeconf cannot be used from included files; ignoring -includeconf=relative2.conf")61self.log.info("-includeconf cannot contain invalid arg")63# Commented out as long as we ignore invalid arguments in configuration files64#with open(self.nodes[0].datadir_path / "relative.conf", "w") as f:65# f.write("foo=bar\n")66#self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Invalid configuration value foo")68self.log.info("-includeconf cannot be invalid path")69(self.nodes[0].datadir_path / "relative.conf").unlink()70self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Failed to include configuration file relative.conf")72self.log.info("multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'")73with open(self.nodes[0].datadir_path / "relative.conf", "w") as f:74# Restore initial file contents75f.write("uacomment=relative\n")77with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:78f.write("includeconf=relative2.conf\n")80self.start_node(0)82subversion = self.nodes[0].getnetworkinfo()["subversion"]83assert subversion.endswith("main; relative; relative2)/")85if __name__ == '__main__':86IncludeConfTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.