Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/coinselector_tests.cpp
Show First 20 Lines • Show All 324 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(bnb_search_test) { | ||||
BOOST_CHECK(m_wallet.SelectCoinsMinConf( | BOOST_CHECK(m_wallet.SelectCoinsMinConf( | ||||
1 * CENT, filter_standard, GroupCoins(vCoins), setCoinsRet, nValueRet, | 1 * CENT, filter_standard, GroupCoins(vCoins), setCoinsRet, nValueRet, | ||||
coin_selection_params_bnb, bnb_used)); | coin_selection_params_bnb, bnb_used)); | ||||
BOOST_CHECK_EQUAL(nValueRet, 1 * CENT); | BOOST_CHECK_EQUAL(nValueRet, 1 * CENT); | ||||
// Make sure that can use BnB when there are preset inputs | // Make sure that can use BnB when there are preset inputs | ||||
empty_wallet(); | empty_wallet(); | ||||
{ | { | ||||
auto wallet = | auto wallet = std::make_unique<CWallet>(m_chain.get(), WalletLocation(), | ||||
std::make_unique<CWallet>(Params(), m_chain.get(), WalletLocation(), | |||||
WalletDatabase::CreateMock()); | WalletDatabase::CreateMock()); | ||||
bool firstRun; | bool firstRun; | ||||
wallet->LoadWallet(firstRun); | wallet->LoadWallet(firstRun); | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
wallet->SetupLegacyScriptPubKeyMan(); | wallet->SetupLegacyScriptPubKeyMan(); | ||||
add_coin(*wallet, 5 * CENT, 6 * 24, false, 0, true); | add_coin(*wallet, 5 * CENT, 6 * 24, false, 0, true); | ||||
add_coin(*wallet, 3 * CENT, 6 * 24, false, 0, true); | add_coin(*wallet, 3 * CENT, 6 * 24, false, 0, true); | ||||
add_coin(*wallet, 2 * CENT, 6 * 24, false, 0, true); | add_coin(*wallet, 2 * CENT, 6 * 24, false, 0, true); | ||||
CCoinControl coin_control; | CCoinControl coin_control; | ||||
coin_control.fAllowOtherInputs = true; | coin_control.fAllowOtherInputs = true; | ||||
coin_control.Select( | coin_control.Select( | ||||
COutPoint(vCoins.at(0).tx->GetId(), vCoins.at(0).i)); | COutPoint(vCoins.at(0).tx->GetId(), vCoins.at(0).i)); | ||||
coin_selection_params_bnb.effective_fee = CFeeRate(Amount::zero()); | coin_selection_params_bnb.effective_fee = CFeeRate(Amount::zero()); | ||||
BOOST_CHECK(wallet->SelectCoins(vCoins, 10 * CENT, setCoinsRet, | BOOST_CHECK(wallet->SelectCoins(vCoins, 10 * CENT, setCoinsRet, | ||||
nValueRet, coin_control, | nValueRet, coin_control, | ||||
coin_selection_params_bnb, bnb_used)); | coin_selection_params_bnb, bnb_used)); | ||||
BOOST_CHECK(bnb_used); | BOOST_CHECK(bnb_used); | ||||
BOOST_CHECK(coin_selection_params_bnb.use_bnb); | BOOST_CHECK(coin_selection_params_bnb.use_bnb); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(knapsack_solver_test) { | BOOST_AUTO_TEST_CASE(knapsack_solver_test) { | ||||
auto testChain = interfaces::MakeChain(testNode, Params()); | auto testChain = interfaces::MakeChain(testNode, Params()); | ||||
CWallet testWallet(Params(), testChain.get(), WalletLocation(), | CWallet testWallet(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(); | testWallet.SetupLegacyScriptPubKeyMan(); | ||||
▲ Show 20 Lines • Show All 414 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(ApproximateBestSubset) { | ||||
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(testChain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
testWallet.SetupLegacyScriptPubKeyMan(); | 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; | ||||
Show All 36 Lines |