test: Add tests for GetArg methods / settings.json type coercion
Just add tests. No changes to application behavior. Tests will be
updated in the next commit changing & improving current behavior.
Include a Qt test for GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 caused by GetArg
behavior that happens if settings.json contains an integer value for any
of the configuration options which GUI settings can currently clash with
(-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen,
-server, -proxy, -proxy, -onion, -onion, -lang, and -prune).
2022-03-07 13:29:46 -05:00
|
|
|
// Copyright (c) 2018 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2022-03-24 18:33:14 +01:00
|
|
|
#include <init.h>
|
test: Add tests for GetArg methods / settings.json type coercion
Just add tests. No changes to application behavior. Tests will be
updated in the next commit changing & improving current behavior.
Include a Qt test for GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 caused by GetArg
behavior that happens if settings.json contains an integer value for any
of the configuration options which GUI settings can currently clash with
(-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen,
-server, -proxy, -proxy, -onion, -onion, -lang, and -prune).
2022-03-07 13:29:46 -05:00
|
|
|
#include <qt/bitcoin.h>
|
2022-06-21 19:15:06 -03:00
|
|
|
#include <qt/guiutil.h>
|
test: Add tests for GetArg methods / settings.json type coercion
Just add tests. No changes to application behavior. Tests will be
updated in the next commit changing & improving current behavior.
Include a Qt test for GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 caused by GetArg
behavior that happens if settings.json contains an integer value for any
of the configuration options which GUI settings can currently clash with
(-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen,
-server, -proxy, -proxy, -onion, -onion, -lang, and -prune).
2022-03-07 13:29:46 -05:00
|
|
|
#include <qt/test/optiontests.h>
|
|
|
|
#include <test/util/setup_common.h>
|
|
|
|
#include <util/system.h>
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QTest>
|
|
|
|
|
|
|
|
#include <univalue.h>
|
|
|
|
|
2019-04-29 15:29:00 -04:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
OptionTests::OptionTests(interfaces::Node& node) : m_node(node)
|
|
|
|
{
|
|
|
|
gArgs.LockSettings([&](util::Settings& s) { m_previous_settings = s; });
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionTests::init()
|
|
|
|
{
|
|
|
|
// reset args
|
|
|
|
gArgs.LockSettings([&](util::Settings& s) { s = m_previous_settings; });
|
|
|
|
gArgs.ClearPathCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionTests::migrateSettings()
|
|
|
|
{
|
|
|
|
// Set legacy QSettings and verify that they get cleared and migrated to
|
|
|
|
// settings.json
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue("nDatabaseCache", 600);
|
2019-04-29 15:29:00 -04:00
|
|
|
settings.setValue("nThreadsScriptVerif", 12);
|
2022-04-18 19:19:02 -04:00
|
|
|
settings.setValue("fUseUPnP", false);
|
2019-04-29 15:29:00 -04:00
|
|
|
settings.setValue("fListen", false);
|
2019-04-29 15:29:00 -04:00
|
|
|
settings.setValue("bPrune", true);
|
|
|
|
settings.setValue("nPruneSize", 3);
|
2019-04-29 15:29:00 -04:00
|
|
|
settings.setValue("fUseProxy", true);
|
|
|
|
settings.setValue("addrProxy", "proxy:123");
|
|
|
|
settings.setValue("fUseSeparateProxyTor", true);
|
|
|
|
settings.setValue("addrSeparateProxyTor", "onion:234");
|
2019-04-29 15:29:00 -04:00
|
|
|
|
|
|
|
settings.sync();
|
|
|
|
|
|
|
|
OptionsModel options{m_node};
|
|
|
|
bilingual_str error;
|
|
|
|
QVERIFY(options.Init(error));
|
|
|
|
QVERIFY(!settings.contains("nDatabaseCache"));
|
2019-04-29 15:29:00 -04:00
|
|
|
QVERIFY(!settings.contains("nThreadsScriptVerif"));
|
2022-04-18 19:19:02 -04:00
|
|
|
QVERIFY(!settings.contains("fUseUPnP"));
|
2019-04-29 15:29:00 -04:00
|
|
|
QVERIFY(!settings.contains("fListen"));
|
2019-04-29 15:29:00 -04:00
|
|
|
QVERIFY(!settings.contains("bPrune"));
|
|
|
|
QVERIFY(!settings.contains("nPruneSize"));
|
2019-04-29 15:29:00 -04:00
|
|
|
QVERIFY(!settings.contains("fUseProxy"));
|
|
|
|
QVERIFY(!settings.contains("addrProxy"));
|
|
|
|
QVERIFY(!settings.contains("fUseSeparateProxyTor"));
|
|
|
|
QVERIFY(!settings.contains("addrSeparateProxyTor"));
|
2019-04-29 15:29:00 -04:00
|
|
|
|
|
|
|
std::ifstream file(gArgs.GetDataDirNet() / "settings.json");
|
|
|
|
QCOMPARE(std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()).c_str(), "{\n"
|
2019-04-29 15:29:00 -04:00
|
|
|
" \"dbcache\": \"600\",\n"
|
2019-04-29 15:29:00 -04:00
|
|
|
" \"listen\": false,\n"
|
2019-04-29 15:29:00 -04:00
|
|
|
" \"onion\": \"onion:234\",\n"
|
|
|
|
" \"par\": \"12\",\n"
|
2019-04-29 15:29:00 -04:00
|
|
|
" \"proxy\": \"proxy:123\",\n"
|
|
|
|
" \"prune\": \"2861\"\n"
|
2019-04-29 15:29:00 -04:00
|
|
|
"}\n");
|
|
|
|
}
|
|
|
|
|
2019-04-29 15:29:00 -04:00
|
|
|
void OptionTests::integerGetArgBug()
|
test: Add tests for GetArg methods / settings.json type coercion
Just add tests. No changes to application behavior. Tests will be
updated in the next commit changing & improving current behavior.
Include a Qt test for GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 caused by GetArg
behavior that happens if settings.json contains an integer value for any
of the configuration options which GUI settings can currently clash with
(-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen,
-server, -proxy, -proxy, -onion, -onion, -lang, and -prune).
2022-03-07 13:29:46 -05:00
|
|
|
{
|
qt: Avoid crash on startup if int specified in settings.json
Fix GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 that happens if
settings.json contains an integer value for any of the configuration
options which GUI settings can currently clash with (-dbcache, -par,
-spendzeroconfchange, -signer, -upnp, -natpmp, -listen, -server, -proxy,
-proxy, -onion, -onion, -lang, and -prune).
Fix is a one-line change in ArgsManager::GetArg.
2022-03-07 13:29:46 -05:00
|
|
|
// Test regression https://github.com/bitcoin/bitcoin/issues/24457. Ensure
|
|
|
|
// that setting integer prune value doesn't cause an exception to be thrown
|
|
|
|
// in the OptionsModel constructor
|
test: Add tests for GetArg methods / settings.json type coercion
Just add tests. No changes to application behavior. Tests will be
updated in the next commit changing & improving current behavior.
Include a Qt test for GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 caused by GetArg
behavior that happens if settings.json contains an integer value for any
of the configuration options which GUI settings can currently clash with
(-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen,
-server, -proxy, -proxy, -onion, -onion, -lang, and -prune).
2022-03-07 13:29:46 -05:00
|
|
|
gArgs.LockSettings([&](util::Settings& settings) {
|
|
|
|
settings.forced_settings.erase("prune");
|
|
|
|
settings.rw_settings["prune"] = 3814;
|
|
|
|
});
|
|
|
|
gArgs.WriteSettingsFile();
|
2019-04-29 15:29:00 -04:00
|
|
|
bilingual_str error;
|
|
|
|
QVERIFY(OptionsModel{m_node}.Init(error));
|
test: Add tests for GetArg methods / settings.json type coercion
Just add tests. No changes to application behavior. Tests will be
updated in the next commit changing & improving current behavior.
Include a Qt test for GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 caused by GetArg
behavior that happens if settings.json contains an integer value for any
of the configuration options which GUI settings can currently clash with
(-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen,
-server, -proxy, -proxy, -onion, -onion, -lang, and -prune).
2022-03-07 13:29:46 -05:00
|
|
|
gArgs.LockSettings([&](util::Settings& settings) {
|
|
|
|
settings.rw_settings.erase("prune");
|
|
|
|
});
|
|
|
|
gArgs.WriteSettingsFile();
|
|
|
|
}
|
2022-03-24 18:33:14 +01:00
|
|
|
|
|
|
|
void OptionTests::parametersInteraction()
|
|
|
|
{
|
|
|
|
// Test that the bug https://github.com/bitcoin-core/gui/issues/567 does not resurface.
|
|
|
|
// It was fixed via https://github.com/bitcoin-core/gui/pull/568.
|
|
|
|
// With fListen=false in ~/.config/Bitcoin/Bitcoin-Qt.conf and all else left as default,
|
|
|
|
// bitcoin-qt should set both -listen and -listenonion to false and start successfully.
|
|
|
|
gArgs.LockSettings([&](util::Settings& s) {
|
|
|
|
s.forced_settings.erase("listen");
|
|
|
|
s.forced_settings.erase("listenonion");
|
|
|
|
});
|
|
|
|
QVERIFY(!gArgs.IsArgSet("-listen"));
|
|
|
|
QVERIFY(!gArgs.IsArgSet("-listenonion"));
|
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue("fListen", false);
|
|
|
|
|
2019-04-29 15:29:00 -04:00
|
|
|
bilingual_str error;
|
|
|
|
QVERIFY(OptionsModel{m_node}.Init(error));
|
2022-03-24 18:33:14 +01:00
|
|
|
|
|
|
|
const bool expected{false};
|
|
|
|
|
|
|
|
QVERIFY(gArgs.IsArgSet("-listen"));
|
|
|
|
QCOMPARE(gArgs.GetBoolArg("-listen", !expected), expected);
|
|
|
|
|
|
|
|
QVERIFY(gArgs.IsArgSet("-listenonion"));
|
|
|
|
QCOMPARE(gArgs.GetBoolArg("-listenonion", !expected), expected);
|
|
|
|
|
|
|
|
QVERIFY(AppInitParameterInteraction(gArgs));
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
settings.remove("fListen");
|
|
|
|
QVERIFY(!settings.contains("fListen"));
|
|
|
|
gArgs.ClearPathCache();
|
|
|
|
}
|
2022-06-21 19:15:06 -03:00
|
|
|
|
|
|
|
void OptionTests::extractFilter()
|
|
|
|
{
|
|
|
|
QString filter = QString("Partially Signed Transaction (Binary) (*.psbt)");
|
|
|
|
QCOMPARE(GUIUtil::ExtractFirstSuffixFromFilter(filter), "psbt");
|
|
|
|
|
|
|
|
filter = QString("Image (*.png *.jpg)");
|
|
|
|
QCOMPARE(GUIUtil::ExtractFirstSuffixFromFilter(filter), "png");
|
|
|
|
}
|