Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/coinselector_tests.cpp
Show All 24 Lines | |||||
// only show up with particular random shuffles | // only show up with particular random shuffles | ||||
#define RUN_TESTS 100 | #define RUN_TESTS 100 | ||||
// some tests fail 1% of the time due to bad luck. | // some tests fail 1% of the time due to bad luck. | ||||
// we repeat those tests this many times and only complain if all iterations of | // we repeat those tests this many times and only complain if all iterations of | ||||
// the test fail | // the test fail | ||||
#define RANDOM_REPEATS 5 | #define RANDOM_REPEATS 5 | ||||
std::vector<std::unique_ptr<CWalletTx>> wtxn; | |||||
typedef std::set<CInputCoin> CoinSet; | typedef std::set<CInputCoin> CoinSet; | ||||
static std::vector<COutput> vCoins; | static std::vector<COutput> vCoins; | ||||
static NodeContext testNode; | static NodeContext testNode; | ||||
static Amount balance = Amount::zero(); | static Amount balance = Amount::zero(); | ||||
CoinEligibilityFilter filter_standard(1, 6, 0); | CoinEligibilityFilter filter_standard(1, 6, 0); | ||||
CoinEligibilityFilter filter_confirmed(1, 1, 0); | CoinEligibilityFilter filter_confirmed(1, 1, 0); | ||||
Show All 33 Lines | if (spendable) { | ||||
tx.vout[nInput].scriptPubKey = GetScriptForDestination(dest); | tx.vout[nInput].scriptPubKey = GetScriptForDestination(dest); | ||||
} | } | ||||
if (fIsFromMe) { | if (fIsFromMe) { | ||||
// IsFromMe() returns (GetDebit() > 0), and GetDebit() is 0 if | // IsFromMe() returns (GetDebit() > 0), and GetDebit() is 0 if | ||||
// vin.empty(), so stop vin being empty, and cache a non-zero Debit to | // vin.empty(), so stop vin being empty, and cache a non-zero Debit to | ||||
// fake out IsFromMe() | // fake out IsFromMe() | ||||
tx.vin.resize(1); | tx.vin.resize(1); | ||||
} | } | ||||
auto wtx = | CWalletTx *wtx = wallet.AddToWallet(MakeTransactionRef(std::move(tx)), | ||||
std::make_unique<CWalletTx>(&wallet, MakeTransactionRef(std::move(tx))); | /* confirm= */ {}); | ||||
if (fIsFromMe) { | if (fIsFromMe) { | ||||
wtx->m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, SATOSHI); | wtx->m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, SATOSHI); | ||||
wtx->m_is_cache_empty = false; | wtx->m_is_cache_empty = false; | ||||
} | } | ||||
COutput output(wtx.get(), nInput, nAge, true /* spendable */, | COutput output(wtx, nInput, nAge, true /* spendable */, true /* solvable */, | ||||
true /* solvable */, true /* safe */); | true /* safe */); | ||||
vCoins.push_back(output); | vCoins.push_back(output); | ||||
wallet.AddToWallet(*wtx.get()); | |||||
wtxn.emplace_back(std::move(wtx)); | |||||
} | } | ||||
static void empty_wallet() { | static void empty_wallet() { | ||||
vCoins.clear(); | vCoins.clear(); | ||||
wtxn.clear(); | |||||
balance = Amount::zero(); | balance = Amount::zero(); | ||||
} | } | ||||
static bool equal_sets(CoinSet a, CoinSet b) { | static bool equal_sets(CoinSet a, CoinSet b) { | ||||
std::pair<CoinSet::iterator, CoinSet::iterator> ret = | std::pair<CoinSet::iterator, CoinSet::iterator> ret = | ||||
mismatch(a.begin(), a.end(), b.begin()); | mismatch(a.begin(), a.end(), b.begin()); | ||||
return ret.first == a.end() && ret.second == b.end(); | return ret.first == a.end() && ret.second == b.end(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 725 Lines • Show Last 20 Lines |