mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 20:32:35 -03:00
Test that BnB is not used when there are preset inputs
This commit is contained in:
parent
6ef99826b9
commit
081bf54ee4
2 changed files with 23 additions and 10 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "wallet/wallet.h"
|
||||
#include "wallet/coinselection.h"
|
||||
#include "wallet/coincontrol.h"
|
||||
#include "amount.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "random.h"
|
||||
|
@ -27,7 +28,7 @@ std::vector<std::unique_ptr<CWalletTx>> wtxn;
|
|||
typedef std::set<CInputCoin> CoinSet;
|
||||
|
||||
static std::vector<COutput> vCoins;
|
||||
static const CWallet testWallet("dummy", CWalletDBWrapper::CreateDummy());
|
||||
static CWallet testWallet("dummy", CWalletDBWrapper::CreateDummy());
|
||||
static CAmount balance = 0;
|
||||
|
||||
CoinEligibilityFilter filter_standard(1, 6, 0);
|
||||
|
@ -72,6 +73,7 @@ static void add_coin(const CAmount& nValue, int nAge = 6*24, bool fIsFromMe = fa
|
|||
}
|
||||
COutput output(wtx.get(), nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */);
|
||||
vCoins.push_back(output);
|
||||
testWallet.AddToWallet(*wtx.get());
|
||||
wtxn.emplace_back(std::move(wtx));
|
||||
}
|
||||
|
||||
|
@ -222,6 +224,18 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
|
|||
add_coin(1);
|
||||
vCoins.at(0).nInputBytes = 40; // Make sure that it has a negative effective value. The next check should assert if this somehow got through. Otherwise it will fail
|
||||
BOOST_CHECK(!testWallet.SelectCoinsMinConf( 1 * CENT, filter_standard, vCoins, setCoinsRet, nValueRet, coin_selection_params_bnb, bnb_used));
|
||||
|
||||
// Make sure that we aren't using BnB when there are preset inputs
|
||||
empty_wallet();
|
||||
add_coin(5 * CENT);
|
||||
add_coin(3 * CENT);
|
||||
add_coin(2 * CENT);
|
||||
CCoinControl coin_control;
|
||||
coin_control.fAllowOtherInputs = true;
|
||||
coin_control.Select(COutPoint(vCoins.at(0).tx->GetHash(), vCoins.at(0).i));
|
||||
BOOST_CHECK(testWallet.SelectCoins(vCoins, 10 * CENT, setCoinsRet, nValueRet, coin_control, coin_selection_params_bnb, bnb_used));
|
||||
BOOST_CHECK(!bnb_used);
|
||||
BOOST_CHECK(!coin_selection_params_bnb.use_bnb);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(knapsack_solver_test)
|
||||
|
|
|
@ -667,15 +667,6 @@ private:
|
|||
std::mutex mutexScanning;
|
||||
friend class WalletRescanReserver;
|
||||
|
||||
|
||||
/**
|
||||
* Select a set of coins such that nValueRet >= nTargetValue and at least
|
||||
* all coins from coinControl are selected; Never select unconfirmed coins
|
||||
* if they are not ours
|
||||
*/
|
||||
bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet,
|
||||
const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool& bnb_used) const;
|
||||
|
||||
CWalletDB *pwalletdbEncryption;
|
||||
|
||||
//! the current wallet version: clients below this version are not able to load the wallet
|
||||
|
@ -768,6 +759,14 @@ public:
|
|||
return *dbw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a set of coins such that nValueRet >= nTargetValue and at least
|
||||
* all coins from coinControl are selected; Never select unconfirmed coins
|
||||
* if they are not ours
|
||||
*/
|
||||
bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet,
|
||||
const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool& bnb_used) const;
|
||||
|
||||
/** Get a name for this wallet for logging/debugging purposes.
|
||||
*/
|
||||
const std::string& GetName() const { return m_name; }
|
||||
|
|
Loading…
Reference in a new issue