Skip to content

Commit 47bac47

Browse files
committed
Merge #569: test: add regression test for #567
4d4dca4 test: add regression test for /issues/567 (Vasil Dimov) 3b82608 options: add a comment for -listenonion and dedup a long expression (Vasil Dimov) Pull request description: Add a test that would fail, should #567 resurface. Also, add a comment and dedup a long expression. ACKs for top commit: jarolrod: reACK 4d4dca4 jonatack: ACK 4d4dca4 hebasto: ACK 4d4dca4, tested with reverting changes from #568, and getting an expected test failure. shaavan: ACK 4d4dca4 Tree-SHA512: 59f069bdaa84586bb599e9372f89e4e66a3cafcbf58677fdf913d685c17dfa9c3d5b118829d81021a9a33b4fd8e46d4c7eb68c1dd902cf1c44a41b8e66e2967b
2 parents 4faf7a1 + 4d4dca4 commit 47bac47

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
@@ -151,9 +151,26 @@ void OptionsModel::Init(bool resetSettings)
151151

152152
if (!settings.contains("fListen"))
153153
settings.setValue("fListen", DEFAULT_LISTEN);
154-
if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool())) {
154+
const bool listen{settings.value("fListen").toBool()};
155+
if (!gArgs.SoftSetBoolArg("-listen", listen)) {
155156
addOverriddenOption("-listen");
156-
} else if (!settings.value("fListen").toBool()) {
157+
} else if (!listen) {
158+
// We successfully set -listen=0, thus mimic the logic from InitParameterInteraction():
159+
// "parameter interaction: -listen=0 -> setting -listenonion=0".
160+
//
161+
// Both -listen and -listenonion default to true.
162+
//
163+
// The call order is:
164+
//
165+
// InitParameterInteraction()
166+
// would set -listenonion=0 if it sees -listen=0, but for bitcoin-qt with
167+
// fListen=false -listen is 1 at this point
168+
//
169+
// OptionsModel::Init()
170+
// (this method) can flip -listen from 1 to 0 if fListen=false
171+
//
172+
// AppInitParameterInteraction()
173+
// raises an error if -listen=0 and -listenonion=1
157174
gArgs.SoftSetBoolArg("-listenonion", false);
158175
}
159176

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)