Skip to content

Commit ff2566f

Browse files
committed
merge bitcoin-core/gui#569: add regression test for bitcoin-core/gui#567
1 parent b56c1d5 commit ff2566f

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/qt/optionsmodel.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,26 @@ void OptionsModel::Init(bool resetSettings)
262262

263263
if (!settings.contains("fListen"))
264264
settings.setValue("fListen", DEFAULT_LISTEN);
265-
if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool())) {
265+
const bool listen{settings.value("fListen").toBool()};
266+
if (!gArgs.SoftSetBoolArg("-listen", listen)) {
266267
addOverriddenOption("-listen");
267-
} else if (!settings.value("fListen").toBool()) {
268+
} else if (!listen) {
269+
// We successfully set -listen=0, thus mimic the logic from InitParameterInteraction():
270+
// "parameter interaction: -listen=0 -> setting -listenonion=0".
271+
//
272+
// Both -listen and -listenonion default to true.
273+
//
274+
// The call order is:
275+
//
276+
// InitParameterInteraction()
277+
// would set -listenonion=0 if it sees -listen=0, but for bitcoin-qt with
278+
// fListen=false -listen is 1 at this point
279+
//
280+
// OptionsModel::Init()
281+
// (this method) can flip -listen from 1 to 0 if fListen=false
282+
//
283+
// AppInitParameterInteraction()
284+
// raises an error if -listen=0 and -listenonion=1
268285
gArgs.SoftSetBoolArg("-listenonion", false);
269286
}
270287

src/qt/test/optiontests.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <init.h>
56
#include <qt/bitcoin.h>
67
#include <qt/test/optiontests.h>
78
#include <test/util/setup_common.h>
@@ -29,3 +30,39 @@ void OptionTests::optionTests()
2930
});
3031
gArgs.WriteSettingsFile();
3132
}
33+
34+
void OptionTests::parametersInteraction()
35+
{
36+
// Test that the bug https://github.com/bitcoin-core/gui/issues/567 does not resurface.
37+
// It was fixed via https://github.com/bitcoin-core/gui/pull/568.
38+
// With fListen=false in ~/.config/Bitcoin/Bitcoin-Qt.conf and all else left as default,
39+
// bitcoin-qt should set both -listen and -listenonion to false and start successfully.
40+
gArgs.ClearPathCache();
41+
42+
gArgs.LockSettings([&](util::Settings& s) {
43+
s.forced_settings.erase("listen");
44+
s.forced_settings.erase("listenonion");
45+
});
46+
QVERIFY(!gArgs.IsArgSet("-listen"));
47+
QVERIFY(!gArgs.IsArgSet("-listenonion"));
48+
49+
QSettings settings;
50+
settings.setValue("fListen", false);
51+
52+
OptionsModel{};
53+
54+
const bool expected{false};
55+
56+
QVERIFY(gArgs.IsArgSet("-listen"));
57+
QCOMPARE(gArgs.GetBoolArg("-listen", !expected), expected);
58+
59+
QVERIFY(gArgs.IsArgSet("-listenonion"));
60+
QCOMPARE(gArgs.GetBoolArg("-listenonion", !expected), expected);
61+
62+
QVERIFY(AppInitParameterInteraction(gArgs));
63+
64+
// cleanup
65+
settings.remove("fListen");
66+
QVERIFY(!settings.contains("fListen"));
67+
gArgs.ClearPathCache();
68+
}

src/qt/test/optiontests.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class OptionTests : public QObject
1717

1818
private Q_SLOTS:
1919
void optionTests();
20+
void parametersInteraction();
2021

2122
private:
2223
interfaces::Node& m_node;

0 commit comments

Comments
 (0)