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// Copyright (c) 2018-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <bitcoin-build-config.h> // IWYU pragma: keep7#include <common/args.h>8#include <init.h>9#include <qt/bitcoin.h>10#include <qt/guiutil.h>11#include <qt/test/optiontests.h>12#include <test/util/setup_common.h>14#include <QSettings>15#include <QTest>17#include <univalue.h>19#include <fstream>21OptionTests::OptionTests(interfaces::Node& node) : m_node(node)22{23gArgs.LockSettings([&](common::Settings& s) { m_previous_settings = s; });24}26void OptionTests::init()27{28// reset args29gArgs.LockSettings([&](common::Settings& s) { s = m_previous_settings; });30gArgs.ClearPathCache();31}33void OptionTests::migrateSettings()34{35// Set legacy QSettings and verify that they get cleared and migrated to36// settings.json37QSettings settings;38settings.setValue("nDatabaseCache", 600);39settings.setValue("nThreadsScriptVerif", 12);40settings.setValue("fListen", false);41settings.setValue("bPrune", true);42settings.setValue("nPruneSize", 3);43settings.setValue("fUseProxy", true);44settings.setValue("addrProxy", "proxy:123");45settings.setValue("fUseSeparateProxyTor", true);46settings.setValue("addrSeparateProxyTor", "onion:234");48settings.sync();50QVERIFY(settings.contains("nDatabaseCache"));51QVERIFY(settings.contains("nThreadsScriptVerif"));52QVERIFY(settings.contains("fListen"));53QVERIFY(settings.contains("bPrune"));54QVERIFY(settings.contains("nPruneSize"));55QVERIFY(settings.contains("fUseProxy"));56QVERIFY(settings.contains("addrProxy"));57QVERIFY(settings.contains("fUseSeparateProxyTor"));58QVERIFY(settings.contains("addrSeparateProxyTor"));60OptionsModel options{m_node};61bilingual_str error;62QVERIFY(options.Init(error));63QVERIFY(!settings.contains("nDatabaseCache"));64QVERIFY(!settings.contains("nThreadsScriptVerif"));65QVERIFY(!settings.contains("fListen"));66QVERIFY(!settings.contains("bPrune"));67QVERIFY(!settings.contains("nPruneSize"));68QVERIFY(!settings.contains("fUseProxy"));69QVERIFY(!settings.contains("addrProxy"));70QVERIFY(!settings.contains("fUseSeparateProxyTor"));71QVERIFY(!settings.contains("addrSeparateProxyTor"));73std::ifstream file((gArgs.GetDataDirNet() / "settings.json").std_path());74std::string default_warning = strprintf("This file is automatically generated and updated by %s. Please do not edit this file while the node "75"is running, as any changes might be ignored or overwritten.",76CLIENT_NAME);77QCOMPARE(std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()).c_str(), "{\n"78" \"_warning_\": \""+ default_warning+"\",\n"79" \"dbcache\": \"600\",\n"80" \"listen\": false,\n"81" \"onion\": \"onion:234\",\n"82" \"par\": \"12\",\n"83" \"proxy\": \"proxy:123\",\n"84" \"prune\": \"2861\"\n"85"}\n");86}88void OptionTests::integerGetArgBug()89{90// Test regression https://github.com/bitcoin/bitcoin/issues/24457. Ensure91// that setting integer prune value doesn't cause an exception to be thrown92// in the OptionsModel constructor93gArgs.LockSettings([&](common::Settings& settings) {94settings.forced_settings.erase("prune");95settings.rw_settings["prune"] = 3814;96});97gArgs.WriteSettingsFile();98bilingual_str error;99QVERIFY(OptionsModel{m_node}.Init(error));100gArgs.LockSettings([&](common::Settings& settings) {101settings.rw_settings.erase("prune");102});103gArgs.WriteSettingsFile();104}106void OptionTests::parametersInteraction()107{108// Test that the bug https://github.com/bitcoin-core/gui/issues/567 does not resurface.109// It was fixed via https://github.com/bitcoin-core/gui/pull/568.110// With fListen=false in ~/.config/Bitcoin/Bitcoin-Qt.conf and all else left as default,111// bitcoin-qt should set both -listen and -listenonion to false and start successfully.112gArgs.LockSettings([&](common::Settings& s) {113s.forced_settings.erase("listen");114s.forced_settings.erase("listenonion");115});116QVERIFY(!gArgs.IsArgSet("-listen"));117QVERIFY(!gArgs.IsArgSet("-listenonion"));119QSettings settings;120settings.setValue("fListen", false);122bilingual_str error;123QVERIFY(OptionsModel{m_node}.Init(error));125const bool expected{false};127QVERIFY(gArgs.IsArgSet("-listen"));128QCOMPARE(gArgs.GetBoolArg("-listen", !expected), expected);130QVERIFY(gArgs.IsArgSet("-listenonion"));131QCOMPARE(gArgs.GetBoolArg("-listenonion", !expected), expected);133QVERIFY(AppInitParameterInteraction(gArgs));135// cleanup136settings.remove("fListen");137QVERIFY(!settings.contains("fListen"));138gArgs.ClearPathCache();139}141void OptionTests::extractFilter()142{143QString filter = QString("Partially Signed Transaction (Binary) (*.psbt)");144QCOMPARE(GUIUtil::ExtractFirstSuffixFromFilter(filter), "psbt");146filter = QString("Image (*.png *.jpg)");147QCOMPARE(GUIUtil::ExtractFirstSuffixFromFilter(filter), "png");148}
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.