diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2020-04-21 12:41:35 -0400 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2020-04-26 20:23:05 -0400 |
commit | 7918c1b019a36a8f9aa55daae422c6b6723b2a39 (patch) | |
tree | b79c090383a2f68f615cca184550608c4df1d89b /src/test/util/logging.cpp | |
parent | eef90c14ed0f559e3f6e187341009270b84f45cb (diff) | |
download | bitcoin-7918c1b019a36a8f9aa55daae422c6b6723b2a39.tar.xz |
test: Add CreateWalletFromFile test
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:
https://github.com/bitcoin/bitcoin/blob/ef8c6ca60767cac589d98ca57ee33179608ccda8/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.
Diffstat (limited to 'src/test/util/logging.cpp')
-rw-r--r-- | src/test/util/logging.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/test/util/logging.cpp b/src/test/util/logging.cpp index fe2e69104b..65a64f2384 100644 --- a/src/test/util/logging.cpp +++ b/src/test/util/logging.cpp @@ -11,13 +11,13 @@ #include <stdexcept> -DebugLogHelper::DebugLogHelper(std::string message) - : m_message{std::move(message)} +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_found = s.find(m_message) != std::string::npos && m_match(&s); }); noui_test_redirect(); } @@ -26,7 +26,7 @@ void DebugLogHelper::check_found() { noui_reconnect(); LogInstance().DeleteCallback(m_print_connection); - if (!m_found) { + if (!m_found && m_match(nullptr)) { throw std::runtime_error(strprintf("'%s' not found in debug log\n", m_message)); } } |