public void ElementsSelectCoinsTest24()
        {
            // SelectCoins_with_multiple_asset_not_consider_fee
            CoinSelectionUtil util = new CoinSelectionUtil();

            ElementsUtxoData[] utxos    = GetElementsBnbUtxoList(CfdNetworkType.Liquidv1);
            ConfidentialAsset  feeAsset = new ConfidentialAsset(assetC);
            var targetAssetAmountMap    = new Dictionary <ConfidentialAsset, long> {
                { new ConfidentialAsset(assetA), 115800000 },
                { new ConfidentialAsset(assetB), 19226350 },
                { new ConfidentialAsset(assetC), 99060000 },
            };

            ElementsUtxoData[] selectedList = util.SelectCoinsForElements(
                utxos, targetAssetAmountMap, feeAsset, 1500, 0);
            Assert.Equal(6, selectedList.Length);
            Assert.Equal(0, util.GetLastSelectedUtxoFee());
            long totalAmountA = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetA));
            long totalAmountB = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetB));
            long totalAmountC = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetC));

            Assert.Equal(115800000, totalAmountA);
            Assert.Equal(19226350, totalAmountB);
            Assert.Equal(127030000, totalAmountC);
            if (selectedList.Length == 6)
            {
                Assert.Equal(61062500, selectedList[0].GetAmount());
                Assert.Equal(39062500, selectedList[1].GetAmount());
                Assert.Equal(15675000, selectedList[2].GetAmount());
                Assert.Equal(18476350, selectedList[3].GetAmount());
                Assert.Equal(750000, selectedList[4].GetAmount());
                Assert.Equal(127030000, selectedList[5].GetAmount());
            }
        }
        public void ElementsSelectCoinsTest21()
        {
            // SelectCoins_KnapsackSolver_with_multiple_asset
            CoinSelectionUtil util = new CoinSelectionUtil();

            ElementsUtxoData[] utxos    = GetElementsUtxoList();
            ConfidentialAsset  feeAsset = new ConfidentialAsset(assetA);
            var targetAssetAmountMap    = new Dictionary <ConfidentialAsset, long> {
                { new ConfidentialAsset(assetA), 39060180 },
                { new ConfidentialAsset(assetB), 25000000 },
            };

            ElementsUtxoData[] selectedList = util.SelectCoinsForElements(
                utxos, targetAssetAmountMap, feeAsset, 1500, 20.0);
            Assert.Equal(2, selectedList.Length);
            Assert.Equal(3680, util.GetLastSelectedUtxoFee());
            long totalAmountA = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetA));
            long totalAmountB = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetB));
            long totalAmountC = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetC));

            Assert.Equal(78125000, totalAmountA);
            Assert.Equal(26918400, totalAmountB);
            Assert.Equal(0, totalAmountC);
            if (selectedList.Length == 2)
            {
                Assert.Equal(26918400, selectedList[0].GetAmount());
                Assert.Equal(78125000, selectedList[1].GetAmount());
            }
        }
        public void ElementsSelectCoinsTest23()
        {
            // SelectCoins_with_multiple_asset_fee_only_target
            CoinSelectionUtil util = new CoinSelectionUtil();

            ElementsUtxoData[] utxos    = GetElementsBnbUtxoList(CfdNetworkType.Liquidv1);
            ConfidentialAsset  feeAsset = new ConfidentialAsset(assetC);
            var targetAssetAmountMap    = new Dictionary <ConfidentialAsset, long> {
                { new ConfidentialAsset(assetA), 99997900 },
                { new ConfidentialAsset(assetB), 346495050 },
                { new ConfidentialAsset(assetC), 0 },
            };

            ElementsUtxoData[] selectedList = util.SelectCoinsForElements(
                utxos, targetAssetAmountMap, feeAsset, 1500, 2.0);
            Assert.Equal(4, selectedList.Length);
            Assert.Equal(736, util.GetLastSelectedUtxoFee());
            long totalAmountA = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetA));
            long totalAmountB = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetB));
            long totalAmountC = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetC));

            Assert.Equal(155062500, totalAmountA);
            Assert.Equal(347180050, totalAmountB);
            Assert.Equal(37654200, totalAmountC);
            if (selectedList.Length == 4)
            {
                Assert.Equal(155062500, selectedList[0].GetAmount());
                Assert.Equal(346430050, selectedList[1].GetAmount());
                Assert.Equal(750000, selectedList[2].GetAmount());
                Assert.Equal(37654200, selectedList[3].GetAmount());
            }
        }
        public void ElementsSelectCoinsTest13()
        {
            // SelectCoins_SelectCoinsBnB_empty_with_asset
            CoinSelectionUtil util = new CoinSelectionUtil();

            ElementsUtxoData[] utxos    = GetElementsBnbUtxoList(CfdNetworkType.Liquidv1);
            ConfidentialAsset  feeAsset = new ConfidentialAsset(assetA);
            var targetAssetAmountMap    = new Dictionary <ConfidentialAsset, long> {
                { new ConfidentialAsset(assetA), 114040000 },
            };

            ElementsUtxoData[] selectedList = util.SelectCoinsForElements(
                utxos, targetAssetAmountMap, feeAsset, 1500, 1.0);
            Assert.Equal(3, selectedList.Length);
            Assert.Equal(276, util.GetLastSelectedUtxoFee());
            long totalAmount = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetA));

            Assert.Equal(115063590, totalAmount);
            if (selectedList.Length == 3)
            {
                Assert.Equal(61062500, selectedList[0].GetAmount());
                Assert.Equal(39062500, selectedList[1].GetAmount());
                Assert.Equal(14938590, selectedList[2].GetAmount());
            }
        }
        public void ElementsSelectCoinsTest01()
        {
            CoinSelectionUtil util = new CoinSelectionUtil();

            ElementsUtxoData[] utxos    = GetElementsUtxoList();
            ConfidentialAsset  feeAsset = new ConfidentialAsset(assetA);
            var targetAssetAmountMap    = new Dictionary <ConfidentialAsset, long> {
                { new ConfidentialAsset(assetA), 0 },
            };

            ElementsUtxoData[] selectedList = util.SelectCoinsForElements(
                utxos, targetAssetAmountMap, feeAsset, 1500, 0);
            Assert.Empty(selectedList);
            Assert.Equal(0, util.GetLastSelectedUtxoFee());
            long totalAmount = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetA));

            Assert.Equal(0, totalAmount);
        }
        public void ElementsSelectCoinsTest02()
        {
            CoinSelectionUtil util = new CoinSelectionUtil();

            ElementsUtxoData[] utxos    = GetElementsUtxoList();
            ConfidentialAsset  feeAsset = new ConfidentialAsset(assetA);
            var targetAssetAmountMap    = new Dictionary <ConfidentialAsset, long> {
                { new ConfidentialAsset(assetA), 39060180 },
            };

            ElementsUtxoData[] selectedList = util.SelectCoinsForElements(
                utxos, targetAssetAmountMap, feeAsset, 1500, 20.0);
            Assert.Single(selectedList);
            Assert.Equal(1840, util.GetLastSelectedUtxoFee());
            long totalAmount = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetA));

            Assert.Equal(78125000, totalAmount);
            if (selectedList.Length == 1)
            {
                Assert.Equal(78125000, selectedList[0].GetAmount());
            }
        }
        public void ElementsSelectCoinsTest12()
        {
            // SelectCoins_SelectCoinsBnB_single_with_asset
            CoinSelectionUtil util = new CoinSelectionUtil();

            ElementsUtxoData[] utxos    = GetElementsBnbUtxoList(CfdNetworkType.Liquidv1);
            ConfidentialAsset  feeAsset = new ConfidentialAsset(assetA);
            var targetAssetAmountMap    = new Dictionary <ConfidentialAsset, long> {
                { new ConfidentialAsset(assetA), 155060800 },
            };

            ElementsUtxoData[] selectedList = util.SelectCoinsForElements(
                utxos, targetAssetAmountMap, feeAsset, 1500, 2.0);
            Assert.Single(selectedList);
            Assert.Equal(184, util.GetLastSelectedUtxoFee());
            long totalAmount = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetA));

            Assert.Equal(155062500, totalAmount);
            if (selectedList.Length == 1)
            {
                Assert.Equal(155062500, selectedList[0].GetAmount());
            }
        }
        public void ElementsSelectCoinsTest11()
        {
            CoinSelectionUtil util = new CoinSelectionUtil();

            ElementsUtxoData[] utxos    = GetElementsBnbUtxoList(CfdNetworkType.Liquidv1);
            ConfidentialAsset  feeAsset = new ConfidentialAsset(assetA);
            var targetAssetAmountMap    = new Dictionary <ConfidentialAsset, long> {
                { new ConfidentialAsset(assetA), 99998500 },
            };

            ElementsUtxoData[] selectedList = util.SelectCoinsForElements(
                utxos, targetAssetAmountMap, feeAsset, 1500, 2.0);
            Assert.Equal(2, selectedList.Length);
            Assert.Equal(368, util.GetLastSelectedUtxoFee());
            long totalAmount = CoinSelectionUtil.GetTotalAmount(selectedList, new ConfidentialAsset(assetA));

            Assert.Equal(100001090, totalAmount);
            if (selectedList.Length == 2)
            {
                Assert.Equal(85062500, selectedList[0].GetAmount());
                Assert.Equal(14938590, selectedList[1].GetAmount());
            }
        }