bench: Utilize setup() in WalletCreate to cleanup previous wallets

The WalletCreate benchmark should only be for creating a wallet and
exclude the unloading of the newly created wallet. Instead, unloading
can be done in setup() and after the benchmark completes.
This commit is contained in:
Ava Chow
2026-04-29 14:27:30 -07:00
parent cef58341a0
commit 61412ef887

View File

@@ -47,17 +47,21 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
const auto wallet_path = test_setup->m_path_root / "test_wallet";
const auto wallet_name = fs::PathToString(wallet_path);
bench.run([&] {
auto wallet = CreateWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
assert(status == DatabaseStatus::SUCCESS);
assert(wallet != nullptr);
std::shared_ptr<CWallet> wallet;
auto cleanup{[&] {
if (!wallet) return;
// Release wallet
RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
RemoveWallet(context, wallet, /*load_on_start=*/std::nullopt);
WaitForDeleteWallet(std::move(wallet));
fs::remove(wallet_path / "wallet.dat");
fs::remove(wallet_path);
}};
bench.setup(cleanup).run([&] {
wallet = CreateWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
assert(status == DatabaseStatus::SUCCESS);
assert(wallet != nullptr);
});
cleanup();
}
static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }