Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add regression test for #567 #569

Merged
merged 2 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,26 @@ void OptionsModel::Init(bool resetSettings)

if (!settings.contains("fListen"))
settings.setValue("fListen", DEFAULT_LISTEN);
if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool())) {
const bool listen{settings.value("fListen").toBool()};
if (!gArgs.SoftSetBoolArg("-listen", listen)) {
addOverriddenOption("-listen");
} else if (!settings.value("fListen").toBool()) {
} else if (!listen) {
// We successfully set -listen=0, thus mimic the logic from InitParameterInteraction():
// "parameter interaction: -listen=0 -> setting -listenonion=0".
//
// Both -listen and -listenonion default to true.
//
// The call order is:
//
// InitParameterInteraction()
// would set -listenonion=0 if it sees -listen=0, but for bitcoin-qt with
// fListen=false -listen is 1 at this point
//
// OptionsModel::Init()
// (this method) can flip -listen from 1 to 0 if fListen=false
//
// AppInitParameterInteraction()
// raises an error if -listen=0 and -listenonion=1
gArgs.SoftSetBoolArg("-listenonion", false);
}

Expand Down
37 changes: 37 additions & 0 deletions src/qt/test/optiontests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <init.h>
#include <qt/bitcoin.h>
#include <qt/test/optiontests.h>
#include <test/util/setup_common.h>
Expand Down Expand Up @@ -29,3 +30,39 @@ void OptionTests::optionTests()
});
gArgs.WriteSettingsFile();
}

void OptionTests::parametersInteraction()
vasild marked this conversation as resolved.
Show resolved Hide resolved
{
// 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.ClearPathCache();

gArgs.LockSettings([&](util::Settings& s) {
s.forced_settings.erase("listen");
s.forced_settings.erase("listenonion");
});
Copy link
Member

@jonatack jonatack Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added asserts here as a sanity check, maybe good to add in case the defaults in test_main.cpp change.

 void OptionTests::parametersInteraction()
 {
+    QVERIFY(gArgs.IsArgSet("-listen"));
+    QVERIFY(gArgs.IsArgSet("-listenonion"));
     gArgs.LockSettings([&](util::Settings& s) {
         s.forced_settings.erase("listen");
         s.forced_settings.erase("listenonion");
     }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test unsets those options, so it does not care or rely that they are set when it starts. Thus I think those checks are not necessary. I.e. the test will still work even if those options are not set when it starts.

QVERIFY(!gArgs.IsArgSet("-listen"));
QVERIFY(!gArgs.IsArgSet("-listenonion"));

QSettings settings;
settings.setValue("fListen", false);

OptionsModel{};

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();
}
1 change: 1 addition & 0 deletions src/qt/test/optiontests.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class OptionTests : public QObject

private Q_SLOTS:
void optionTests();
void parametersInteraction();

private:
interfaces::Node& m_node;
Expand Down