Skip to content

Commit a94030a

Browse files
committed
test: Recreate BnB clone skipping test
1 parent 7db6f01 commit a94030a

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/wallet/test/coinselection_tests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ static void AddCoins(std::vector<OutputGroup>& utxo_pool, std::vector<CAmount> c
6262
}
6363
}
6464

65+
/** Make multiple coins that share the same effective value */
66+
static void AddDuplicateCoins(std::vector<OutputGroup>& utxo_pool, int count, int amount) {
67+
for (int i = 0 ; i < count; ++i) {
68+
utxo_pool.push_back(MakeCoin(amount));
69+
}
70+
}
71+
6572
/** Check if SelectionResult a is equivalent to SelectionResult b.
6673
* 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) */
6774
static bool HaveEquivalentValues(const SelectionResult& a, const SelectionResult& b)
@@ -116,6 +123,12 @@ BOOST_AUTO_TEST_CASE(bnb_test)
116123

117124
// BnB finds changeless solution while overshooting by up to cost_of_change
118125
TestBnBSuccess("Select upper bound", utxo_pool, /*selection_target=*/4 * CENT - default_cs_params.m_cost_of_change, /*expected_input_amounts=*/{1 * CENT, 3 * CENT});
126+
127+
// Test skipping of equivalent input sets
128+
std::vector<OutputGroup> clone_pool;
129+
AddCoins(clone_pool, {2 * CENT, 7 * CENT, 7 * CENT});
130+
AddDuplicateCoins(clone_pool, 50'000, 5 * CENT);
131+
TestBnBSuccess("Skip equivalent input sets", clone_pool, /*selection_target=*/16 * CENT, /*expected_input_amounts=*/{2 * CENT, 7 * CENT, 7 * CENT});
119132
}
120133

121134
BOOST_AUTO_TEST_CASE(bnb_feerate_sensitivity_test)

src/wallet/test/coinselector_tests.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -227,26 +227,6 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
227227
const auto result7 = SelectCoinsBnB(GroupCoins(utxo_pool), target, 1); // Should not exhaust
228228
BOOST_CHECK(result7);
229229

230-
// Test same value early bailout optimization
231-
utxo_pool.clear();
232-
add_coin(7 * CENT, 7, expected_result);
233-
add_coin(7 * CENT, 7, expected_result);
234-
add_coin(7 * CENT, 7, expected_result);
235-
add_coin(7 * CENT, 7, expected_result);
236-
add_coin(2 * CENT, 7, expected_result);
237-
add_coin(7 * CENT, 7, utxo_pool);
238-
add_coin(7 * CENT, 7, utxo_pool);
239-
add_coin(7 * CENT, 7, utxo_pool);
240-
add_coin(7 * CENT, 7, utxo_pool);
241-
add_coin(2 * CENT, 7, utxo_pool);
242-
for (int i = 0; i < 50000; ++i) {
243-
add_coin(5 * CENT, 7, utxo_pool);
244-
}
245-
const auto result8 = SelectCoinsBnB(GroupCoins(utxo_pool), 30 * CENT, 5000);
246-
BOOST_CHECK(result8);
247-
BOOST_CHECK_EQUAL(result8->GetSelectedValue(), 30 * CENT);
248-
BOOST_CHECK(EquivalentResult(expected_result, *result8));
249-
250230
////////////////////
251231
// Behavior tests //
252232
////////////////////

0 commit comments

Comments
 (0)