Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | for (size_t totalTransactions = 0; totalTransactions < 100; | ||||
BOOST_CHECK_EQUAL(parentEntry.GetVirtualSizeWithDescendants(), | BOOST_CHECK_EQUAL(parentEntry.GetVirtualSizeWithDescendants(), | ||||
totalVirtualSize_strict); | totalVirtualSize_strict); | ||||
BOOST_CHECK_EQUAL(parentEntry.GetModFeesWithDescendants(), totalFee); | BOOST_CHECK_EQUAL(parentEntry.GetModFeesWithDescendants(), totalFee); | ||||
BOOST_CHECK_EQUAL(parentEntry.GetSigOpCountWithDescendants(), | BOOST_CHECK_EQUAL(parentEntry.GetSigOpCountWithDescendants(), | ||||
totalSigOpCount); | totalSigOpCount); | ||||
} | } | ||||
} | } | ||||
static constexpr auto REMOVAL_REASON_DUMMY = MemPoolRemovalReason::REPLACED; | |||||
BOOST_AUTO_TEST_CASE(MempoolRemoveTest) { | BOOST_AUTO_TEST_CASE(MempoolRemoveTest) { | ||||
// Test CTxMemPool::remove functionality | // Test CTxMemPool::remove functionality | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
// Parent transaction with three children, and three grand-children: | // Parent transaction with three children, and three grand-children: | ||||
CMutableTransaction txParent; | CMutableTransaction txParent; | ||||
txParent.vin.resize(1); | txParent.vin.resize(1); | ||||
txParent.vin[0].scriptSig = CScript() << OP_11; | txParent.vin[0].scriptSig = CScript() << OP_11; | ||||
Show All 21 Lines | for (int i = 0; i < 3; i++) { | ||||
txGrandChild[i].vout[0].nValue = 11000 * SATOSHI; | txGrandChild[i].vout[0].nValue = 11000 * SATOSHI; | ||||
} | } | ||||
CTxMemPool testPool; | CTxMemPool testPool; | ||||
LOCK2(cs_main, testPool.cs); | LOCK2(cs_main, 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), REMOVAL_REASON_DUMMY); | ||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize); | BOOST_CHECK_EQUAL(testPool.size(), poolSize); | ||||
// Just the parent: | // Just the parent: | ||||
testPool.addUnchecked(entry.FromTx(txParent)); | testPool.addUnchecked(entry.FromTx(txParent)); | ||||
poolSize = testPool.size(); | poolSize = testPool.size(); | ||||
testPool.removeRecursive(CTransaction(txParent)); | testPool.removeRecursive(CTransaction(txParent), REMOVAL_REASON_DUMMY); | ||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize - 1); | BOOST_CHECK_EQUAL(testPool.size(), poolSize - 1); | ||||
// Parent, children, grandchildren: | // Parent, children, grandchildren: | ||||
testPool.addUnchecked(entry.FromTx(txParent)); | testPool.addUnchecked(entry.FromTx(txParent)); | ||||
for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
testPool.addUnchecked(entry.FromTx(txChild[i])); | testPool.addUnchecked(entry.FromTx(txChild[i])); | ||||
testPool.addUnchecked(entry.FromTx(txGrandChild[i])); | testPool.addUnchecked(entry.FromTx(txGrandChild[i])); | ||||
} | } | ||||
// Remove Child[0], GrandChild[0] should be removed: | // Remove Child[0], GrandChild[0] should be removed: | ||||
poolSize = testPool.size(); | poolSize = testPool.size(); | ||||
testPool.removeRecursive(CTransaction(txChild[0])); | testPool.removeRecursive(CTransaction(txChild[0]), REMOVAL_REASON_DUMMY); | ||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize - 2); | BOOST_CHECK_EQUAL(testPool.size(), poolSize - 2); | ||||
// ... make sure grandchild and child are gone: | // ... make sure grandchild and child are gone: | ||||
poolSize = testPool.size(); | poolSize = testPool.size(); | ||||
testPool.removeRecursive(CTransaction(txGrandChild[0])); | testPool.removeRecursive(CTransaction(txGrandChild[0]), | ||||
REMOVAL_REASON_DUMMY); | |||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize); | BOOST_CHECK_EQUAL(testPool.size(), poolSize); | ||||
poolSize = testPool.size(); | poolSize = testPool.size(); | ||||
testPool.removeRecursive(CTransaction(txChild[0])); | testPool.removeRecursive(CTransaction(txChild[0]), REMOVAL_REASON_DUMMY); | ||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize); | BOOST_CHECK_EQUAL(testPool.size(), poolSize); | ||||
// Remove parent, all children/grandchildren should go: | // Remove parent, all children/grandchildren should go: | ||||
poolSize = testPool.size(); | poolSize = testPool.size(); | ||||
testPool.removeRecursive(CTransaction(txParent)); | testPool.removeRecursive(CTransaction(txParent), REMOVAL_REASON_DUMMY); | ||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize - 5); | BOOST_CHECK_EQUAL(testPool.size(), poolSize - 5); | ||||
BOOST_CHECK_EQUAL(testPool.size(), 0UL); | BOOST_CHECK_EQUAL(testPool.size(), 0UL); | ||||
// Add children and grandchildren, but NOT the parent (simulate the parent | // Add children and grandchildren, but NOT the parent (simulate the parent | ||||
// being in a block) | // being in a block) | ||||
for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
testPool.addUnchecked(entry.FromTx(txChild[i])); | testPool.addUnchecked(entry.FromTx(txChild[i])); | ||||
testPool.addUnchecked(entry.FromTx(txGrandChild[i])); | testPool.addUnchecked(entry.FromTx(txGrandChild[i])); | ||||
} | } | ||||
// Now remove the parent, as might happen if a block-re-org occurs but the | // Now remove the parent, as might happen if a block-re-org occurs but the | ||||
// parent cannot be put into the mempool (maybe because it is non-standard): | // parent cannot be put into the mempool (maybe because it is non-standard): | ||||
poolSize = testPool.size(); | poolSize = testPool.size(); | ||||
testPool.removeRecursive(CTransaction(txParent)); | testPool.removeRecursive(CTransaction(txParent), REMOVAL_REASON_DUMMY); | ||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize - 6); | BOOST_CHECK_EQUAL(testPool.size(), poolSize - 6); | ||||
BOOST_CHECK_EQUAL(testPool.size(), 0UL); | BOOST_CHECK_EQUAL(testPool.size(), 0UL); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(MempoolClearTest) { | BOOST_AUTO_TEST_CASE(MempoolClearTest) { | ||||
// Test CTxMemPool::clear functionality | // Test CTxMemPool::clear functionality | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
▲ Show 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolIndexingTest) { | ||||
// tx10 is just before tx6 | // tx10 is just before tx6 | ||||
sortedOrder.insert(sortedOrder.begin() + 7, tx10.GetId().ToString()); | sortedOrder.insert(sortedOrder.begin() + 7, tx10.GetId().ToString()); | ||||
CheckSort<descendant_score>(pool, sortedOrder, "MempoolIndexingTest6"); | CheckSort<descendant_score>(pool, sortedOrder, "MempoolIndexingTest6"); | ||||
// there should be 10 transactions in the mempool | // there should be 10 transactions in the mempool | ||||
BOOST_CHECK_EQUAL(pool.size(), 10UL); | BOOST_CHECK_EQUAL(pool.size(), 10UL); | ||||
// Now try removing tx10 and verify the sort order returns to normal | // Now try removing tx10 and verify the sort order returns to normal | ||||
pool.removeRecursive(pool.mapTx.find(tx10.GetId())->GetTx()); | pool.removeRecursive(pool.mapTx.find(tx10.GetId())->GetTx(), | ||||
REMOVAL_REASON_DUMMY); | |||||
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()); | REMOVAL_REASON_DUMMY); | ||||
pool.removeRecursive(pool.mapTx.find(tx8.GetId())->GetTx(), | |||||
REMOVAL_REASON_DUMMY); | |||||
} | } | ||||
BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { | BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { | ||||
CTxMemPool pool; | CTxMemPool pool; | ||||
LOCK2(cs_main, pool.cs); | LOCK2(cs_main, pool.cs); | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 621 Lines • Show Last 20 Lines |