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) 2017-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"""Test various command line arguments and configuration file parameters."""7import json10from test_framework.test_framework import BitcoinTestFramework11from test_framework.test_node import ErrorMatch12from test_framework.util import assert_equal15class SettingsTest(BitcoinTestFramework):16def set_test_params(self):17self.setup_clean_chain = True18self.num_nodes = 119self.wallet_names = []20self.uses_wallet = None22def test_wallet_settings(self, settings_path):23if not self.is_wallet_compiled():24return26self.log.info("Testing wallet settings..")27node = self.nodes[0]28# Create wallet to use it during tests29self.start_node(0)30node.createwallet(wallet_name='w1')31self.stop_node(0)33# Verify wallet settings can only be strings. Either names or paths. Not booleans, nums nor anything else.34for wallets_data in [[10], [True], [[]], [{}], ["w1", 10], ["w1", False]]:35with settings_path.open("w") as fp:36json.dump({"wallet": wallets_data}, fp)37node.assert_start_raises_init_error(expected_msg="Error: Invalid value detected for '-wallet' or '-nowallet'. '-wallet' requires a string value, while '-nowallet' accepts only '1' to disable all wallets",38extra_args=[f'-settings={settings_path}'])40def run_test(self):41node, = self.nodes42settings = node.chain_path / "settings.json"43conf = node.datadir_path / "bitcoin.conf"45# Assert default settings file was created46self.stop_node(0)47default_settings = {"_warning_": f"This file is automatically generated and updated by {self.config['environment']['CLIENT_NAME']}. Please do not edit this file while the node is running, as any changes might be ignored or overwritten."}48with settings.open() as fp:49assert_equal(json.load(fp), default_settings)51# Assert settings are parsed and logged52with settings.open("w") as fp:53json.dump({"string": "string", "num": 5, "bool": True, "null": None, "list": [6, 7]}, fp)54with node.assert_debug_log(expected_msgs=[55'Ignoring unknown rw_settings value bool',56'Ignoring unknown rw_settings value list',57'Ignoring unknown rw_settings value null',58'Ignoring unknown rw_settings value num',59'Ignoring unknown rw_settings value string',60'Setting file arg: string = "string"',61'Setting file arg: num = 5',62'Setting file arg: bool = true',63'Setting file arg: null = null',64'Setting file arg: list = [6,7]',65]):66self.start_node(0)67self.stop_node(0)69# Assert settings are unchanged after shutdown70with settings.open() as fp:71assert_equal(json.load(fp), {**default_settings, **{"string": "string", "num": 5, "bool": True, "null": None, "list": [6, 7]}})73# Test invalid json74with settings.open("w") as fp:75fp.write("invalid json")76node.assert_start_raises_init_error(expected_msg='does not contain valid JSON. This may be caused by a crash, power loss, full disk, or storage error', match=ErrorMatch.PARTIAL_REGEX)78# Test invalid json object79with settings.open("w") as fp:80fp.write('"string"')81node.assert_start_raises_init_error(expected_msg='Found non-object value "string" in settings file', match=ErrorMatch.PARTIAL_REGEX)83# Test invalid settings file containing duplicate keys84with settings.open("w") as fp:85fp.write('{"key": 1, "key": 2}')86node.assert_start_raises_init_error(expected_msg='Found duplicate key key in settings file', match=ErrorMatch.PARTIAL_REGEX)88# Test invalid settings file is ignored with command line -nosettings89with node.assert_debug_log(expected_msgs=['Command-line arg: settings=false']):90self.start_node(0, extra_args=["-nosettings"])91self.stop_node(0)93# Test invalid settings file is ignored with config file -nosettings94with conf.open('a') as conf:95conf.write('nosettings=1\n')96with node.assert_debug_log(expected_msgs=['Config file arg: [regtest] settings=false']):97self.start_node(0)98self.stop_node(0)100# Test alternate settings path101altsettings = node.datadir_path / "altsettings.json"102with altsettings.open("w") as fp:103fp.write('{"key": "value"}')104with node.assert_debug_log(expected_msgs=['Setting file arg: key = "value"']):105self.start_node(0, extra_args=[f"-settings={altsettings}"])106self.stop_node(0)108self.test_wallet_settings(settings)111if __name__ == '__main__':112SettingsTest(__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.