Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/coinselector_tests.cpp
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | for (auto &coin : coins) { | ||||
0); | 0); | ||||
} | } | ||||
return static_groups; | return static_groups; | ||||
} | } | ||||
// Branch and bound coin selection tests | // Branch and bound coin selection tests | ||||
BOOST_AUTO_TEST_CASE(bnb_search_test) { | BOOST_AUTO_TEST_CASE(bnb_search_test) { | ||||
LOCK(m_wallet.cs_wallet); | LOCK(m_wallet.cs_wallet); | ||||
m_wallet.SetupLegacyScriptPubKeyMan(); | |||||
// Setup | // Setup | ||||
std::vector<CInputCoin> utxo_pool; | std::vector<CInputCoin> utxo_pool; | ||||
CoinSet selection; | CoinSet selection; | ||||
CoinSet actual_selection; | CoinSet actual_selection; | ||||
Amount value_ret = Amount::zero(); | Amount value_ret = Amount::zero(); | ||||
Amount not_input_fees = Amount::zero(); | Amount not_input_fees = Amount::zero(); | ||||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(knapsack_solver_test) { | ||||
CWallet testWallet(Params(), testChain.get(), WalletLocation(), | CWallet testWallet(Params(), testChain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
CoinSet setCoinsRet, setCoinsRet2; | CoinSet setCoinsRet, setCoinsRet2; | ||||
Amount nValueRet; | Amount nValueRet; | ||||
bool bnb_used; | bool bnb_used; | ||||
LOCK(testWallet.cs_wallet); | LOCK(testWallet.cs_wallet); | ||||
testWallet.SetupLegacyScriptPubKeyMan(); | |||||
// test multiple times to allow for differences in the shuffle order | // test multiple times to allow for differences in the shuffle order | ||||
for (int i = 0; i < RUN_TESTS; i++) { | for (int i = 0; i < RUN_TESTS; i++) { | ||||
empty_wallet(); | empty_wallet(); | ||||
// with an empty wallet we can't even pay one cent | // with an empty wallet we can't even pay one cent | ||||
BOOST_CHECK(!testWallet.SelectCoinsMinConf( | BOOST_CHECK(!testWallet.SelectCoinsMinConf( | ||||
1 * CENT, filter_standard, GroupCoins(vCoins), setCoinsRet, | 1 * CENT, filter_standard, GroupCoins(vCoins), setCoinsRet, | ||||
▲ Show 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
BOOST_AUTO_TEST_CASE(ApproximateBestSubset) { | BOOST_AUTO_TEST_CASE(ApproximateBestSubset) { | ||||
CoinSet setCoinsRet; | CoinSet setCoinsRet; | ||||
Amount nValueRet; | Amount nValueRet; | ||||
bool bnb_used; | bool bnb_used; | ||||
LOCK(m_wallet.cs_wallet); | LOCK(m_wallet.cs_wallet); | ||||
m_wallet.SetupLegacyScriptPubKeyMan(); | |||||
empty_wallet(); | empty_wallet(); | ||||
// Test vValue sort order | // Test vValue sort order | ||||
for (int i = 0; i < 1000; i++) { | for (int i = 0; i < 1000; i++) { | ||||
add_coin(m_wallet, 1000 * COIN); | add_coin(m_wallet, 1000 * COIN); | ||||
} | } | ||||
add_coin(m_wallet, 3 * COIN); | add_coin(m_wallet, 3 * COIN); | ||||
BOOST_CHECK(m_wallet.SelectCoinsMinConf( | BOOST_CHECK(m_wallet.SelectCoinsMinConf( | ||||
1003 * COIN, filter_standard, GroupCoins(vCoins), setCoinsRet, | 1003 * COIN, filter_standard, GroupCoins(vCoins), setCoinsRet, | ||||
nValueRet, coin_selection_params, bnb_used)); | nValueRet, coin_selection_params, bnb_used)); | ||||
BOOST_CHECK_EQUAL(nValueRet, 1003 * COIN); | BOOST_CHECK_EQUAL(nValueRet, 1003 * COIN); | ||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); | BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); | ||||
empty_wallet(); | empty_wallet(); | ||||
} | } | ||||
// Tests that with the ideal conditions, the coin selector will always be able | // Tests that with the ideal conditions, the coin selector will always be able | ||||
// to find a solution that can pay the target value | // to find a solution that can pay the target value | ||||
BOOST_AUTO_TEST_CASE(SelectCoins_test) { | BOOST_AUTO_TEST_CASE(SelectCoins_test) { | ||||
auto testChain = interfaces::MakeChain(testNode, Params()); | auto testChain = interfaces::MakeChain(testNode, Params()); | ||||
CWallet testWallet(Params(), testChain.get(), WalletLocation(), | CWallet testWallet(Params(), testChain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
testWallet.SetupLegacyScriptPubKeyMan(); | |||||
// Random generator stuff | // Random generator stuff | ||||
std::default_random_engine generator; | std::default_random_engine generator; | ||||
std::exponential_distribution<double> distribution(100); | std::exponential_distribution<double> distribution(100); | ||||
FastRandomContext rand; | FastRandomContext rand; | ||||
// Run this test 100 times | // Run this test 100 times | ||||
for (int i = 0; i < 100; ++i) { | for (int i = 0; i < 100; ++i) { | ||||
Show All 34 Lines |