Reworked comment around the code for identifying transactions to spend, to separate explanation of condition, and result.
Corrected comment references to "cent", with "coin" in wallet tests, to match changes to units.
This commit is contained in:
parent
eda7f83cd0
commit
71532b730d
|
@ -134,32 +134,32 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
|||
add_coin( 7*COIN);
|
||||
add_coin( 8*COIN);
|
||||
add_coin(20*COIN);
|
||||
add_coin(30*COIN); // now we have 6+7+8+20+30 = 71 cents total
|
||||
add_coin(30*COIN); // now we have 6+7+8+20+30 = 71 coins total
|
||||
|
||||
// check that we have 71 and not 72
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(71 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK(!wallet.SelectCoinsMinConf(72 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
|
||||
// now try making 16 cents. the best smaller coins can do is 6+7+8 = 21; not as good at the next biggest coin, 20
|
||||
// now try making 16 coins. the best smaller coins can do is 6+7+8 = 21; not as good at the next biggest coin, 20
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(16 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 20 * COIN); // we should get 20 in one coin
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
|
||||
|
||||
add_coin( 5*COIN); // now we have 5+6+7+8+20+30 = 75 cents total
|
||||
add_coin( 5*COIN); // now we have 5+6+7+8+20+30 = 75 coins total
|
||||
|
||||
// now if we try making 16 cents again, the smaller coins can make 5+6+7 = 18 cents, better than the next biggest coin, 20
|
||||
// now if we try making 16 coins again, the smaller coins can make 5+6+7 = 18 coins, better than the next biggest coin, 20
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(16 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 18 * COIN); // we should get 18 in 3 coins
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U);
|
||||
|
||||
add_coin( 18*COIN); // now we have 5+6+7+8+18+20+30
|
||||
|
||||
// and now if we try making 16 cents again, the smaller coins can make 5+6+7 = 18 cents, the same as the next biggest coin, 18
|
||||
// and now if we try making 16 coins again, the smaller coins can make 5+6+7 = 18 coins, the same as the next biggest coin, 18
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(16 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 18 * COIN); // we should get 18 in 1 coin
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); // because in the event of a tie, the biggest coin wins
|
||||
|
||||
// now try making 11 cents. we should get 5+6
|
||||
// now try making 11 coins. we should get 5+6
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(11 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 11 * COIN);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U);
|
||||
|
@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
|||
add_coin( 100*COIN);
|
||||
add_coin( 200*COIN);
|
||||
add_coin( 300*COIN);
|
||||
add_coin( 400*COIN); // now we have 5+6+7+8+18+20+30+100+200+300+400 = 1094 cents
|
||||
add_coin( 400*COIN); // now we have 5+6+7+8+18+20+30+100+200+300+400 = 1094 coins
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(95 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 100 * COIN); // we should get 200 DOGE in 1 coin.
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
|
||||
|
|
|
@ -1228,7 +1228,12 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
|
|||
}
|
||||
else if (n < nTargetValue + DUST_SOFT_LIMIT)
|
||||
{
|
||||
// Skip coins which, if used, would result in less than a transaction fee in change
|
||||
// This coin is not sufficient to cover the target plus change above the dust
|
||||
// limit. The dust limit is important here, as we don't want to leave change
|
||||
// which cannot be spent (is below the network transaction fee).
|
||||
|
||||
// Push the coin into an array for potential matching later, but keep trying to find
|
||||
// an exact match
|
||||
vValue.push_back(coin);
|
||||
nTotalLower += n;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue