mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Added a test for the pruning of extraneous inputs after ApproximateBestSet
This commit is contained in:
parent
af9510e037
commit
fc0f52d780
@ -328,4 +328,22 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
|||||||
empty_wallet();
|
empty_wallet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(pruning_in_ApproximateBestSet)
|
||||||
|
{
|
||||||
|
CoinSet setCoinsRet;
|
||||||
|
CAmount nValueRet;
|
||||||
|
|
||||||
|
LOCK(wallet.cs_wallet);
|
||||||
|
|
||||||
|
empty_wallet();
|
||||||
|
for (int i = 0; i < 12; i++)
|
||||||
|
{
|
||||||
|
add_coin(10*CENT);
|
||||||
|
}
|
||||||
|
add_coin(100*CENT);
|
||||||
|
add_coin(100*CENT);
|
||||||
|
BOOST_CHECK(wallet.SelectCoinsMinConf(221*CENT, 1, 6, vCoins, setCoinsRet, nValueRet));
|
||||||
|
BOOST_CHECK_EQUAL(nValueRet, 230*CENT);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
@ -1605,7 +1605,7 @@ static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,uns
|
|||||||
bool fReachedTarget = false;
|
bool fReachedTarget = false;
|
||||||
for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
|
for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < vValue.size() && !fReachedTarget; i++)
|
for (unsigned int i = 0; i < vValue.size(); i++)
|
||||||
{
|
{
|
||||||
//The solver here uses a randomized algorithm,
|
//The solver here uses a randomized algorithm,
|
||||||
//the randomness serves no real security purpose but is just
|
//the randomness serves no real security purpose but is just
|
||||||
@ -1625,6 +1625,8 @@ static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,uns
|
|||||||
nBest = nTotal;
|
nBest = nTotal;
|
||||||
vfBest = vfIncluded;
|
vfBest = vfIncluded;
|
||||||
}
|
}
|
||||||
|
nTotal -= vValue[i].first;
|
||||||
|
vfIncluded[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1634,11 +1636,11 @@ static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,uns
|
|||||||
//Reduces the approximate best subset by removing any inputs that are smaller than the surplus of nTotal beyond nTargetValue.
|
//Reduces the approximate best subset by removing any inputs that are smaller than the surplus of nTotal beyond nTargetValue.
|
||||||
for (unsigned int i = 0; i < vValue.size(); i++)
|
for (unsigned int i = 0; i < vValue.size(); i++)
|
||||||
{
|
{
|
||||||
if (vfBest[i] && (nBest - vValue[i].first) >= nTargetValue )
|
if (vfBest[i] && (nBest - vValue[i].first) >= nTargetValue )
|
||||||
{
|
{
|
||||||
vfBest[i] = false;
|
vfBest[i] = false;
|
||||||
nBest -= vValue[i].first;
|
nBest -= vValue[i].first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user