aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-07-23 18:39:18 +0200
committerMarcoFalke <falke.marco@gmail.com>2020-07-23 18:39:42 +0200
commitf4cfa6d01900aa4c4696d6e1eac65e1b42f6b762 (patch)
treea16f18697c196f93aecc89a1961f2f94a5b734e9 /test
parent6ee36a263c5a871b435b90203dadf861e528f30b (diff)
parent9c69cfe4c54e38edd2f54303be2f8a53dcf5bad8 (diff)
downloadbitcoin-f4cfa6d01900aa4c4696d6e1eac65e1b42f6b762.tar.xz
Merge #15935: Add <datadir>/settings.json persistent settings storage
9c69cfe4c54e38edd2f54303be2f8a53dcf5bad8 Add <datadir>/settings.json persistent settings storage. (Russell Yanofsky) eb682c5700e7a9176d0104d470b83ff9aa3589e8 util: Add ReadSettings and WriteSettings functions (Russell Yanofsky) Pull request description: Persistent settings are used in followup PRs #15936 to unify gui settings between bitcoin-qt and bitcoind, and #15937 to add a load_on_startup flag to the loadwallet RPC and maintain a dynamic list of wallets that should be loaded on startup that also can be shared between bitcoind and bitcoin-qt. ACKs for top commit: MarcoFalke: Approach re-ACK 9c69cfe4c54e38edd2f54303be2f8a53dcf5bad8 🌾 jnewbery: utACK 9c69cfe4c54e38edd2f54303be2f8a53dcf5bad8 Tree-SHA512: 39fcc6051717117c9141e934de1d0d3f739484be4685cdf97d54de967c8c816502b4fd0de12114433beaa5c5b7060c810fd8ae4e2b3ce7c371eb729ac01ba2e1
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/feature_settings.py84
-rwxr-xr-xtest/functional/test_runner.py1
2 files changed, 85 insertions, 0 deletions
diff --git a/test/functional/feature_settings.py b/test/functional/feature_settings.py
new file mode 100755
index 0000000000..c565854bb0
--- /dev/null
+++ b/test/functional/feature_settings.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+# Copyright (c) 2017-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.
+"""Test various command line arguments and configuration file parameters."""
+
+import json
+
+from pathlib import Path
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.test_node import ErrorMatch
+from test_framework.util import assert_equal
+
+
+class SettingsTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.setup_clean_chain = True
+ self.num_nodes = 1
+
+ def run_test(self):
+ node, = self.nodes
+ settings = Path(node.datadir, self.chain, "settings.json")
+ conf = Path(node.datadir, "bitcoin.conf")
+
+ # Assert empty settings file was created
+ self.stop_node(0)
+ with settings.open() as fp:
+ assert_equal(json.load(fp), {})
+
+ # Assert settings are parsed and logged
+ with settings.open("w") as fp:
+ json.dump({"string": "string", "num": 5, "bool": True, "null": None, "list": [6,7]}, fp)
+ with node.assert_debug_log(expected_msgs=[
+ 'Setting file arg: string = "string"',
+ 'Setting file arg: num = 5',
+ 'Setting file arg: bool = true',
+ 'Setting file arg: null = null',
+ 'Setting file arg: list = [6,7]']):
+ self.start_node(0)
+ self.stop_node(0)
+
+ # Assert settings are unchanged after shutdown
+ with settings.open() as fp:
+ assert_equal(json.load(fp), {"string": "string", "num": 5, "bool": True, "null": None, "list": [6,7]})
+
+ # Test invalid json
+ with settings.open("w") as fp:
+ fp.write("invalid json")
+ node.assert_start_raises_init_error(expected_msg='Unable to parse settings file', match=ErrorMatch.PARTIAL_REGEX)
+
+ # Test invalid json object
+ with settings.open("w") as fp:
+ fp.write('"string"')
+ node.assert_start_raises_init_error(expected_msg='Found non-object value "string" in settings file', match=ErrorMatch.PARTIAL_REGEX)
+
+ # Test invalid settings file containing duplicate keys
+ with settings.open("w") as fp:
+ fp.write('{"key": 1, "key": 2}')
+ node.assert_start_raises_init_error(expected_msg='Found duplicate key key in settings file', match=ErrorMatch.PARTIAL_REGEX)
+
+ # Test invalid settings file is ignored with command line -nosettings
+ with node.assert_debug_log(expected_msgs=['Command-line arg: settings=false']):
+ self.start_node(0, extra_args=["-nosettings"])
+ self.stop_node(0)
+
+ # Test invalid settings file is ignored with config file -nosettings
+ with conf.open('a') as conf:
+ conf.write('nosettings=1\n')
+ with node.assert_debug_log(expected_msgs=['Config file arg: [regtest] settings=false']):
+ self.start_node(0)
+ self.stop_node(0)
+
+ # Test alternate settings path
+ altsettings = Path(node.datadir, "altsettings.json")
+ with altsettings.open("w") as fp:
+ fp.write('{"key": "value"}')
+ with node.assert_debug_log(expected_msgs=['Setting file arg: key = "value"']):
+ self.start_node(0, extra_args=["-settings={}".format(altsettings)])
+ self.stop_node(0)
+
+
+if __name__ == '__main__':
+ SettingsTest().main()
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index 2a360bd38a..95c2b7c5ec 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -243,6 +243,7 @@ BASE_SCRIPTS = [
'p2p_permissions.py',
'feature_blocksdir.py',
'feature_config_args.py',
+ 'feature_settings.py',
'rpc_getdescriptorinfo.py',
'rpc_getpeerinfo_banscore_deprecation.py',
'rpc_help.py',