0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

Merge bitcoin/bitcoin#24820: test: 3 new tests for SelectCoins function

3f8def51d5 add 3 new test cases for SelectCoins() (akankshakashyap)

Pull request description:

  Three new tests have been added.

  1. More coins should be selected when effective fee < long term fee.
  2. Less coin should be selected when effective fee > long term fee.
  3. If a coin is preselected, it should be selected even if disadvantageous.

ACKs for top commit:
  achow101:
    ACK 3f8def51d5
  brunoerg:
    ACK 3f8def51d5

Tree-SHA512: 8db6dd942b02a38c99953b801605f98c4c17729768fdfcf7605c5bbdb17509500a39d0a78a4b19aab37812d2994ec7630d2b4e78d1d348f1c27b67588d74e155
This commit is contained in:
Andrew Chow 2022-05-20 11:29:47 -04:00
commit 3aa851ad2a
No known key found for this signature in database
GPG key ID: 17565732E08E5E41

View file

@ -344,6 +344,48 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
const auto result10 = SelectCoins(*wallet, coins, 10 * CENT, coin_control, coin_selection_params_bnb);
BOOST_CHECK(result10);
}
{
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase());
wallet->LoadWallet();
LOCK(wallet->cs_wallet);
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
wallet->SetupDescriptorScriptPubKeyMans();
std::vector<COutput> coins;
add_coin(coins, *wallet, 10 * CENT, 6 * 24, false, 0, true);
add_coin(coins, *wallet, 9 * CENT, 6 * 24, false, 0, true);
add_coin(coins, *wallet, 1 * CENT, 6 * 24, false, 0, true);
// single coin should be selected when effective fee > long term fee
expected_result.Clear();
add_coin(10 * CENT, 2, expected_result);
CCoinControl coin_control;
coin_selection_params_bnb.m_effective_feerate = CFeeRate(5000);
coin_selection_params_bnb.m_long_term_feerate = CFeeRate(3000);
const auto result11 = SelectCoins(*wallet, coins, 10 * CENT, coin_control, coin_selection_params_bnb);
BOOST_CHECK(EquivalentResult(expected_result, *result11));
// more coins should be selected when effective fee < long term fee
expected_result.Clear();
add_coin(9 * CENT, 2, expected_result);
add_coin(1 * CENT, 2, expected_result);
coin_selection_params_bnb.m_effective_feerate = CFeeRate(3000);
coin_selection_params_bnb.m_long_term_feerate = CFeeRate(5000);
const auto result12 = SelectCoins(*wallet, coins, 10 * CENT, coin_control, coin_selection_params_bnb);
BOOST_CHECK(EquivalentResult(expected_result, *result12));
// pre selected coin should be selected even if disadvantageous
expected_result.Clear();
add_coin(9 * CENT, 2, expected_result);
add_coin(1 * CENT, 2, expected_result);
coin_control.fAllowOtherInputs = true;
coin_control.Select(coins.at(1).outpoint); // pre select 9 coin
coin_selection_params_bnb.m_effective_feerate = CFeeRate(5000);
coin_selection_params_bnb.m_long_term_feerate = CFeeRate(3000);
const auto result13 = SelectCoins(*wallet, coins, 10 * CENT, coin_control, coin_selection_params_bnb);
BOOST_CHECK(EquivalentResult(expected_result, *result13));
}
}
BOOST_AUTO_TEST_CASE(knapsack_solver_test)