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) 2009-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 <interfaces/init.h>8#include <interfaces/node.h>9#include <qt/bitcoin.h>10#include <qt/guiconstants.h>11#include <qt/test/apptests.h>12#include <qt/test/optiontests.h>13#include <qt/test/rpcnestedtests.h>14#include <qt/test/uritests.h>15#include <test/util/setup_common.h>16#include <util/chaintype.h>18#ifdef ENABLE_WALLET19#include <qt/test/addressbooktests.h>20#include <qt/test/wallettests.h>21#endif // ENABLE_WALLET23#include <QApplication>24#include <QDebug>25#include <QObject>26#include <QSettings>27#include <QTest>29#include <functional>31const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS{};33const std::function<std::string()> G_TEST_GET_FULL_NAME{};35// This is all you need to run all the tests36int main(int argc, char* argv[])37{38// Initialize persistent globals with the testing setup state for sanity.39// E.g. -datadir in gArgs is set to a temp directory dummy value (instead40// of defaulting to the default datadir), or globalChainParams is set to41// regtest params.42//43// All tests must use their own testing setup (if needed).44fs::create_directories([] {45BasicTestingSetup dummy{ChainType::REGTEST};46return gArgs.GetDataDirNet() / "blocks";47}());49std::unique_ptr<interfaces::Init> init = interfaces::MakeGuiInit(argc, argv);50gArgs.ForceSetArg("-listen", "0");51gArgs.ForceSetArg("-listenonion", "0");52gArgs.ForceSetArg("-discover", "0");53gArgs.ForceSetArg("-dnsseed", "0");54gArgs.ForceSetArg("-fixedseeds", "0");55gArgs.ForceSetArg("-natpmp", "0");57std::string error;58if (!gArgs.ReadConfigFiles(error, true)) qWarning() << error.c_str();60// Prefer the "minimal" platform for the test instead of the normal default61// platform ("xcb", "windows", or "cocoa") so tests can't unintentionally62// interfere with any background GUIs and don't require extra resources.63#if defined(WIN32)64if (getenv("QT_QPA_PLATFORM") == nullptr) _putenv_s("QT_QPA_PLATFORM", "minimal");65#else66setenv("QT_QPA_PLATFORM", "minimal", 0 /* overwrite */);67#endif69#ifdef Q_OS_MACOS70// QMacStyle assumes a Cocoa platform window, which the minimal platform71// does not provide. In particular, painting a QGroupBox can make Qt call72// addSubview: on an invalid native object (QTBUG-49686).73setenv("QT_STYLE_OVERRIDE", "fusion", 0 /* overwrite */);74#endif76QCoreApplication::setOrganizationName(QAPP_ORG_NAME);77QCoreApplication::setApplicationName(QAPP_APP_NAME_DEFAULT "-test");79int num_test_failures{0};81{82BitcoinApplication app;83app.createNode(*init);85AppTests app_tests(app);86num_test_failures += QTest::qExec(&app_tests);88OptionTests options_tests(app.node());89num_test_failures += QTest::qExec(&options_tests);91URITests test1;92num_test_failures += QTest::qExec(&test1);94RPCNestedTests test3(app.node());95num_test_failures += QTest::qExec(&test3);97#ifdef ENABLE_WALLET98WalletTests test5(app.node());99num_test_failures += QTest::qExec(&test5);101AddressBookTests test6(app.node());102num_test_failures += QTest::qExec(&test6);103#endif105if (num_test_failures) {106qWarning("\nFailed tests: %d\n", num_test_failures);107} else {108qDebug("\nAll tests passed.\n");109}110}112QSettings settings;113settings.clear();115return num_test_failures;116}
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.