mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-11 08:07:33 +02:00
test: Rework SRD insufficient balance test
This refactor is part of the effort to move the coin selection tests to a framework that can use non-zero, realistic feerates. The insufficient funds failure case is extended with a few additional similar variants of the failure.
This commit is contained in:
@@ -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<OutputGroup>& 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<OutputGroup> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user