11 #include <boost/test/unit_test.hpp>
23 txParent.
vin.resize(1);
25 txParent.
vout.resize(3);
26 for (
int i = 0; i < 3; i++)
29 txParent.
vout[i].nValue = 33000LL;
32 for (
int i = 0; i < 3; i++)
34 txChild[i].
vin.resize(1);
36 txChild[i].
vin[0].prevout.hash = txParent.
GetHash();
37 txChild[i].
vin[0].prevout.n = i;
38 txChild[i].
vout.resize(1);
40 txChild[i].
vout[0].nValue = 11000LL;
43 for (
int i = 0; i < 3; i++)
45 txGrandChild[i].
vin.resize(1);
47 txGrandChild[i].
vin[0].prevout.hash = txChild[i].
GetHash();
48 txGrandChild[i].
vin[0].prevout.n = 0;
49 txGrandChild[i].
vout.resize(1);
51 txGrandChild[i].
vout[0].nValue = 11000LL;
58 unsigned int poolSize = testPool.
size();
64 poolSize = testPool.
size();
70 for (
int i = 0; i < 3; i++)
76 poolSize = testPool.
size();
80 poolSize = testPool.
size();
83 poolSize = testPool.
size();
87 poolSize = testPool.
size();
93 for (
int i = 0; i < 3; i++)
100 poolSize = testPool.
size();
106 template<
typename name>
110 typename CTxMemPool::indexed_transaction_set::index<name>::type::iterator it = pool.
mapTx.get<
name>().begin();
112 for (; it != pool.
mapTx.get<
name>().end(); ++it, ++count) {
126 tx1.
vout[0].nValue = 10 * COIN;
133 tx2.
vout[0].nValue = 2 * COIN;
140 tx3.
vout[0].nValue = 5 * COIN;
147 tx4.
vout[0].nValue = 6 * COIN;
154 tx5.
vout[0].nValue = 11 * COIN;
159 std::vector<std::string> sortedOrder;
160 sortedOrder.resize(5);
166 CheckSort<descendant_score>(pool, sortedOrder);
173 tx6.
vout[0].nValue = 20 * COIN;
178 CheckSort<descendant_score>(pool, sortedOrder);
188 tx7.
vout[0].nValue = 10 * COIN;
190 tx7.
vout[1].nValue = 1 * COIN;
195 BOOST_CHECK(setAncestorsCalculated == setAncestors);
201 sortedOrder.erase(sortedOrder.begin());
204 CheckSort<descendant_score>(pool, sortedOrder);
213 tx8.
vout[0].nValue = 10 * COIN;
219 CheckSort<descendant_score>(pool, sortedOrder);
228 tx9.
vout[0].nValue = 1 * COIN;
234 CheckSort<descendant_score>(pool, sortedOrder);
236 std::vector<std::string> snapshotOrder = sortedOrder;
249 tx10.
vout[0].nValue = 10 * COIN;
251 setAncestorsCalculated.clear();
253 BOOST_CHECK(setAncestorsCalculated == setAncestors);
272 sortedOrder.erase(sortedOrder.begin(), sortedOrder.begin()+2);
276 CheckSort<descendant_score>(pool, sortedOrder);
283 CheckSort<descendant_score>(pool, snapshotOrder);
315 CheckSort<mining_score>(pool, sortedOrder);
327 tx1.
vout[0].nValue = 10 * COIN;
334 tx2.
vout[0].nValue = 2 * COIN;
342 tx3.
vout[0].nValue = 5 * COIN;
349 tx4.
vout[0].nValue = 6 * COIN;
356 tx5.
vout[0].nValue = 11 * COIN;
360 std::vector<std::string> sortedOrder;
361 sortedOrder.resize(5);
376 CheckSort<ancestor_score>(pool, sortedOrder);
383 tx6.
vout[0].nValue = 20 * COIN;
394 CheckSort<ancestor_score>(pool, sortedOrder);
402 tx7.
vout[0].nValue = 10 * COIN;
406 CAmount fee = (20000/tx2Size)*(tx7Size + tx6Size) - 1;
411 CheckSort<ancestor_score>(pool, sortedOrder);
414 std::vector<CTransactionRef> vtx;
415 vtx.emplace_back(MakeTransactionRef(tx6));
418 sortedOrder.erase(sortedOrder.begin()+1);
421 sortedOrder.pop_back();
423 sortedOrder.erase(sortedOrder.end()-2);
425 CheckSort<ancestor_score>(pool, sortedOrder);
439 tx1.
vout[0].nValue = 10 * COIN;
447 tx2.
vout[0].nValue = 10 * COIN;
465 tx3.
vout[0].nValue = 10 * COIN;
483 tx4.
vin[0].prevout.SetNull();
485 tx4.
vin[1].prevout.SetNull();
489 tx4.
vout[0].nValue = 10 * COIN;
491 tx4.
vout[1].nValue = 10 * COIN;
497 tx5.
vin[1].prevout.SetNull();
501 tx5.
vout[0].nValue = 10 * COIN;
503 tx5.
vout[1].nValue = 10 * COIN;
509 tx6.
vin[1].prevout.SetNull();
513 tx6.
vout[0].nValue = 10 * COIN;
515 tx6.
vout[1].nValue = 10 * COIN;
525 tx7.
vout[0].nValue = 10 * COIN;
527 tx7.
vout[1].nValue = 10 * COIN;
553 std::vector<CTransactionRef> vtx;
int64_t CAmount
Amount in PIV (Can be negative)
Fee rate in PIV per kilobyte: CAmount / kB.
CAmount GetFeePerK() const
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
bool addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, bool validFeeEstimate=true)
size_t DynamicMemoryUsage() const
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents=true) const
Try to calculate all in-mempool ancestors of entry.
bool exists(uint256 hash) const
static const int ROLLING_FEE_HALFLIFE
std::set< txiter, CompareIteratorByHash > setEntries
indexed_transaction_set mapTx
unsigned long size() const
void TrimToSize(size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr)
Remove transactions from the mempool until its dynamic size is <= sizelimit.
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight)
Called when a block is connected.
std::string ToString() const
BOOST_AUTO_TEST_SUITE_END()
void CheckSort(CTxMemPool &pool, std::vector< std::string > &sortedOrder)
BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
unsigned int GetSerializeSize(const std::array< T, N > &item)
array
A mutable version of CTransaction.
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
std::vector< CTxOut > vout
TestMemPoolEntryHelper & Time(int64_t _time)
TestMemPoolEntryHelper & Fee(CAmount _fee)
CTxMemPoolEntry FromTx(const CMutableTransaction &tx)
void SetMockTime(int64_t nMockTimeIn)
For testing.