[wallet] Add regression test for vValue sort order

- [wallet] Add regression test for vValue sort order
- [trivial] Merge test cases and replace CENT with COIN

Github-Pull: #7293
Rebased-From: fa3c7e644f427329bcffa1a5600fdbd7e97c837f faf538bfdbb4ecebde73e95c80718c2d9ecee1f5
This commit is contained in:
MarcoFalke 2016-01-05 00:38:12 +01:00 committed by Wladimir J. van der Laan
parent 1ed938b5fe
commit ff9b610026
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6

View File

@ -328,7 +328,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
empty_wallet();
}
BOOST_AUTO_TEST_CASE(pruning_in_ApproximateBestSet)
BOOST_AUTO_TEST_CASE(ApproximateBestSubset)
{
CoinSet setCoinsRet;
CAmount nValueRet;
@ -336,15 +336,28 @@ BOOST_AUTO_TEST_CASE(pruning_in_ApproximateBestSet)
LOCK(wallet.cs_wallet);
empty_wallet();
for (int i = 0; i < 100; i++)
add_coin(10 * CENT);
for (int i = 0; i < 100; i++)
add_coin(1000 * CENT);
BOOST_CHECK(wallet.SelectCoinsMinConf(100001 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet));
// Test vValue sort order
for (int i = 0; i < 1000; i++)
add_coin(1000 * COIN);
add_coin(3 * COIN);
BOOST_CHECK(wallet.SelectCoinsMinConf(1003 * COIN, 1, 6, vCoins, setCoinsRet, nValueRet));
BOOST_CHECK_EQUAL(nValueRet, 1003 * COIN);
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U);
empty_wallet();
// Test trimming
for (int i = 0; i < 100; i++)
add_coin(10 * COIN);
for (int i = 0; i < 100; i++)
add_coin(1000 * COIN);
BOOST_CHECK(wallet.SelectCoinsMinConf(100001 * COIN, 1, 6, vCoins, setCoinsRet, nValueRet));
// We need all 100 larger coins and exactly one small coin.
// Superfluous small coins must be pruned:
BOOST_CHECK_EQUAL(nValueRet, 100010 * CENT);
// Superfluous small coins must be trimmed from the set:
BOOST_CHECK_EQUAL(nValueRet, 100010 * COIN);
BOOST_CHECK_EQUAL(setCoinsRet.size(), 101);
}