diff --git a/src/wallet/test/coinselection_tests.cpp b/src/wallet/test/coinselection_tests.cpp index 347e00f7273..fb3b0b19a8a 100644 --- a/src/wallet/test/coinselection_tests.cpp +++ b/src/wallet/test/coinselection_tests.cpp @@ -236,5 +236,30 @@ BOOST_AUTO_TEST_CASE(bnb_feerate_sensitivity_test) TestBnBSuccess("Prefer two light inputs over two heavy inputs at high feerates", high_feerate_pool, /*selection_target=*/13 * CENT, /*expected_input_amounts=*/{3 * CENT, 10 * CENT}, high_feerate_params); } +static void TestSRDFail(std::string test_title, std::vector& utxo_pool, const CAmount& selection_target, const CoinSelectionParams& cs_params = default_cs_params, int max_selection_weight = MAX_STANDARD_TX_WEIGHT, const bool expect_max_weight_exceeded = false) +{ + const auto result = SelectCoinsSRD(utxo_pool, selection_target, cs_params.m_change_fee, cs_params.rng_fast, max_selection_weight); + BOOST_CHECK_MESSAGE(!result, "SRD-Fail: " + test_title); + bool max_weight_exceeded = util::ErrorString(result).original.find("The inputs size exceeds the maximum weight") != std::string::npos; + BOOST_CHECK(expect_max_weight_exceeded == max_weight_exceeded); +} + +BOOST_AUTO_TEST_CASE(srd_test) +{ + for (int feerate : FEERATES) { + std::vector utxo_pool; + + const CoinSelectionParams cs_params = init_cs_params(feerate); + + TestSRDFail("Empty UTXO pool", utxo_pool, /*selection_target=*/1 * CENT, cs_params); + + AddCoins(utxo_pool, {1 * CENT, 3 * CENT, 5 * CENT}, cs_params); + + TestSRDFail("Undershoot minimum change by one sat", utxo_pool, /*selection_target=*/9 * CENT - cs_params.m_change_fee - CHANGE_LOWER + 1, cs_params); + TestSRDFail("Spend more than available", utxo_pool, /*selection_target=*/9 * CENT + 1, cs_params); + TestSRDFail("Spend everything", utxo_pool, /*selection_target=*/9 * CENT, cs_params); + } +} + BOOST_AUTO_TEST_SUITE_END() } // namespace wallet diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index fe33e9347e7..740079d2c66 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -1217,24 +1217,6 @@ BOOST_AUTO_TEST_CASE(srd_tests) /*avoid_partial=*/false, }; - { - // ######################################################### - // 1) Insufficient funds, select all provided coins and fail - // ######################################################### - CAmount target = 49.5L * COIN; - int max_selection_weight = 10000; // high enough to not fail for this reason. - const auto& res = SelectCoinsSRD(target, dummy_params, m_node, max_selection_weight, [&](CWallet& wallet) { - CoinsResult available_coins; - for (int j = 0; j < 10; ++j) { - add_coin(available_coins, wallet, CAmount(1 * COIN)); - add_coin(available_coins, wallet, CAmount(2 * COIN)); - } - return available_coins; - }); - BOOST_CHECK(!res); - BOOST_CHECK(util::ErrorString(res).empty()); // empty means "insufficient funds" - } - { // ########################### // 2) Test max weight exceeded