@@ -622,6 +622,46 @@ BOOST_FIXTURE_TEST_CASE(ListCoinsTest, ListCoinsTestingSetup)
622
622
BOOST_CHECK_EQUAL (list.begin ()->second .size (), 2U );
623
623
}
624
624
625
+ void TestCoinsResult (ListCoinsTest& context, OutputType out_type, CAmount amount,
626
+ std::map<OutputType, size_t >& expected_coins_sizes)
627
+ {
628
+ LOCK (context.wallet ->cs_wallet );
629
+ util::Result<CTxDestination> dest = Assert (context.wallet ->GetNewDestination (out_type, " " ));
630
+ CWalletTx& wtx = context.AddTx (CRecipient{{GetScriptForDestination (*dest)}, amount, /* fSubtractFeeFromAmount=*/ true });
631
+ CoinFilterParams filter;
632
+ filter.skip_locked = false ;
633
+ CoinsResult available_coins = AvailableCoins (*context.wallet , nullptr , std::nullopt, filter);
634
+ // Lock outputs so they are not spent in follow-up transactions
635
+ for (uint32_t i = 0 ; i < wtx.tx ->vout .size (); i++) context.wallet ->LockCoin ({wtx.GetHash (), i});
636
+ for (const auto & [type, size] : expected_coins_sizes) BOOST_CHECK_EQUAL (size, available_coins.coins [type].size ());
637
+ }
638
+
639
+ BOOST_FIXTURE_TEST_CASE (BasicOutputTypesTest, ListCoinsTest)
640
+ {
641
+ std::map<OutputType, size_t > expected_coins_sizes;
642
+ for (const auto & out_type : OUTPUT_TYPES) { expected_coins_sizes[out_type] = 0U ; }
643
+
644
+ // Verify our wallet has one usable coinbase UTXO before starting
645
+ // This UTXO is a P2PK, so it should show up in the Other bucket
646
+ expected_coins_sizes[OutputType::UNKNOWN] = 1U ;
647
+ CoinsResult available_coins = WITH_LOCK (wallet->cs_wallet , return AvailableCoins (*wallet));
648
+ BOOST_CHECK_EQUAL (available_coins.Size (), expected_coins_sizes[OutputType::UNKNOWN]);
649
+ BOOST_CHECK_EQUAL (available_coins.coins [OutputType::UNKNOWN].size (), expected_coins_sizes[OutputType::UNKNOWN]);
650
+
651
+ // We will create a self transfer for each of the OutputTypes and
652
+ // verify it is put in the correct bucket after running GetAvailablecoins
653
+ //
654
+ // For each OutputType, We expect 2 UTXOs in our wallet following the self transfer:
655
+ // 1. One UTXO as the recipient
656
+ // 2. One UTXO from the change, due to payment address matching logic
657
+
658
+ for (const auto & out_type : OUTPUT_TYPES) {
659
+ if (out_type == OutputType::UNKNOWN) continue ;
660
+ expected_coins_sizes[out_type] = 2U ;
661
+ TestCoinsResult (*this , out_type, 1 * COIN, expected_coins_sizes);
662
+ }
663
+ }
664
+
625
665
BOOST_FIXTURE_TEST_CASE (wallet_disableprivkeys, TestChain100Setup)
626
666
{
627
667
{
0 commit comments