From fc0f52d78085b6ef97d6821fc7592326c2d9b495 Mon Sep 17 00:00:00 2001 From: Murch Date: Mon, 7 Dec 2015 00:15:36 +0100 Subject: [PATCH] Added a test for the pruning of extraneous inputs after ApproximateBestSet --- src/wallet/test/wallet_tests.cpp | 18 ++++++++++++++++++ src/wallet/wallet.cpp | 14 ++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 8b9292bd1..5e8ccd90a 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -328,4 +328,22 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) 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() diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f9e8a97ae..a262769c4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1605,7 +1605,7 @@ static void ApproximateBestSubset(vector= nTargetValue ) - { - vfBest[i] = false; - nBest -= vValue[i].first; - } + if (vfBest[i] && (nBest - vValue[i].first) >= nTargetValue ) + { + vfBest[i] = false; + nBest -= vValue[i].first; + } } }