@@ -980,5 +980,45 @@ BOOST_AUTO_TEST_CASE(SelectCoins_effective_value_test)
980980 BOOST_CHECK (!result);
981981}
982982
983+ BOOST_FIXTURE_TEST_CASE (wallet_coinsresult_test, BasicTestingSetup)
984+ {
985+ // Test case to verify CoinsResult object sanity.
986+ CoinsResult available_coins;
987+ {
988+ std::unique_ptr<CWallet> dummyWallet = std::make_unique<CWallet>(m_node.chain .get (), " dummy" , m_args, CreateMockWalletDatabase ());
989+ BOOST_CHECK_EQUAL (dummyWallet->LoadWallet (), DBErrors::LOAD_OK);
990+ LOCK (dummyWallet->cs_wallet );
991+ dummyWallet->SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
992+ dummyWallet->SetupDescriptorScriptPubKeyMans ();
993+
994+ // Add some coins to 'available_coins'
995+ for (int i=0 ; i<10 ; i++) {
996+ add_coin (available_coins, *dummyWallet, 1 * COIN);
997+ }
998+ }
999+
1000+ {
1001+ // First test case, check that 'CoinsResult::Erase' function works as expected.
1002+ // By trying to erase two elements from the 'available_coins' object.
1003+ std::unordered_set<COutPoint, SaltedOutpointHasher> outs_to_remove;
1004+ const auto & coins = available_coins.All ();
1005+ for (int i = 0 ; i < 2 ; i++) {
1006+ outs_to_remove.emplace (coins[i].outpoint );
1007+ }
1008+ available_coins.Erase (outs_to_remove);
1009+
1010+ // Check that the elements were actually removed.
1011+ const auto & updated_coins = available_coins.All ();
1012+ for (const auto & out: outs_to_remove) {
1013+ auto it = std::find_if (updated_coins.begin (), updated_coins.end (), [&out](const COutput &coin) {
1014+ return coin.outpoint == out;
1015+ });
1016+ BOOST_CHECK (it == updated_coins.end ());
1017+ }
1018+ // And verify that no extra element were removed
1019+ BOOST_CHECK_EQUAL (available_coins.Size (), 8 );
1020+ }
1021+ }
1022+
9831023BOOST_AUTO_TEST_SUITE_END ()
9841024} // namespace wallet
0 commit comments