Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | for (int i = 0; i < 3; i++) { | ||||
txGrandChild[i].vin[0].scriptSig = CScript() << OP_11; | txGrandChild[i].vin[0].scriptSig = CScript() << OP_11; | ||||
txGrandChild[i].vin[0].prevout = COutPoint(txChild[i].GetId(), 0); | txGrandChild[i].vin[0].prevout = COutPoint(txChild[i].GetId(), 0); | ||||
txGrandChild[i].vout.resize(1); | txGrandChild[i].vout.resize(1); | ||||
txGrandChild[i].vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | txGrandChild[i].vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
txGrandChild[i].vout[0].nValue = 11000 * SATOSHI; | txGrandChild[i].vout[0].nValue = 11000 * SATOSHI; | ||||
} | } | ||||
CTxMemPool testPool; | CTxMemPool testPool; | ||||
LOCK(testPool.cs); | |||||
// Nothing in pool, remove should do nothing: | // Nothing in pool, remove should do nothing: | ||||
unsigned int poolSize = testPool.size(); | unsigned int poolSize = testPool.size(); | ||||
testPool.removeRecursive(CTransaction(txParent)); | testPool.removeRecursive(CTransaction(txParent)); | ||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize); | BOOST_CHECK_EQUAL(testPool.size(), poolSize); | ||||
// Just the parent: | // Just the parent: | ||||
testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); | testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | for (; it != pool.mapTx.get<name>().end(); ++it, ++count) { | ||||
it->GetTx().GetId().ToString() | it->GetTx().GetId().ToString() | ||||
<< " != " << sortedOrder[count] << " in test " | << " != " << sortedOrder[count] << " in test " | ||||
<< testcase << ":" << count); | << testcase << ":" << count); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(MempoolIndexingTest) { | BOOST_AUTO_TEST_CASE(MempoolIndexingTest) { | ||||
CTxMemPool pool; | CTxMemPool pool; | ||||
LOCK(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(), | ||||
Show All 35 Lines | BOOST_AUTO_TEST_CASE(MempoolIndexingTest) { | ||||
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 | ||||
sortedOrder[3] = tx4.GetId().ToString(); // 15000 | sortedOrder[3] = tx4.GetId().ToString(); // 15000 | ||||
sortedOrder[4] = tx2.GetId().ToString(); // 20000 | sortedOrder[4] = tx2.GetId().ToString(); // 20000 | ||||
LOCK(pool.cs); | |||||
CheckSort<descendant_score>(pool, sortedOrder, "MempoolIndexingTest1"); | CheckSort<descendant_score>(pool, sortedOrder, "MempoolIndexingTest1"); | ||||
/* low fee but with high fee child */ | /* low fee but with high fee child */ | ||||
/* tx6 -> tx7 -> tx8, tx9 -> tx10 */ | /* tx6 -> tx7 -> tx8, tx9 -> tx10 */ | ||||
CMutableTransaction tx6 = CMutableTransaction(); | CMutableTransaction tx6 = CMutableTransaction(); | ||||
tx6.vout.resize(1); | tx6.vout.resize(1); | ||||
tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
tx6.vout[0].nValue = 20 * COIN; | tx6.vout[0].nValue = 20 * COIN; | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolIndexingTest) { | ||||
CheckSort<descendant_score>(pool, snapshotOrder, "MempoolIndexingTest7"); | CheckSort<descendant_score>(pool, snapshotOrder, "MempoolIndexingTest7"); | ||||
pool.removeRecursive(pool.mapTx.find(tx9.GetId())->GetTx()); | pool.removeRecursive(pool.mapTx.find(tx9.GetId())->GetTx()); | ||||
pool.removeRecursive(pool.mapTx.find(tx8.GetId())->GetTx()); | pool.removeRecursive(pool.mapTx.find(tx8.GetId())->GetTx()); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { | BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { | ||||
CTxMemPool pool; | CTxMemPool pool; | ||||
LOCK(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(), | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (tx1.GetId() < tx5.GetId()) { | ||||
sortedOrder[2] = tx1.GetId().ToString(); | sortedOrder[2] = tx1.GetId().ToString(); | ||||
sortedOrder[3] = tx5.GetId().ToString(); | sortedOrder[3] = tx5.GetId().ToString(); | ||||
} else { | } else { | ||||
sortedOrder[2] = tx5.GetId().ToString(); | sortedOrder[2] = tx5.GetId().ToString(); | ||||
sortedOrder[3] = tx1.GetId().ToString(); | sortedOrder[3] = tx1.GetId().ToString(); | ||||
} | } | ||||
sortedOrder[4] = tx3.GetId().ToString(); // 0 | sortedOrder[4] = tx3.GetId().ToString(); // 0 | ||||
LOCK(pool.cs); | |||||
CheckSort<ancestor_score>(pool, sortedOrder, | CheckSort<ancestor_score>(pool, sortedOrder, | ||||
"MempoolAncestorIndexingTest1"); | "MempoolAncestorIndexingTest1"); | ||||
/* low fee parent with high fee child */ | /* low fee parent with high fee child */ | ||||
/* tx6 (0) -> tx7 (high) */ | /* tx6 (0) -> tx7 (high) */ | ||||
CMutableTransaction tx6 = CMutableTransaction(); | CMutableTransaction tx6 = CMutableTransaction(); | ||||
tx6.vout.resize(1); | tx6.vout.resize(1); | ||||
tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | pool.addUnchecked(tx8.GetId(), | ||||
entry.Fee(Amount(5000 * SATOSHI)).FromTx(tx8)); | entry.Fee(Amount(5000 * SATOSHI)).FromTx(tx8)); | ||||
sortedOrder.insert(sortedOrder.end() - 1, tx8.GetId().ToString()); | sortedOrder.insert(sortedOrder.end() - 1, tx8.GetId().ToString()); | ||||
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; | ||||
LOCK(pool.cs); | |||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
entry.dPriority = 10.0; | 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); | ||||
▲ Show 20 Lines • Show All 277 Lines • ▼ Show 20 Lines | #define MK_INPUTS(txs...) \ | ||||
std::vector<CTransactionRef> { txs } | std::vector<CTransactionRef> { txs } | ||||
#define MK_INPUT_IDX(idxes...) \ | #define MK_INPUT_IDX(idxes...) \ | ||||
std::vector<uint32_t> { idxes } | std::vector<uint32_t> { idxes } | ||||
BOOST_AUTO_TEST_CASE(MempoolAncestryTests) { | BOOST_AUTO_TEST_CASE(MempoolAncestryTests) { | ||||
size_t ancestors, descendants; | size_t ancestors, descendants; | ||||
CTxMemPool pool; | CTxMemPool pool; | ||||
LOCK(pool.cs); | |||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
/* Base transaction */ | /* Base transaction */ | ||||
// | // | ||||
// [tx1] | // [tx1] | ||||
// | // | ||||
CTransactionRef tx1 = make_tx(MK_OUTPUTS(10 * COIN)); | CTransactionRef tx1 = make_tx(MK_OUTPUTS(10 * COIN)); | ||||
pool.addUnchecked(tx1->GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx1)); | pool.addUnchecked(tx1->GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx1)); | ||||
▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines |