21#include <boost/test/unit_test.hpp>
32#define RANDOM_REPEATS 5
47 group.Insert(std::make_shared<COutput>(output), 0, 0);
59 group.Insert(coin, 0, 0);
60 coin->long_term_fee = long_term_fee;
80 available_coins.Add(
OutputType::BECH32, {
COutPoint(wtx.
GetHash(),
nInput), txout,
nAge,
custom_size == 0 ?
CalculateMaximumSignedInputSize(txout, &
wallet,
nullptr) :
custom_size,
true,
true, wtx.
GetTxTime(),
fIsFromMe, feerate});
88 return res ? std::optional<SelectionResult>(*
res) : std::nullopt;
94 return res ? std::optional<SelectionResult>(*
res) : std::nullopt;
101 std::vector<CAmount>
a_amts;
102 std::vector<CAmount>
b_amts;
103 for (
const auto& coin :
a.GetInputSet()) {
104 a_amts.push_back(coin->txout.nValue);
107 b_amts.push_back(coin->txout.nValue);
112 std::pair<std::vector<CAmount>::iterator, std::vector<CAmount>::iterator>
ret = std::mismatch(
a_amts.begin(),
a_amts.end(),
b_amts.begin());
119 std::pair<OutputSet::iterator, OutputSet::iterator>
ret = std::mismatch(
a.GetInputSet().begin(),
a.GetInputSet().end(), b.
GetInputSet().begin(),
120 [](
const std::shared_ptr<COutput>&
a,
const std::shared_ptr<COutput>& b) {
121 return a->outpoint == b->outpoint;
133 group.Insert(std::make_shared<COutput>(coin), 0, 0);
163 wallet->SetupDescriptorScriptPubKeyMans();
254 expected_result.Clear();
294 expected_result.Clear();
323 params.m_subtract_fee_outputs =
true;
324 params.m_change_fee = params.m_effective_feerate.
GetFee(params.change_output_size);
325 params.m_cost_of_change = params.m_discard_feerate.GetFee(params.change_spend_size) + params.m_change_fee;
326 params.m_min_change_target = params.m_cost_of_change + 1;
514 for (
int j = 0;
j < 20;
j++)
595 for (
int i2 = 0;
i2 < 100;
i2++)
658 for (
int i = 0; i < 1000; i++)
676 std::exponential_distribution<double>
distribution (100);
680 for (
int i = 0; i < 100; ++i)
686 for (
int j = 0;
j < 1000; ++
j)
723 const CAmount min_viable_change{300};
855 const CAmount min_viable_change{200};
865 const std::vector<std::shared_ptr<COutput>> inputs =
selection.GetShuffledInputVector();
867 for (
size_t i = 0; i < inputs.size(); ++i) {
868 inputs[i]->ApplyBumpFee(20*(i+1));
891 const std::vector<std::shared_ptr<COutput>> inputs =
selection.GetShuffledInputVector();
893 for (
size_t i = 0; i < inputs.size(); ++i) {
894 inputs[i]->ApplyBumpFee(20*(i+1));
910 const int input_bytes = 148;
987 for (
int j = 0;
j < 10; ++
j) {
1005 for (
int j = 0;
j < 10; ++
j) {
1023 for (
int j = 0;
j < 60; ++
j) {
1026 for (
int i = 0; i < 10; i++) {
1032 for (
int i = 0; i < 10; ++i) {
1035 for (
int j = 0;
j < 17; ++
j) {
1074 for (
int j = 0;
j < 5; ++
j) {
1109 for (
int j = 0;
j < 100; ++
j) {
1112 for (
int j = 0;
j < 100; ++
j) {
1115 for (
int j = 0;
j < 100; ++
j) {
1118 for (
int j = 0;
j < 100; ++
j) {
1145 for (
int j = 0;
j < 100; ++
j) {
1169 for (
int i = 0; i < 18; ++i) {
1176 for (
int i = 0; i < 8; ++i) {
1187 for (
int i = 0; i < 19; ++i) {
1204 const auto signedTxSize = 10 + 34 + 68 * result->GetInputSet().size();
1214 return std::any_of(set.begin(), set.end(), [&](
const auto& coin) { return coin->GetEffectiveValue() == amount; });
1247 for (
int j = 0;
j < 1515; ++
j) {
1273 for (
int j = 0;
j < 400; ++
j) {
1276 for (
int j = 0;
j < 2000; ++
j) {
1298 for (
int j = 0;
j < 1515; ++
j) {
1362 for (
int i=0; i<10; i++) {
1370 std::unordered_set<COutPoint, SaltedOutpointHasher>
outs_to_remove;
1372 for (
int i = 0; i < 2; i++) {
1381 return coin.outpoint == out;
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
int64_t CAmount
Amount in satoshis (Can be negative)
constexpr CAmount COIN
The amount of satoshis in one BTC.
BOOST_CHECK_LT(ZeroL, OneL)
#define Assert(val)
Identity function.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
CAmount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
An outpoint - a combination of a transaction hash and an index n into its vout.
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
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.
const Txid & GetHash() const LIFETIMEBOUND
int64_t GetTxTime() const
CTransactionRef GetTx() const
constexpr int WITNESS_SCALE_FACTOR
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_GT(excessive_headers.size(), MAX_HEADERS_SIZE)
bilingual_str ErrorString(const Result< T > &result)
static const CoinEligibilityFilter filter_standard(1, 6, 0)
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase()
FilteredOutputGroups GroupOutputs(const CWallet &wallet, const CoinsResult &coins, const CoinSelectionParams &coin_sel_params, const std::vector< SelectionFilter > &filters, std::vector< OutputGroup > &ret_discarded_groups)
Group coins by the provided filters, groups that pass no filter are appended to ret_discarded_groups.
util::Result< CoinsResult > FetchSelectedInputs(const CWallet &wallet, const CCoinControl &coin_control, const CoinSelectionParams &coin_selection_params)
Fetch and validate coin control selected inputs.
BOOST_FIXTURE_TEST_CASE(wallet_coinsresult_test, BasicTestingSetup)
util::Result< SelectionResult > SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change, int max_selection_weight)
static void add_coin(const CAmount &nValue, uint32_t nInput, std::vector< OutputGroup > &set)
static std::unique_ptr< CWallet > NewWallet(const node::NodeContext &m_node, const std::string &wallet_name="")
util::Result< SelectionResult > CoinGrinder(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, CAmount change_target, int max_selection_weight)
std::vector< OutputGroup > & GroupCoins(const std::vector< COutput > &available_coins, bool subtract_fee_outputs=false)
std::vector< OutputGroup > & KnapsackGroupOutputs(const CoinsResult &available_coins, CWallet &wallet, const CoinEligibilityFilter &filter)
std::set< std::shared_ptr< COutput >, OutputPtrComparator > OutputSet
util::Result< SelectionResult > KnapsackSolver(std::vector< OutputGroup > &groups, const CAmount &nTargetValue, CAmount change_target, FastRandomContext &rng, int max_selection_weight)
util::Result< SelectionResult > SelectCoins(const CWallet &wallet, CoinsResult &available_coins, const CoinsResult &pre_set_inputs, const CAmount &nTargetValue, const CCoinControl &coin_control, const CoinSelectionParams &coin_selection_params)
Select all coins from coin_control, and if coin_control 'm_allow_other_inputs=true',...
static bool has_coin(const OutputSet &set, CAmount amount)
static const CoinEligibilityFilter filter_standard_extra(6, 6, 0)
static bool EqualResult(const SelectionResult &a, const SelectionResult &b)
Check if this selection is equal to another one.
BOOST_AUTO_TEST_CASE(bnb_test)
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
static const CoinEligibilityFilter filter_confirmed(1, 1, 0)
int CalculateMaximumSignedInputSize(const CTxOut &txout, const COutPoint outpoint, const SigningProvider *provider, bool can_grind_r, const CCoinControl *coin_control)
static bool EquivalentResult(const SelectionResult &a, const SelectionResult &b)
Check if SelectionResult a is equivalent to SelectionResult b.
static void ApproximateBestSubset(FastRandomContext &insecure_rand, const std::vector< OutputGroup > &groups, const CAmount &nTotalLower, const CAmount &nTargetValue, std::vector< char > &vfBest, CAmount &nBest, int max_selection_weight, int iterations=1000)
Find a subset of the OutputGroups that is at least as large as, but as close as possible to,...
static util::Result< SelectionResult > select_coins(const CAmount &target, const CoinSelectionParams &cs_params, const CCoinControl &cc, std::function< CoinsResult(CWallet &)> coin_setup, const node::NodeContext &m_node)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
constexpr int32_t MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
NodeContext struct containing references to chain state and connection state.
std::unique_ptr< interfaces::Chain > chain
A UTXO under consideration for use in funding a new transaction.
COutPoint outpoint
The outpoint identifying this UTXO.
CTxOut txout
The output itself.
Parameters for filtering which OutputGroups we may use in coin selection.
Parameters for one iteration of Coin Selection.
COutputs available for spending, stored by OutputType.
void Add(OutputType type, const COutput &out)
std::vector< OutputGroup > mixed_group
A group of UTXOs paid to the same output script.
Stores several 'Groups' whose were mapped by output type.
void AddInput(const OutputGroup &group)
const OutputSet & GetInputSet() const
Get m_selected_inputs.
State of transaction not confirmed or conflicting with a known block and not in the mempool.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
BOOST_CHECK_NE(OneL.ToString(), ArrayToString(ZeroArray, 32))
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.