Skip to content

Commit

Permalink
WHY YOU TAKE TEN INSTEAD OF 2,3,5?
Browse files Browse the repository at this point in the history
Intent here is to remove the two tests that are on the combined
selection level that should just be BnB behavior tests, that fail when
SFFO causes BnB to be skipped
  • Loading branch information
murchandamus committed Nov 9, 2023
1 parent f9cf973 commit ebb5cee
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/wallet/test/coinselection_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ static COutput MakeCoin(const CAmount& amount, bool is_eff_value = true, int nIn
return COutput{COutPoint(tx.GetHash(), nInput), tx.vout.at(nInput), /*depth=*/ 1, /*input_bytes=*/ custom_spending_vsize, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, /*time=*/ 0, /*from_me=*/ false, /*fees=*/ fees};
}

static void AddCoins(std::vector<COutput>& utxo_pool, std::vector<CAmount> coins) {
static void AddCoins(std::vector<COutput>& utxo_pool, std::vector<CAmount> coins, CFeeRate feerate = default_cs_params.m_effective_feerate) {
for (int c : coins) {
utxo_pool.push_back(MakeCoin(c));
utxo_pool.push_back(MakeCoin(c, true, 0, feerate));
}
}

Expand All @@ -103,13 +103,13 @@ std::optional<SelectionResult> SelectCoinsBnB(std::vector<COutput>& utxo_pool, c
return res ? std::optional<SelectionResult>(*res) : std::nullopt;
}

static void TestBnBSuccess(std::string test_title, std::vector<COutput>& utxo_pool, const CAmount& selection_target, const std::vector<CAmount>& expected_input_amounts)
static void TestBnBSuccess(std::string test_title, std::vector<COutput>& utxo_pool, const CAmount& selection_target, const std::vector<CAmount>& expected_input_amounts, const CFeeRate& feerate = default_cs_params.m_effective_feerate )
{
SelectionResult expected_result(CAmount(0), SelectionAlgorithm::BNB);
CAmount expected_amount = 0;
for (int input_amount : expected_input_amounts) {
OutputGroup group;
COutput coin = MakeCoin(input_amount);
COutput coin = MakeCoin(input_amount, true, 0, feerate);
expected_amount += coin.txout.nValue;
group.Insert(std::make_shared<COutput>(coin), /*ancestors=*/ 0, /*descendants=*/ 0);
expected_result.AddInput(group);
Expand Down Expand Up @@ -138,5 +138,18 @@ BOOST_AUTO_TEST_CASE(bnb_test)
TestBnBSuccess("Select upper bound", utxo_pool, /*selection_target=*/ 9 * CENT - default_cs_params.m_cost_of_change, /*expected_input_amounts=*/ {1 * CENT, 3 * CENT, 5 * CENT});
}

BOOST_AUTO_TEST_CASE(bnb_feerate_sensitivity_test)
{
// Create sets of UTXOs with the same effective amounts at different feerates (but different absolute amounts)
std::vector<COutput> low_feerate_pool; // 5 sat/vB
AddCoins(low_feerate_pool, {2 * CENT, 3 * CENT, 5 * CENT, 10 * CENT});
TestBnBSuccess("Select many inputs at low feerates", low_feerate_pool, /*selection_target=*/ 10 * CENT, /*expected_input_amounts=*/ {10 * CENT});
// TestBnBSuccess("Select many inputs at low feerates", low_feerate_pool, /*selection_target=*/ 10 * CENT, /*expected_input_amounts=*/ {2 * CENT, 3 * CENT, 5 * CENT});

std::vector<COutput> high_feerate_pool; // 25 sat/vB
AddCoins(high_feerate_pool, {2 * CENT, 3 * CENT, 5 * CENT, 10 * CENT}, CFeeRate{25'000});
TestBnBSuccess("Select one input at high feerates", high_feerate_pool, /*selection_target=*/ 10 * CENT, /*expected_input_amounts=*/ {10 * CENT}, CFeeRate{25'000});
}

BOOST_AUTO_TEST_SUITE_END()
} // namespace wallet

0 comments on commit ebb5cee

Please sign in to comment.