test: wallet: Split create and load

This commit is contained in:
David Gumberg
2025-05-27 19:05:54 -07:00
parent 70dbc79b09
commit e12ff8aca0
5 changed files with 38 additions and 11 deletions

View File

@@ -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

View File

@@ -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());

View File

@@ -47,11 +47,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)
std::shared_ptr<CWallet> TestCreateWallet(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> TestCreateWallet(WalletContext& context)
{
DatabaseOptions options;
options.require_create = true;
options.create_flags = WALLET_FLAG_DESCRIPTORS;
DatabaseStatus status;
bilingual_str error;
std::vector<bilingual_str> warnings;
auto database = MakeWalletDatabase("", options, status, error);
return TestCreateWallet(std::move(database), context, options.create_flags);
}
std::shared_ptr<CWallet> TestLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context)
{
bilingual_str error;
std::vector<bilingual_str> 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<CWallet> TestLoadWallet(std::unique_ptr<WalletDatabase> database
std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
{
DatabaseOptions options;
options.create_flags = WALLET_FLAG_DESCRIPTORS;
options.require_existing = true;
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);
return TestLoadWallet(std::move(database), context);
}
void TestUnloadWallet(std::shared_ptr<CWallet>&& wallet)

View File

@@ -32,8 +32,10 @@ const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqq
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);
std::shared_ptr<CWallet> TestCreateWallet(WalletContext& context);
std::shared_ptr<CWallet> TestCreateWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, uint64_t create_flags);
std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context);
std::shared_ptr<CWallet> TestLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, uint64_t create_flags);
std::shared_ptr<CWallet> TestLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context);
void TestUnloadWallet(std::shared_ptr<CWallet>&& wallet);
// Creates a copy of the provided database

View File

@@ -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);