5#include <chainparams.h>
15#include <test/util/setup_common.h>
18#include <boost/test/unit_test.hpp>
32#define RANDOM_REPEATS 5
47 std::vector<CInputCoin> &
set) {
100 std::pair<CoinSet::iterator, CoinSet::iterator>
ret =
102 return ret.first ==
a.end() &&
ret.second ==
b.end();
108 for (
int i = 0; i <
utxos; ++i) {
118inline std::vector<OutputGroup> &
122 for (
auto &coin : coins) {
129inline std::vector<OutputGroup> &
GroupCoins(
const std::vector<COutput> &coins) {
132 for (
auto &coin : coins) {
149 m_wallet.SetupLegacyScriptPubKeyMan();
277 for (
int i = 0; i < 50000; ++i) {
290 for (
int i = 5; i <= 20; ++i) {
294 for (
int i = 0; i < 100; ++i) {
310 vCoins.at(0).nInputBytes = 40;
318 vCoins.at(0).nInputBytes = 40;
331 auto wallet = std::make_unique<CWallet>(
m_node.chain.get(),
"",
336 wallet->SetupLegacyScriptPubKeyMan();
588 for (
int j = 0;
j < 20;
j++) {
689 for (
int i2 = 0;
i2 < 100;
i2++) {
762 m_wallet.SetupLegacyScriptPubKeyMan();
767 for (
int i = 0; i < 1000; i++) {
790 std::exponential_distribution<double>
distribution(100);
794 for (
int i = 0; i < 100; ++i) {
798 for (
int j = 0;
j < 1000; ++
j) {
static constexpr Amount SATOSHI
static constexpr Amount COIN
const CChainParams & Params()
Return the currently selected parameters.
bool fAllowOtherInputs
If false, allows unselected inputs, but requires all selected inputs be used.
Fee rate in satoshis per kilobyte: Amount / kB.
A mutable version of CTransaction.
std::vector< CTxOut > vout
An outpoint - a combination of a transaction hash and an index n into its vout.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]
bool m_is_cache_empty
This flag is true if all m_amounts caches are empty.
std::set< CInputCoin > CoinSet
static void ApproximateBestSubset(const std::vector< OutputGroup > &groups, const Amount &nTotalLower, const Amount &nTargetValue, std::vector< char > &vfBest, Amount &nBest, int iterations=1000)
bool SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const Amount &target_value, const Amount &cost_of_change, std::set< CInputCoin > &out_set, Amount &value_ret, const Amount not_input_fees)
This is the Branch and Bound Coin Selection algorithm designed by Murch.
static constexpr Amount MIN_CHANGE
target minimum change amount
CoinEligibilityFilter filter_standard_extra(6, 6)
static std::vector< COutput > vCoins
static void empty_wallet()
static node::NodeContext testNode
BOOST_AUTO_TEST_CASE(bnb_search_test)
CoinSelectionParams coin_selection_params(false, 0, 0, CFeeRate(Amount::zero()), 0, false)
static bool equal_sets(CoinSet a, CoinSet b)
std::set< CInputCoin > CoinSet
std::vector< OutputGroup > & GroupCoins(const std::vector< CInputCoin > &coins)
CoinEligibilityFilter filter_standard(1, 6)
CoinEligibilityFilter filter_confirmed(1, 1)
static Amount make_hard_case(int utxos, std::vector< CInputCoin > &utxo_pool)
static void add_coin(const Amount nValue, int nInput, std::vector< CInputCoin > &set)
bool error(const char *fmt, const Args &...args)
std::unique_ptr< Chain > MakeChain(node::NodeContext &node, const CChainParams ¶ms)
Return implementation of Chain interface.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static CTransactionRef MakeTransactionRef()
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
bool SelectCoinsMinConf(const CWallet &wallet, const Amount nTargetValue, const CoinEligibilityFilter &eligibility_filter, std::vector< COutput > coins, std::set< CInputCoin > &setCoinsRet, Amount &nValueRet, const CoinSelectionParams &coin_selection_params, bool &bnb_used)
Shuffle and select coins until nTargetValue is reached while avoiding small change; This method is st...
bool SelectCoins(const CWallet &wallet, const std::vector< COutput > &vAvailableCoins, const Amount nTargetValue, std::set< CInputCoin > &setCoinsRet, Amount &nValueRet, const CCoinControl &coin_control, CoinSelectionParams &coin_selection_params, bool &bnb_used)
Select a set of coins such that nValueRet >= nTargetValue and at least all coins from coin_control ar...
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
void Set(isminefilter filter, Amount value)
Testing setup and teardown for wallet.
NodeContext struct containing references to chain state and connection state.
std::shared_ptr< CWallet > m_wallet
std::unique_ptr< WalletDatabase > CreateDummyWalletDatabase()
Return object for accessing dummy database with no read/write capabilities.
std::unique_ptr< WalletDatabase > CreateMockWalletDatabase()
Return object for accessing temporary in-memory database.