aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2022-05-20 11:29:47 -0400
committerAndrew Chow <achow101-github@achow101.com>2022-05-20 12:06:30 -0400
commit3aa851ad2ae836f2bb8071396efec8b67347adcd (patch)
tree8542d2ad54c9727440b3d73290fb804e801b67df /src
parent4d0c00dffd13df9b055dbca244783c5de9ca23a5 (diff)
parent3f8def51d53a078a5ee71ec675b5e06b784147de (diff)
downloadbitcoin-3aa851ad2ae836f2bb8071396efec8b67347adcd.tar.xz
Merge bitcoin/bitcoin#24820: test: 3 new tests for SelectCoins function
3f8def51d53a078a5ee71ec675b5e06b784147de 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 3f8def51d53a078a5ee71ec675b5e06b784147de brunoerg: ACK 3f8def51d53a078a5ee71ec675b5e06b784147de Tree-SHA512: 8db6dd942b02a38c99953b801605f98c4c17729768fdfcf7605c5bbdb17509500a39d0a78a4b19aab37812d2994ec7630d2b4e78d1d348f1c27b67588d74e155
Diffstat (limited to 'src')
-rw-r--r--src/wallet/test/coinselector_tests.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp
index 72e749477b..d851101260 100644
--- a/src/wallet/test/coinselector_tests.cpp
+++ b/src/wallet/test/coinselector_tests.cpp
@@ -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)