aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/test/util.cpp
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-05-25 14:06:21 -0400
committerAndrew Chow <github@achow101.com>2023-05-25 14:40:26 -0400
commitc61d3f02f5122b38ea8bf0029aa9dfbbf38e10d0 (patch)
tree5cf8152ce5f1e625619cdfada6332ad7488a8ad0 /src/wallet/test/util.cpp
parent25202cace9140870c75cb3a811e10045df88c226 (diff)
downloadbitcoin-c61d3f02f5122b38ea8bf0029aa9dfbbf38e10d0.tar.xz
tests, bench: Consolidate {Test,Bench}Un/LoadWallet helper
The wallet tests and benchmarks both had helper functions for loading and unloading the wallet for the test that were almost identical. These functions are consolidated and reused.
Diffstat (limited to 'src/wallet/test/util.cpp')
-rw-r--r--src/wallet/test/util.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp
index 09e7979c02..eacb70cd69 100644
--- a/src/wallet/test/util.cpp
+++ b/src/wallet/test/util.cpp
@@ -9,6 +9,7 @@
#include <key_io.h>
#include <streams.h>
#include <test/util/setup_common.h>
+#include <wallet/context.h>
#include <wallet/wallet.h>
#include <wallet/walletdb.h>
@@ -45,6 +46,36 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
return wallet;
}
+std::shared_ptr<CWallet> TestLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, uint64_t create_flags)
+{
+ bilingual_str error;
+ std::vector<bilingual_str> warnings;
+ auto wallet = CWallet::Create(context, "", std::move(database), create_flags, error, warnings);
+ NotifyWalletLoaded(context, wallet);
+ if (context.chain) {
+ wallet->postInitProcess();
+ }
+ return wallet;
+}
+
+std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
+{
+ DatabaseOptions options;
+ options.create_flags = WALLET_FLAG_DESCRIPTORS;
+ DatabaseStatus status;
+ bilingual_str error;
+ std::vector<bilingual_str> warnings;
+ auto database = MakeWalletDatabase("", options, status, error);
+ return TestLoadWallet(std::move(database), context, options.create_flags);
+}
+
+void TestUnloadWallet(std::shared_ptr<CWallet>&& wallet)
+{
+ SyncWithValidationInterfaceQueue();
+ wallet->m_chain_notifications_handler.reset();
+ UnloadWallet(std::move(wallet));
+}
+
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database)
{
return std::make_unique<MockableDatabase>(dynamic_cast<MockableDatabase&>(database).m_records);