diff --git a/src/bench/wallet_ismine.cpp b/src/bench/wallet_ismine.cpp index 6eef1efd992..b0b9c2c5ad0 100644 --- a/src/bench/wallet_ismine.cpp +++ b/src/bench/wallet_ismine.cpp @@ -36,7 +36,7 @@ static void WalletIsMine(benchmark::Bench& bench, int num_combo = 0) // Loading the wallet will also create it uint64_t create_flags = WALLET_FLAG_DESCRIPTORS; auto database = CreateMockableWalletDatabase(); - auto wallet = TestLoadWallet(std::move(database), context, create_flags); + auto wallet = TestCreateWallet(std::move(database), context, create_flags); // For a descriptor wallet, fill with num_combo combo descriptors with random keys // This benchmarks a non-HD wallet migrated to descriptors diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp index 3397fb0030e..8131f192c7a 100644 --- a/src/bench/wallet_loading.cpp +++ b/src/bench/wallet_loading.cpp @@ -43,7 +43,7 @@ static void WalletLoadingDescriptors(benchmark::Bench& bench) // Loading the wallet will also create it uint64_t create_flags = WALLET_FLAG_DESCRIPTORS; auto database = CreateMockableWalletDatabase(); - auto wallet = TestLoadWallet(std::move(database), context, create_flags); + auto wallet = TestCreateWallet(std::move(database), context, create_flags); // Generate a bunch of transactions and addresses to put into the wallet for (int i = 0; i < 1000; ++i) { @@ -56,7 +56,7 @@ static void WalletLoadingDescriptors(benchmark::Bench& bench) TestUnloadWallet(std::move(wallet)); bench.epochs(5).run([&] { - wallet = TestLoadWallet(std::move(database), context, create_flags); + wallet = TestLoadWallet(std::move(database), context); // Cleanup database = DuplicateMockDatabase(wallet->GetDatabase()); diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp index c06c6af5b55..db85b5efe8f 100644 --- a/src/wallet/test/util.cpp +++ b/src/wallet/test/util.cpp @@ -47,11 +47,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) +std::shared_ptr TestCreateWallet(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 TestCreateWallet(WalletContext& context) +{ + DatabaseOptions options; + options.require_create = true; + options.create_flags = WALLET_FLAG_DESCRIPTORS; + DatabaseStatus status; + bilingual_str error; + std::vector warnings; + auto database = MakeWalletDatabase("", options, status, error); + return TestCreateWallet(std::move(database), context, options.create_flags); +} + + +std::shared_ptr TestLoadWallet(std::unique_ptr database, WalletContext& context) { bilingual_str error; std::vector warnings; - auto wallet = CWallet::Create(context, "", std::move(database), create_flags, error, warnings); + auto wallet = CWallet::LoadExisting(context, "", std::move(database), error, warnings); NotifyWalletLoaded(context, wallet); if (context.chain) { wallet->postInitProcess(); @@ -62,12 +87,12 @@ std::shared_ptr TestLoadWallet(std::unique_ptr database std::shared_ptr TestLoadWallet(WalletContext& context) { DatabaseOptions options; - options.create_flags = WALLET_FLAG_DESCRIPTORS; + options.require_existing = true; DatabaseStatus status; bilingual_str error; std::vector warnings; auto database = MakeWalletDatabase("", options, status, error); - return TestLoadWallet(std::move(database), context, options.create_flags); + return TestLoadWallet(std::move(database), context); } void TestUnloadWallet(std::shared_ptr&& wallet) diff --git a/src/wallet/test/util.h b/src/wallet/test/util.h index ecedbd90807..18305fb598e 100644 --- a/src/wallet/test/util.h +++ b/src/wallet/test/util.h @@ -32,8 +32,10 @@ const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqq std::unique_ptr CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key); +std::shared_ptr TestCreateWallet(WalletContext& context); +std::shared_ptr TestCreateWallet(std::unique_ptr database, WalletContext& context, uint64_t create_flags); std::shared_ptr TestLoadWallet(WalletContext& context); -std::shared_ptr TestLoadWallet(std::unique_ptr database, WalletContext& context, uint64_t create_flags); +std::shared_ptr TestLoadWallet(std::unique_ptr database, WalletContext& context); void TestUnloadWallet(std::shared_ptr&& wallet); // Creates a copy of the provided database diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 50d2f78b8d7..4c422904990 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -584,7 +584,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup) WalletContext context; context.args = &m_args; context.chain = m_node.chain.get(); - auto wallet = TestLoadWallet(context); + auto wallet = TestCreateWallet(context); CKey key = GenerateRandomKey(); AddKey(*wallet, key); TestUnloadWallet(std::move(wallet)); @@ -681,7 +681,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWalletWithoutChain, BasicTestingSetup) { WalletContext context; context.args = &m_args; - auto wallet = TestLoadWallet(context); + auto wallet = TestCreateWallet(context); BOOST_CHECK(wallet); WaitForDeleteWallet(std::move(wallet)); } @@ -692,7 +692,7 @@ BOOST_FIXTURE_TEST_CASE(RemoveTxs, TestChain100Setup) WalletContext context; context.args = &m_args; context.chain = m_node.chain.get(); - auto wallet = TestLoadWallet(context); + auto wallet = TestCreateWallet(context); CKey key = GenerateRandomKey(); AddKey(*wallet, key);