mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-15 14:22:37 -03:00
7918c1b019
Add unit test calling CreateWalletFromFile, which isn't currently called from
other unit tests, with some basic checks to make sure it rescans and registers
for notifications correctly.
Motivation for this change was to try to write a test that would fail without
the early `handleNotifications` call in ef8c6ca60767cac589d98ca57ee33179608ccda8
from https://github.com/bitcoin/bitcoin/pull/16426, but succeed with it:
ef8c6ca607/src/wallet/wallet.cpp (L3978-L3986)
However, writing a full test for the race condition that call prevents isn't
possible without the locking changes from #16426. So this PR just adds as much
test coverage as is possible now.
This new test is also useful for https://github.com/bitcoin/bitcoin/pull/15719,
since it detects the stale notifications.transactionAddedToMempool notifications
that PR eliminates.
32 lines
962 B
C++
32 lines
962 B
C++
// Copyright (c) 2019 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <test/util/logging.h>
|
|
|
|
#include <logging.h>
|
|
#include <noui.h>
|
|
#include <tinyformat.h>
|
|
#include <util/memory.h>
|
|
|
|
#include <stdexcept>
|
|
|
|
DebugLogHelper::DebugLogHelper(std::string message, MatchFn match)
|
|
: m_message{std::move(message)}, m_match(std::move(match))
|
|
{
|
|
m_print_connection = LogInstance().PushBackCallback(
|
|
[this](const std::string& s) {
|
|
if (m_found) return;
|
|
m_found = s.find(m_message) != std::string::npos && m_match(&s);
|
|
});
|
|
noui_test_redirect();
|
|
}
|
|
|
|
void DebugLogHelper::check_found()
|
|
{
|
|
noui_reconnect();
|
|
LogInstance().DeleteCallback(m_print_connection);
|
|
if (!m_found && m_match(nullptr)) {
|
|
throw std::runtime_error(strprintf("'%s' not found in debug log\n", m_message));
|
|
}
|
|
}
|