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) 2018-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 <qt/test/apptests.h>7#include <chainparams.h>8#include <key.h>9#include <logging.h>10#include <qt/bitcoin.h>11#include <qt/bitcoingui.h>12#include <qt/networkstyle.h>13#include <qt/rpcconsole.h>14#include <test/util/setup_common.h>15#include <validation.h>17#include <QAction>18#include <QLineEdit>19#include <QRegularExpression>20#include <QScopedPointer>21#include <QSignalSpy>22#include <QString>23#include <QTest>24#include <QTextEdit>25#include <QtGlobal>26#include <QtTest/QtTestWidgets>27#include <QtTest/QtTestGui>29namespace {30//! Regex find a string group inside of the console output31QString FindInConsole(const QString& output, const QString& pattern)32{33const QRegularExpression re(pattern);34return re.match(output).captured(1);35}37//! Call getblockchaininfo RPC and check first field of JSON output.38void TestRpcCommand(RPCConsole* console)39{40QTextEdit* messagesWidget = console->findChild<QTextEdit*>("messagesWidget");41QLineEdit* lineEdit = console->findChild<QLineEdit*>("lineEdit");42QSignalSpy mw_spy(messagesWidget, &QTextEdit::textChanged);43QVERIFY(mw_spy.isValid());44QTest::keyClicks(lineEdit, "getblockchaininfo");45QTest::keyClick(lineEdit, Qt::Key_Return);46QVERIFY(mw_spy.wait(1000));47QCOMPARE(mw_spy.count(), 4);48const QString output = messagesWidget->toPlainText();49const QString pattern = QStringLiteral("\"chain\": \"(\\w+)\"");50QCOMPARE(FindInConsole(output, pattern), QString("regtest"));51}52} // namespace54//! Entry point for BitcoinApplication tests.55void AppTests::appTests()56{57qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo");58m_app.parameterSetup();59QVERIFY(m_app.createOptionsModel(/*resetSettings=*/true));60QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().GetChainType()));61m_app.setupPlatformStyle();62m_app.createWindow(style.data());63connect(&m_app, &BitcoinApplication::windowShown, this, &AppTests::guiTests);64expectCallback("guiTests");65m_app.baseInitialize();66m_app.requestInitialize();67m_app.exec();68m_app.requestShutdown();69m_app.exec();71// Reset global state to avoid interfering with later tests.72LogInstance().DisconnectTestLogger();73}75//! Entry point for BitcoinGUI tests.76void AppTests::guiTests(BitcoinGUI* window)77{78HandleCallback callback{"guiTests", *this};79connect(window, &BitcoinGUI::consoleShown, this, &AppTests::consoleTests);80expectCallback("consoleTests");81QAction* action = window->findChild<QAction*>("openRPCConsoleAction");82action->activate(QAction::Trigger);83}85//! Entry point for RPCConsole tests.86void AppTests::consoleTests(RPCConsole* console)87{88HandleCallback callback{"consoleTests", *this};89TestRpcCommand(console);90}92//! Destructor to shut down after the last expected callback completes.93AppTests::HandleCallback::~HandleCallback()94{95auto& callbacks = m_app_tests.m_callbacks;96auto it = callbacks.find(m_callback);97assert(it != callbacks.end());98callbacks.erase(it);99if (callbacks.empty()) {100m_app_tests.m_app.exit(0);101}102}
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.