Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | for (int i = 0; i < 3; i++) { | ||||
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 = Amount(11000LL); | txGrandChild[i].vout[0].nValue = Amount(11000LL); | ||||
} | } | ||||
CTxMemPool testPool(CFeeRate(Amount(0))); | CTxMemPool testPool(CFeeRate(Amount(0))); | ||||
// 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(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)); | ||||
poolSize = testPool.size(); | poolSize = testPool.size(); | ||||
testPool.removeRecursive(txParent); | testPool.removeRecursive(CTransaction(txParent)); | ||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize - 1); | BOOST_CHECK_EQUAL(testPool.size(), poolSize - 1); | ||||
// Parent, children, grandchildren: | // Parent, children, grandchildren: | ||||
testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); | testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); | ||||
for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
testPool.addUnchecked(txChild[i].GetId(), entry.FromTx(txChild[i])); | testPool.addUnchecked(txChild[i].GetId(), entry.FromTx(txChild[i])); | ||||
testPool.addUnchecked(txGrandChild[i].GetId(), | testPool.addUnchecked(txGrandChild[i].GetId(), | ||||
entry.FromTx(txGrandChild[i])); | 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(txChild[0]); | testPool.removeRecursive(CTransaction(txChild[0])); | ||||
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(txGrandChild[0]); | testPool.removeRecursive(CTransaction(txGrandChild[0])); | ||||
BOOST_CHECK_EQUAL(testPool.size(), poolSize); | BOOST_CHECK_EQUAL(testPool.size(), poolSize); | ||||
poolSize = testPool.size(); | poolSize = testPool.size(); | ||||
testPool.removeRecursive(txChild[0]); | testPool.removeRecursive(CTransaction(txChild[0])); | ||||
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(txParent); | testPool.removeRecursive(CTransaction(txParent)); | ||||
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(txChild[i].GetId(), entry.FromTx(txChild[i])); | testPool.addUnchecked(txChild[i].GetId(), entry.FromTx(txChild[i])); | ||||
testPool.addUnchecked(txGrandChild[i].GetId(), | testPool.addUnchecked(txGrandChild[i].GetId(), | ||||
entry.FromTx(txGrandChild[i])); | 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(txParent); | testPool.removeRecursive(CTransaction(txParent)); | ||||
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 561 Lines • Show Last 20 Lines |