mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Merge bitcoin/bitcoin#26715: Introduce MockableDatabase for wallet unit tests
33e2b82a4fwallet, bench: Remove unused database options from WalletBenchLoading (Andrew Chow)80ace042d8tests: Modify records directly in wallet ckey loading test (Andrew Chow)b3bb17d5d0tests: Update DuplicateMockDatabase for MockableDatabase (Andrew Chow)f0eecf5e40scripted-diff: Replace CreateMockWalletDB with CreateMockableWalletDB (Andrew Chow)075962bc25wallet, tests: Include wallet/test/util.h (Andrew Chow)14aa4cb1e4wallet: Move DummyDatabase to salvage (Andrew Chow)f67a385556wallet, tests: Replace usage of dummy db with mockable db (Andrew Chow)33c6245ac1Introduce MockableDatabase for wallet unit tests (Andrew Chow) Pull request description: For the wallet's unit tests, we currently use either `DummyDatabase` or memory-only versions of either BDB or SQLite. The tests that use `DummyDatabase` just need a `WalletDatabase` so that the `CWallet` can be constructed, while the tests using the memory-only databases just need a backing data store. There is also a `FailDatabase` that is similar to `DummyDatabase` except it fails be default or can have a configured return value. Having all of these different database types can make it difficult to write tests, particularly tests that work when either BDB or SQLite is disabled. This PR unifies all of these different unit test database classes into a single `MockableDatabase`. Like `DummyDatabase`, most functions do nothing and just return true. Like `FailDatabase`, the return value of some functions can be configured on the fly to test various failure cases. Like the memory-only databases, records can actually be written to the `MockableDatabase` and be retrieved later, but all of this is still held in memory. Using `MockableDatabase` completely removes the need for having BDB or SQLite backed wallets in the unit tests for the tests that are not actually testing specific database behaviors. Because `MockableDatabase`s can be created by each unit test, we can also control what records are stored in the database. Records can be added and removed externally from the typical database modification functions. This will give us greater ability to test failure conditions, particularly those involving corrupted records. Possible alternative to #26644 ACKs for top commit: furszy: ACK33e2b82TheCharlatan: ACK33e2b82a4fTree-SHA512: c2b09eff9728d063d2d4aea28a0f0e64e40b76483e75dc53f08667df23bd25834d52656cd4eafb02e552db0b9e619cfdb1b1c65b26b5436ee2c971d804768bcc
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <key.h>
|
||||
#include <key_io.h>
|
||||
#include <wallet/wallet.h>
|
||||
#include <wallet/test/util.h>
|
||||
#include <walletinitinterface.h>
|
||||
|
||||
#include <chrono>
|
||||
@@ -31,7 +32,7 @@
|
||||
|
||||
using wallet::AddWallet;
|
||||
using wallet::CWallet;
|
||||
using wallet::CreateMockWalletDatabase;
|
||||
using wallet::CreateMockableWalletDatabase;
|
||||
using wallet::RemoveWallet;
|
||||
using wallet::WALLET_FLAG_DESCRIPTORS;
|
||||
using wallet::WalletContext;
|
||||
@@ -75,7 +76,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
|
||||
auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
|
||||
test.m_node.wallet_loader = wallet_loader.get();
|
||||
node.setContext(&test.m_node);
|
||||
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
|
||||
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
|
||||
wallet->LoadWallet();
|
||||
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <qt/walletmodel.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <validation.h>
|
||||
#include <wallet/test/util.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
#include <chrono>
|
||||
@@ -46,7 +47,7 @@
|
||||
|
||||
using wallet::AddWallet;
|
||||
using wallet::CWallet;
|
||||
using wallet::CreateMockWalletDatabase;
|
||||
using wallet::CreateMockableWalletDatabase;
|
||||
using wallet::RemoveWallet;
|
||||
using wallet::WALLET_FLAG_DESCRIPTORS;
|
||||
using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS;
|
||||
@@ -189,7 +190,7 @@ void SyncUpWallet(const std::shared_ptr<CWallet>& wallet, interfaces::Node& node
|
||||
|
||||
std::shared_ptr<CWallet> SetupLegacyWatchOnlyWallet(interfaces::Node& node, TestChain100Setup& test)
|
||||
{
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
|
||||
wallet->LoadWallet();
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
@@ -207,7 +208,7 @@ std::shared_ptr<CWallet> SetupLegacyWatchOnlyWallet(interfaces::Node& node, Test
|
||||
|
||||
std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChain100Setup& test)
|
||||
{
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
|
||||
wallet->LoadWallet();
|
||||
LOCK(wallet->cs_wallet);
|
||||
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||
|
||||
Reference in New Issue
Block a user