| 22 | using wallet::WALLET_FLAG_DESCRIPTORS; |
| 23 | |
| 24 | static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine) |
| 25 | { |
| 26 | const auto test_setup = MakeNoLogFileContext<const TestingSetup>(); |
| 27 | |
| 28 | const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE; |
| 29 | |
| 30 | CWallet wallet{test_setup->m_node.chain.get(), "", gArgs, CreateMockWalletDatabase()}; |
| 31 | { |
| 32 | LOCK(wallet.cs_wallet); |
| 33 | wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); |
| 34 | wallet.SetupDescriptorScriptPubKeyMans(); |
| 35 | if (wallet.LoadWallet() != DBErrors::LOAD_OK) assert(false); |
| 36 | } |
| 37 | auto handler = test_setup->m_node.chain->handleNotifications({&wallet, [](CWallet*) {}}); |
| 38 | |
| 39 | const std::optional<std::string> address_mine{add_mine ? std::optional<std::string>{getnewaddress(wallet)} : std::nullopt}; |
| 40 | |
| 41 | for (int i = 0; i < 100; ++i) { |
| 42 | generatetoaddress(test_setup->m_node, address_mine.value_or(ADDRESS_WATCHONLY)); |
| 43 | generatetoaddress(test_setup->m_node, ADDRESS_WATCHONLY); |
| 44 | } |
| 45 | SyncWithValidationInterfaceQueue(); |
| 46 | |
| 47 | auto bal = GetBalance(wallet); // Cache |
| 48 | |
| 49 | bench.run([&] { |
| 50 | if (set_dirty) wallet.MarkDirty(); |
| 51 | bal = GetBalance(wallet); |
| 52 | if (add_mine) assert(bal.m_mine_trusted[::policyAsset] > 0); |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | static void WalletBalanceDirty(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ true, /* add_mine */ true); } |
| 57 | static void WalletBalanceClean(benchmark::Bench& bench) { WalletBalance(bench, /* set_dirty */ false, /* add_mine */ true); } |
no test coverage detected