Skip to content

Commit 9d73176

Browse files
furszyfanquake
authored andcommitted
test: wallet, coverage for CoinsResult::Erase function
Github-Pull: #26560 Rebased-From: 341ba7f
1 parent 195f0df commit 9d73176

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/wallet/test/coinselector_tests.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,5 +969,45 @@ BOOST_AUTO_TEST_CASE(SelectCoins_effective_value_test)
969969
BOOST_CHECK(!result);
970970
}
971971

972+
BOOST_FIXTURE_TEST_CASE(wallet_coinsresult_test, BasicTestingSetup)
973+
{
974+
// Test case to verify CoinsResult object sanity.
975+
CoinsResult available_coins;
976+
{
977+
std::unique_ptr<CWallet> dummyWallet = std::make_unique<CWallet>(m_node.chain.get(), "dummy", m_args, CreateMockWalletDatabase());
978+
BOOST_CHECK_EQUAL(dummyWallet->LoadWallet(), DBErrors::LOAD_OK);
979+
LOCK(dummyWallet->cs_wallet);
980+
dummyWallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
981+
dummyWallet->SetupDescriptorScriptPubKeyMans();
982+
983+
// Add some coins to 'available_coins'
984+
for (int i=0; i<10; i++) {
985+
add_coin(available_coins, *dummyWallet, 1 * COIN);
986+
}
987+
}
988+
989+
{
990+
// First test case, check that 'CoinsResult::Erase' function works as expected.
991+
// By trying to erase two elements from the 'available_coins' object.
992+
std::set<COutPoint> outs_to_remove;
993+
const auto& coins = available_coins.All();
994+
for (int i = 0; i < 2; i++) {
995+
outs_to_remove.emplace(coins[i].outpoint);
996+
}
997+
available_coins.Erase(outs_to_remove);
998+
999+
// Check that the elements were actually removed.
1000+
const auto& updated_coins = available_coins.All();
1001+
for (const auto& out: outs_to_remove) {
1002+
auto it = std::find_if(updated_coins.begin(), updated_coins.end(), [&out](const COutput &coin) {
1003+
return coin.outpoint == out;
1004+
});
1005+
BOOST_CHECK(it == updated_coins.end());
1006+
}
1007+
// And verify that no extra element were removed
1008+
BOOST_CHECK_EQUAL(available_coins.Size(), 8);
1009+
}
1010+
}
1011+
9721012
BOOST_AUTO_TEST_SUITE_END()
9731013
} // namespace wallet

0 commit comments

Comments
 (0)