Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolIndexingTest) { | ||||
LOCK2(cs_main, pool.cs); | LOCK2(cs_main, pool.cs); | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
/* 3rd highest fee */ | /* 3rd highest fee */ | ||||
CMutableTransaction tx1 = CMutableTransaction(); | CMutableTransaction tx1 = CMutableTransaction(); | ||||
tx1.vout.resize(1); | tx1.vout.resize(1); | ||||
tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx1.vout[0].nValue = 10 * COIN; | tx1.vout[0].nValue = 10 * COIN; | ||||
pool.addUnchecked(tx1.GetId(), | pool.addUnchecked(tx1.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx1)); | ||||
entry.Fee(10000 * SATOSHI).Priority(10.0).FromTx(tx1)); | |||||
/* highest fee */ | /* highest fee */ | ||||
CMutableTransaction tx2 = CMutableTransaction(); | CMutableTransaction tx2 = CMutableTransaction(); | ||||
tx2.vout.resize(1); | tx2.vout.resize(1); | ||||
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx2.vout[0].nValue = 2 * COIN; | tx2.vout[0].nValue = 2 * COIN; | ||||
pool.addUnchecked(tx2.GetId(), | pool.addUnchecked(tx2.GetId(), entry.Fee(20000 * SATOSHI).FromTx(tx2)); | ||||
entry.Fee(20000 * SATOSHI).Priority(9.0).FromTx(tx2)); | |||||
/* lowest fee */ | /* lowest fee */ | ||||
CMutableTransaction tx3 = CMutableTransaction(); | CMutableTransaction tx3 = CMutableTransaction(); | ||||
tx3.vout.resize(1); | tx3.vout.resize(1); | ||||
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx3.vout[0].nValue = 5 * COIN; | tx3.vout[0].nValue = 5 * COIN; | ||||
pool.addUnchecked(tx3.GetId(), | pool.addUnchecked(tx3.GetId(), entry.Fee(Amount::zero()).FromTx(tx3)); | ||||
entry.Fee(Amount::zero()).Priority(100.0).FromTx(tx3)); | |||||
/* 2nd highest fee */ | /* 2nd highest fee */ | ||||
CMutableTransaction tx4 = CMutableTransaction(); | CMutableTransaction tx4 = CMutableTransaction(); | ||||
tx4.vout.resize(1); | tx4.vout.resize(1); | ||||
tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx4.vout[0].nValue = 6 * COIN; | tx4.vout[0].nValue = 6 * COIN; | ||||
pool.addUnchecked(tx4.GetId(), | pool.addUnchecked(tx4.GetId(), entry.Fee(15000 * SATOSHI).FromTx(tx4)); | ||||
entry.Fee(15000 * SATOSHI).Priority(1.0).FromTx(tx4)); | |||||
/* equal fee rate to tx1, but newer */ | /* equal fee rate to tx1, but newer */ | ||||
CMutableTransaction tx5 = CMutableTransaction(); | CMutableTransaction tx5 = CMutableTransaction(); | ||||
tx5.vout.resize(1); | tx5.vout.resize(1); | ||||
tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx5.vout[0].nValue = 11 * COIN; | tx5.vout[0].nValue = 11 * COIN; | ||||
entry.nTime = 1; | entry.nTime = 1; | ||||
entry.dPriority = 10.0; | |||||
pool.addUnchecked(tx5.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx5)); | pool.addUnchecked(tx5.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx5)); | ||||
BOOST_CHECK_EQUAL(pool.size(), 5UL); | BOOST_CHECK_EQUAL(pool.size(), 5UL); | ||||
std::vector<std::string> sortedOrder; | std::vector<std::string> sortedOrder; | ||||
sortedOrder.resize(5); | sortedOrder.resize(5); | ||||
sortedOrder[0] = tx3.GetId().ToString(); // 0 | sortedOrder[0] = tx3.GetId().ToString(); // 0 | ||||
sortedOrder[1] = tx5.GetId().ToString(); // 10000 | sortedOrder[1] = tx5.GetId().ToString(); // 10000 | ||||
sortedOrder[2] = tx1.GetId().ToString(); // 10000 | sortedOrder[2] = tx1.GetId().ToString(); // 10000 | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { | ||||
LOCK2(cs_main, pool.cs); | LOCK2(cs_main, pool.cs); | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
/* 3rd highest fee */ | /* 3rd highest fee */ | ||||
CMutableTransaction tx1 = CMutableTransaction(); | CMutableTransaction tx1 = CMutableTransaction(); | ||||
tx1.vout.resize(1); | tx1.vout.resize(1); | ||||
tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx1.vout[0].nValue = 10 * COIN; | tx1.vout[0].nValue = 10 * COIN; | ||||
pool.addUnchecked(tx1.GetId(), | pool.addUnchecked(tx1.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx1)); | ||||
entry.Fee(10000 * SATOSHI).Priority(10.0).FromTx(tx1)); | |||||
/* highest fee */ | /* highest fee */ | ||||
CMutableTransaction tx2 = CMutableTransaction(); | CMutableTransaction tx2 = CMutableTransaction(); | ||||
tx2.vout.resize(1); | tx2.vout.resize(1); | ||||
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx2.vout[0].nValue = 2 * COIN; | tx2.vout[0].nValue = 2 * COIN; | ||||
pool.addUnchecked(tx2.GetId(), | pool.addUnchecked(tx2.GetId(), entry.Fee(20000 * SATOSHI).FromTx(tx2)); | ||||
entry.Fee(20000 * SATOSHI).Priority(9.0).FromTx(tx2)); | |||||
uint64_t tx2Size = CTransaction(tx2).GetTotalSize(); | uint64_t tx2Size = CTransaction(tx2).GetTotalSize(); | ||||
/* lowest fee */ | /* lowest fee */ | ||||
CMutableTransaction tx3 = CMutableTransaction(); | CMutableTransaction tx3 = CMutableTransaction(); | ||||
tx3.vout.resize(1); | tx3.vout.resize(1); | ||||
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx3.vout[0].nValue = 5 * COIN; | tx3.vout[0].nValue = 5 * COIN; | ||||
pool.addUnchecked(tx3.GetId(), | pool.addUnchecked(tx3.GetId(), entry.Fee(Amount::zero()).FromTx(tx3)); | ||||
entry.Fee(Amount::zero()).Priority(100.0).FromTx(tx3)); | |||||
/* 2nd highest fee */ | /* 2nd highest fee */ | ||||
CMutableTransaction tx4 = CMutableTransaction(); | CMutableTransaction tx4 = CMutableTransaction(); | ||||
tx4.vout.resize(1); | tx4.vout.resize(1); | ||||
tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx4.vout[0].nValue = 6 * COIN; | tx4.vout[0].nValue = 6 * COIN; | ||||
pool.addUnchecked(tx4.GetId(), | pool.addUnchecked(tx4.GetId(), entry.Fee(15000 * SATOSHI).FromTx(tx4)); | ||||
entry.Fee(15000 * SATOSHI).Priority(1.0).FromTx(tx4)); | |||||
/* equal fee rate to tx1, but newer */ | /* equal fee rate to tx1, but newer */ | ||||
CMutableTransaction tx5 = CMutableTransaction(); | CMutableTransaction tx5 = CMutableTransaction(); | ||||
tx5.vout.resize(1); | tx5.vout.resize(1); | ||||
tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx5.vout[0].nValue = 11 * COIN; | tx5.vout[0].nValue = 11 * COIN; | ||||
pool.addUnchecked(tx5.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx5)); | pool.addUnchecked(tx5.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx5)); | ||||
BOOST_CHECK_EQUAL(pool.size(), 5UL); | BOOST_CHECK_EQUAL(pool.size(), 5UL); | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { | ||||
CheckSort<ancestor_score>(pool, sortedOrder, | CheckSort<ancestor_score>(pool, sortedOrder, | ||||
"MempoolAncestorIndexingTest5"); | "MempoolAncestorIndexingTest5"); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) { | BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) { | ||||
CTxMemPool pool; | CTxMemPool pool; | ||||
LOCK2(cs_main, pool.cs); | LOCK2(cs_main, pool.cs); | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
entry.dPriority = 10.0; | |||||
Amount feeIncrement = MEMPOOL_FULL_FEE_INCREMENT.GetFeePerK(); | Amount feeIncrement = MEMPOOL_FULL_FEE_INCREMENT.GetFeePerK(); | ||||
CMutableTransaction tx1 = CMutableTransaction(); | CMutableTransaction tx1 = CMutableTransaction(); | ||||
tx1.vin.resize(1); | tx1.vin.resize(1); | ||||
tx1.vin[0].scriptSig = CScript() << OP_1; | tx1.vin[0].scriptSig = CScript() << OP_1; | ||||
tx1.vout.resize(1); | tx1.vout.resize(1); | ||||
tx1.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL; | tx1.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL; | ||||
tx1.vout[0].nValue = 10 * COIN; | tx1.vout[0].nValue = 10 * COIN; | ||||
▲ Show 20 Lines • Show All 446 Lines • Show Last 20 Lines |