From c61d3f02f5122b38ea8bf0029aa9dfbbf38e10d0 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Thu, 25 May 2023 14:06:21 -0400 Subject: 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. --- src/wallet/test/util.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/wallet/test/util.cpp') 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 #include #include +#include #include #include @@ -45,6 +46,36 @@ std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, CChain& cc return wallet; } +std::shared_ptr TestLoadWallet(std::unique_ptr database, WalletContext& context, uint64_t create_flags) +{ + bilingual_str error; + std::vector 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 TestLoadWallet(WalletContext& context) +{ + DatabaseOptions options; + options.create_flags = WALLET_FLAG_DESCRIPTORS; + DatabaseStatus status; + bilingual_str error; + std::vector warnings; + auto database = MakeWalletDatabase("", options, status, error); + return TestLoadWallet(std::move(database), context, options.create_flags); +} + +void TestUnloadWallet(std::shared_ptr&& wallet) +{ + SyncWithValidationInterfaceQueue(); + wallet->m_chain_notifications_handler.reset(); + UnloadWallet(std::move(wallet)); +} + std::unique_ptr DuplicateMockDatabase(WalletDatabase& database) { return std::make_unique(dynamic_cast(database).m_records); -- cgit v1.2.3