10#include <boost/test/unit_test.hpp>
53 csp.m_change_fee =
csp.m_effective_feerate.
GetFee(
csp.change_output_size);
54 csp.min_viable_change =
csp.m_discard_feerate.GetFee(
csp.change_spend_size);
55 csp.m_cost_of_change =
csp.min_viable_change +
csp.m_change_fee;
56 csp.m_subtract_fee_outputs =
false;
72 group.Insert(std::make_shared<COutput>(
COutPoint(tx.
GetHash(), 0), tx.
vout.at(0), 1,
custom_spending_vsize,
true,
true, 0,
false,
fees), 0, 0);
86 for (
int i = 0 ; i <
count; ++i) {
95 std::vector<CAmount>
a_amts;
96 std::vector<CAmount>
b_amts;
97 for (
const auto& coin :
a.GetInputSet()) {
98 a_amts.push_back(coin->txout.nValue);
101 b_amts.push_back(coin->txout.nValue);
112 return "[" +
util::Join(
selection.GetInputSet(),
" ", [](
const auto& input){ return util::ToString(input->txout.nValue);}) +
"]";
122 expected_result.AddInput(group);
199 for (
int i = 0; i < 17; ++i) {
231 for (
size_t i = 0; i < 19; ++i) {
int64_t CAmount
Amount in satoshis (Can be negative)
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.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
bilingual_str ErrorString(const Result< T > &result)
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
constexpr CAmount CHANGE_LOWER
lower bound for randomly-chosen target change amount
util::Result< SelectionResult > SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change, int max_selection_weight)
static void TestBnBFail(std::string test_title, std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CoinSelectionParams &cs_params=default_cs_params, int max_selection_weight=MAX_STANDARD_TX_WEIGHT, const bool expect_max_weight_exceeded=false)
static CoinSelectionParams init_cs_params(int eff_feerate=5000)
Default coin selection parameters allow us to only explicitly set parameters when a diverging value i...
static const int P2WPKH_OUTPUT_VSIZE
static bool HaveEquivalentValues(const SelectionResult &a, const SelectionResult &b)
Check if SelectionResult a is equivalent to SelectionResult b.
static const int P2WPKH_INPUT_VSIZE
static void TestSRDFail(std::string test_title, std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CoinSelectionParams &cs_params=default_cs_params, int max_selection_weight=MAX_STANDARD_TX_WEIGHT, const bool expect_max_weight_exceeded=false)
static void AddDuplicateCoins(std::vector< OutputGroup > &utxo_pool, int count, int amount, CoinSelectionParams cs_params=default_cs_params)
Make multiple coins that share the same effective value.
BOOST_AUTO_TEST_CASE(bnb_test)
static int next_lock_time
static void TestBnBSuccess(std::string test_title, std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const std::vector< CAmount > &expected_input_amounts, size_t expected_attempts, const CoinSelectionParams &cs_params=default_cs_params, const int custom_spending_vsize=P2WPKH_INPUT_VSIZE, const int max_selection_weight=MAX_STANDARD_TX_WEIGHT)
static const CoinSelectionParams default_cs_params
static void AddCoins(std::vector< OutputGroup > &utxo_pool, std::vector< CAmount > coins, CoinSelectionParams cs_params=default_cs_params)
Make multiple OutputGroups with the given values as their effective value.
static OutputGroup MakeCoin(const CAmount &amount, bool is_eff_value=true, CoinSelectionParams cs_params=default_cs_params, int custom_spending_vsize=P2WPKH_INPUT_VSIZE)
Make one OutputGroup with a single UTXO that either has a given effective value (default) or a given ...
static FastRandomContext default_rand
static void TestSRDSuccess(std::string test_title, std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CoinSelectionParams &cs_params=default_cs_params, const int max_selection_weight=MAX_STANDARD_TX_WEIGHT)
static const std::vector< int > FEERATES
This set of feerates is used in the tests to test edge cases around the default minimum feerate and o...
util::Result< SelectionResult > SelectCoinsSRD(const std::vector< OutputGroup > &utxo_pool, CAmount target_value, CAmount change_fee, FastRandomContext &rng, int max_selection_weight)
Select coins by Single Random Draw (SRD).
static std::string InputAmountsToString(const SelectionResult &selection)
#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.
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
Testing setup that configures a complete environment.
Parameters for one iteration of Coin Selection.
CAmount m_cost_of_change
Cost of creating the change output + cost of spending the change output in the future.
A group of UTXOs paid to the same output script.
const OutputSet & GetInputSet() const
Get m_selected_inputs.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.