MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / TestBnBSuccess

Function TestBnBSuccess

src/wallet/test/coinselection_tests.cpp:115–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115static void TestBnBSuccess(std::string test_title, std::vector<OutputGroup>& utxo_pool, const CAmount& selection_target, const std::vector<CAmount>& expected_input_amounts, size_t expected_attempts, const CoinSelectionParams& cs_params = default_cs_params, const int custom_spending_vsize = P2WPKH_INPUT_VSIZE, const int max_selection_weight = MAX_STANDARD_TX_WEIGHT)
116{
117 SelectionResult expected_result(CAmount(0), SelectionAlgorithm::BNB);
118 CAmount expected_amount = 0;
119 for (CAmount input_amount : expected_input_amounts) {
120 OutputGroup group = MakeCoin(input_amount, true, cs_params, custom_spending_vsize);
121 expected_amount += group.m_value;
122 expected_result.AddInput(group);
123 }
124
125 const auto result = SelectCoinsBnB(utxo_pool, selection_target, /*cost_of_change=*/cs_params.m_cost_of_change, max_selection_weight);
126 BOOST_CHECK_MESSAGE(result, "Falsy result in BnB-Success: " + test_title);
127 BOOST_CHECK_MESSAGE(HaveEquivalentValues(expected_result, *result), strprintf("Result mismatch in BnB-Success: %s. Expected %s, but got %s", test_title, InputAmountsToString(expected_result), InputAmountsToString(*result)));
128 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()));
129 BOOST_CHECK_MESSAGE(result->GetWeight() <= max_selection_weight, strprintf("Selected weight is higher than permitted in BnB-Success: %s. Expected %d, but got %d", test_title, max_selection_weight, result->GetWeight()));
130 BOOST_CHECK_MESSAGE(result->GetSelectionsEvaluated() == expected_attempts, strprintf("Unexpected number of attempts in BnB-Success: %s. Expected %i attempts, but got %i", test_title, expected_attempts, result->GetSelectionsEvaluated()));
131}
132
133static void TestBnBFail(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)
134{

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 8

MakeCoinFunction · 0.85
HaveEquivalentValuesFunction · 0.85
InputAmountsToStringFunction · 0.85
GetSelectedValueMethod · 0.80
GetWeightMethod · 0.80
SelectCoinsBnBFunction · 0.70
AddInputMethod · 0.45

Tested by

no test coverage detected