mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-24 11:51:20 +02:00
test: Check max_weight_exceeded error
This slays the mutants 14 and 39 Bruno reported via https://gist.github.com/brunoerg/834063398d5002f738506d741513e310, that changing the intial or subsequent value of `max_tx_weight_exceeded` in BnB would not fail any tests: diff --git a/src/wallet/coinselection.cpp b/muts/coinselection.mutant.14.cpp index cee558088f..947bf7b642 100644 --- a/src/wallet/coinselection.cpp +++ b/muts/coinselection.mutant.14.cpp @@ -118,7 +118,7 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool CAmount best_waste = MAX_MONEY; bool is_feerate_high = utxo_pool.at(0).fee > utxo_pool.at(0).long_term_fee; - bool max_tx_weight_exceeded = false; + bool max_tx_weight_exceeded = true; // Depth First search loop for choosing the UTXOs for (size_t curr_try = 0, utxo_pool_index = 0; curr_try < TOTAL_TRIES; ++curr_try, ++utxo_pool_index) { diff --git a/src/wallet/coinselection.cpp b/muts/coinselection.mutant.39.cpp index cee558088f..bbfdc23889 100644 --- a/src/wallet/coinselection.cpp +++ b/muts/coinselection.mutant.39.cpp @@ -129,7 +129,7 @@ util::Result<SelectionResult> SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool (curr_waste > best_waste && is_feerate_high)) { // Don't select things which we know will be more wasteful if the waste is increasing backtrack = true; } else if (curr_selection_weight > max_selection_weight) { // Selected UTXOs weight exceeds the maximum weight allowed, cannot find more solutions by adding more inputs - max_tx_weight_exceeded = true; // at least one selection attempt exceeded the max weight + max_tx_weight_exceeded = false; // at least one selection attempt exceeded the max weight backtrack = true; } else if (curr_value >= selection_target) { // Selected value is within range curr_waste += (curr_value - selection_target); // This is the excess value which is added to the waste for the below comparison
This commit is contained in:
@@ -109,9 +109,12 @@ static void TestBnBSuccess(std::string test_title, std::vector<OutputGroup>& utx
|
||||
BOOST_CHECK_MESSAGE(result->GetSelectedValue() == expected_amount, strprintf("Selected amount mismatch in BnB-Success: %s. Expected %d, but got %d", test_title, expected_amount, result->GetSelectedValue()));
|
||||
}
|
||||
|
||||
static void TestBnBFail(std::string test_title, std::vector<OutputGroup>& utxo_pool, const CAmount& selection_target)
|
||||
static void TestBnBFail(std::string test_title, std::vector<OutputGroup>& utxo_pool, const CAmount& selection_target, const bool expect_max_weight_exceeded = false)
|
||||
{
|
||||
BOOST_CHECK_MESSAGE(!SelectCoinsBnB(utxo_pool, selection_target, /*cost_of_change=*/default_cs_params.m_cost_of_change, /*max_selection_weight=*/MAX_STANDARD_TX_WEIGHT), "BnB-Fail: " + test_title);
|
||||
const auto result = SelectCoinsBnB(utxo_pool, selection_target, /*cost_of_change=*/default_cs_params.m_cost_of_change, /*max_selection_weight=*/MAX_STANDARD_TX_WEIGHT);
|
||||
BOOST_CHECK_MESSAGE(!result, "BnB-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(bnb_test)
|
||||
|
Reference in New Issue
Block a user