diff --git a/src/test/mempool_tests.cpp b/src/test/mempool_tests.cpp --- a/src/test/mempool_tests.cpp +++ b/src/test/mempool_tests.cpp @@ -14,6 +14,48 @@ BOOST_FIXTURE_TEST_SUITE(mempool_tests, TestingSetup) +BOOST_AUTO_TEST_CASE(TestPackageAccounting) { + CTxMemPool testPool; + TestMemPoolEntryHelper entry; + CMutableTransaction tx; + + tx.vin.resize(1); + tx.vin[0].scriptSig = CScript(); + tx.vout.resize(1); + tx.vout[0].scriptPubKey = CScript() << OP_TRUE; + tx.vout[0].nValue = 10 * SATOSHI; + testPool.addUnchecked(tx.GetId(), entry.FromTx(tx)); + + TxId parentOfAll = tx.GetId(); + + Amount totalFee = Amount::zero(); + size_t totalSize = CTransaction(tx).GetTotalSize(); + std::vector txIds; + for (int64_t i = 0; i < 100; i++) { + // Recycle the transaction + TxId parentId = tx.GetId(); + txIds.push_back(parentId); + tx.vin[0].prevout = COutPoint(tx.GetId(), 0); + testPool.addUnchecked(tx.GetId(), entry.Fee(i * SATOSHI).FromTx(tx)); + + totalFee += i * SATOSHI; + totalSize += CTransaction(tx).GetTotalSize(); + CTxMemPoolEntry parentEntry = *testPool.mapTx.find(parentOfAll); + CTxMemPoolEntry latestEntry = *testPool.mapTx.find(tx.GetId()); + + BOOST_CHECK_EQUAL(latestEntry.GetCountWithAncestors(), i + 2); + BOOST_CHECK_EQUAL(latestEntry.GetSizeWithAncestors(), totalSize); + BOOST_CHECK_EQUAL(latestEntry.GetModFeesWithAncestors(), totalFee); + + BOOST_CHECK_EQUAL(parentEntry.GetCountWithDescendants(), + latestEntry.GetCountWithAncestors()); + BOOST_CHECK_EQUAL(parentEntry.GetSizeWithDescendants(), + latestEntry.GetSizeWithAncestors()); + BOOST_CHECK_EQUAL(parentEntry.GetModFeesWithDescendants(), + latestEntry.GetModFeesWithAncestors()); + } +} + BOOST_AUTO_TEST_CASE(MempoolRemoveTest) { // Test CTxMemPool::remove functionality @@ -323,10 +365,10 @@ */ // take out tx9, tx8 from the beginning sortedOrder.erase(sortedOrder.begin(), sortedOrder.begin() + 2); - sortedOrder.insert(sortedOrder.begin() + 5, tx9.GetId().ToString()); - sortedOrder.insert(sortedOrder.begin() + 6, tx8.GetId().ToString()); - // tx10 is just before tx6 - sortedOrder.insert(sortedOrder.begin() + 7, tx10.GetId().ToString()); + sortedOrder.insert(sortedOrder.begin() + 7, tx9.GetId().ToString()); + sortedOrder.insert(sortedOrder.begin() + 8, tx8.GetId().ToString()); + // tx10 is before tx7 + sortedOrder.insert(sortedOrder.begin() + 9, tx10.GetId().ToString()); CheckSort(pool, sortedOrder, "MempoolIndexingTest6"); // there should be 10 transactions in the mempool @@ -468,7 +510,7 @@ // CTxMemPoolEntry entry7(tx7, fee, 2, 10.0, 1, true); pool.addUnchecked(tx7.GetId(), entry.Fee(Amount(fee)).FromTx(tx7)); BOOST_CHECK_EQUAL(pool.size(), 7UL); - sortedOrder.insert(sortedOrder.begin() + 1, tx7.GetId().ToString()); + sortedOrder.insert(sortedOrder.begin(), tx7.GetId().ToString()); CheckSort(pool, sortedOrder, "MempoolAncestorIndexingTest3"); @@ -477,7 +519,7 @@ vtx.push_back(MakeTransactionRef(tx6)); pool.removeForBlock(vtx, 1); - sortedOrder.erase(sortedOrder.begin() + 1); + sortedOrder.erase(sortedOrder.begin()); // Ties are broken by hash if (tx3.GetId() < tx6.GetId()) { sortedOrder.pop_back();