test: Recreate BnB clone skipping test

This commit is contained in:
Murch 2024-06-27 11:50:15 -04:00
parent 0ccf142ad6
commit 3921017ff2
No known key found for this signature in database
GPG key ID: 7BA035CA5B901713
2 changed files with 13 additions and 20 deletions

View file

@ -62,6 +62,13 @@ static void AddCoins(std::vector<OutputGroup>& utxo_pool, std::vector<CAmount> c
}
}
/** Make multiple coins that share the same effective value */
static void AddDuplicateCoins(std::vector<OutputGroup>& utxo_pool, int count, int amount) {
for (int i = 0 ; i < count; ++i) {
utxo_pool.push_back(MakeCoin(amount));
}
}
/** Check if SelectionResult a is equivalent to SelectionResult b.
* Two results are equivalent if they are composed of the same input values, even if they have different inputs (i.e., same value, different prevout) */
static bool HaveEquivalentValues(const SelectionResult& a, const SelectionResult& b)
@ -121,6 +128,12 @@ BOOST_AUTO_TEST_CASE(bnb_test)
// BnB finds changeless solution while overshooting by up to cost_of_change
TestBnBSuccess("Select upper bound", utxo_pool, /*selection_target=*/4 * CENT - default_cs_params.m_cost_of_change, /*expected_input_amounts=*/{1 * CENT, 3 * CENT});
// Test skipping of equivalent input sets
std::vector<OutputGroup> clone_pool;
AddCoins(clone_pool, {2 * CENT, 7 * CENT, 7 * CENT});
AddDuplicateCoins(clone_pool, 50'000, 5 * CENT);
TestBnBSuccess("Skip equivalent input sets", clone_pool, /*selection_target=*/16 * CENT, /*expected_input_amounts=*/{2 * CENT, 7 * CENT, 7 * CENT});
}
BOOST_AUTO_TEST_CASE(bnb_feerate_sensitivity_test)

View file

@ -227,26 +227,6 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
const auto result7 = SelectCoinsBnB(GroupCoins(utxo_pool), target, 1); // Should not exhaust
BOOST_CHECK(result7);
// Test same value early bailout optimization
utxo_pool.clear();
add_coin(7 * CENT, 7, expected_result);
add_coin(7 * CENT, 7, expected_result);
add_coin(7 * CENT, 7, expected_result);
add_coin(7 * CENT, 7, expected_result);
add_coin(2 * CENT, 7, expected_result);
add_coin(7 * CENT, 7, utxo_pool);
add_coin(7 * CENT, 7, utxo_pool);
add_coin(7 * CENT, 7, utxo_pool);
add_coin(7 * CENT, 7, utxo_pool);
add_coin(2 * CENT, 7, utxo_pool);
for (int i = 0; i < 50000; ++i) {
add_coin(5 * CENT, 7, utxo_pool);
}
const auto result8 = SelectCoinsBnB(GroupCoins(utxo_pool), 30 * CENT, 5000);
BOOST_CHECK(result8);
BOOST_CHECK_EQUAL(result8->GetSelectedValue(), 30 * CENT);
BOOST_CHECK(EquivalentResult(expected_result, *result8));
////////////////////
// Behavior tests //
////////////////////