Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show All 39 Lines | BOOST_AUTO_TEST_CASE(TestPackageAccounting) { | ||||
// Add some outpoints to the tracking vector | // Add some outpoints to the tracking vector | ||||
for (size_t i = 0; i < maxOutputs; i++) { | for (size_t i = 0; i < maxOutputs; i++) { | ||||
outpoints.emplace_back(COutPoint(parentOfAllId, i)); | outpoints.emplace_back(COutPoint(parentOfAllId, i)); | ||||
} | } | ||||
Amount totalFee = Amount::zero(); | Amount totalFee = Amount::zero(); | ||||
size_t totalSize = CTransaction(parentOfAll).GetTotalSize(); | size_t totalSize = CTransaction(parentOfAll).GetTotalSize(); | ||||
size_t totalVirtualSize = totalSize; | |||||
int64_t totalSigOpCount = 0; | int64_t totalSigOpCount = 0; | ||||
// Generate 100 transactions | // Generate 100 transactions | ||||
for (size_t totalTransactions = 0; totalTransactions < 100; | for (size_t totalTransactions = 0; totalTransactions < 100; | ||||
totalTransactions++) { | totalTransactions++) { | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
uint64_t minAncestors = std::numeric_limits<size_t>::max(); | uint64_t minAncestors = std::numeric_limits<size_t>::max(); | ||||
uint64_t maxAncestors = 0; | uint64_t maxAncestors = 0; | ||||
Amount minFees = MAX_MONEY; | Amount minFees = MAX_MONEY; | ||||
Amount maxFees = Amount::zero(); | Amount maxFees = Amount::zero(); | ||||
uint64_t minSize = std::numeric_limits<size_t>::max(); | uint64_t minSize = std::numeric_limits<size_t>::max(); | ||||
uint64_t maxSize = 0; | uint64_t maxSize = 0; | ||||
uint64_t minVirtualSize = std::numeric_limits<size_t>::max(); | |||||
uint64_t maxVirtualSize = 0; | |||||
int64_t minSigOpCount = std::numeric_limits<int64_t>::max(); | int64_t minSigOpCount = std::numeric_limits<int64_t>::max(); | ||||
int64_t maxSigOpCount = 0; | int64_t maxSigOpCount = 0; | ||||
// Consume random inputs, but make sure we don't consume more than | // Consume random inputs, but make sure we don't consume more than | ||||
// available | // available | ||||
for (size_t input = std::min(InsecureRandRange(maxOutputs) + 1, | for (size_t input = std::min(InsecureRandRange(maxOutputs) + 1, | ||||
uint64_t(outpoints.size())); | uint64_t(outpoints.size())); | ||||
input > 0; input--) { | input > 0; input--) { | ||||
std::swap(outpoints[InsecureRandRange(outpoints.size())], | std::swap(outpoints[InsecureRandRange(outpoints.size())], | ||||
Show All 10 Lines | for (size_t totalTransactions = 0; totalTransactions < 100; | ||||
minAncestors = | minAncestors = | ||||
std::min(minAncestors, parent.GetCountWithAncestors()); | std::min(minAncestors, parent.GetCountWithAncestors()); | ||||
maxAncestors += parent.GetCountWithAncestors(); | maxAncestors += parent.GetCountWithAncestors(); | ||||
minFees = std::min(minFees, parent.GetModFeesWithAncestors()); | minFees = std::min(minFees, parent.GetModFeesWithAncestors()); | ||||
maxFees += parent.GetModFeesWithAncestors(); | maxFees += parent.GetModFeesWithAncestors(); | ||||
minSize = std::min(minSize, parent.GetSizeWithAncestors()); | minSize = std::min(minSize, parent.GetSizeWithAncestors()); | ||||
maxSize += parent.GetSizeWithAncestors(); | maxSize += parent.GetSizeWithAncestors(); | ||||
minVirtualSize = | |||||
std::min(minSize, parent.GetVirtualSizeWithAncestors()); | |||||
maxVirtualSize += parent.GetVirtualSizeWithAncestors(); | |||||
minSigOpCount = | minSigOpCount = | ||||
std::min(minSigOpCount, parent.GetSigOpCountWithAncestors()); | std::min(minSigOpCount, parent.GetSigOpCountWithAncestors()); | ||||
maxSigOpCount += parent.GetSigOpCountWithAncestors(); | maxSigOpCount += parent.GetSigOpCountWithAncestors(); | ||||
} | } | ||||
// Produce random number of outputs | // Produce random number of outputs | ||||
for (size_t output = InsecureRandRange(maxOutputs) + 1; output > 0; | for (size_t output = InsecureRandRange(maxOutputs) + 1; output > 0; | ||||
output--) { | output--) { | ||||
Show All 15 Lines | for (size_t totalTransactions = 0; totalTransactions < 100; | ||||
// Add this transaction to the totals. | // Add this transaction to the totals. | ||||
minAncestors += 1; | minAncestors += 1; | ||||
maxAncestors += 1; | maxAncestors += 1; | ||||
minFees += randFee; | minFees += randFee; | ||||
maxFees += randFee; | maxFees += randFee; | ||||
minSize += CTransaction(tx).GetTotalSize(); | minSize += CTransaction(tx).GetTotalSize(); | ||||
maxSize += CTransaction(tx).GetTotalSize(); | maxSize += CTransaction(tx).GetTotalSize(); | ||||
minVirtualSize += GetVirtualTransactionSize( | |||||
CTransaction(tx).GetTotalSize(), randSigOpCount); | |||||
maxVirtualSize += GetVirtualTransactionSize( | |||||
CTransaction(tx).GetTotalSize(), randSigOpCount); | |||||
minSigOpCount += randSigOpCount; | minSigOpCount += randSigOpCount; | ||||
maxSigOpCount += randSigOpCount; | maxSigOpCount += randSigOpCount; | ||||
// Calculate overall values | // Calculate overall values | ||||
totalFee += randFee; | totalFee += randFee; | ||||
totalSize += CTransaction(tx).GetTotalSize(); | totalSize += CTransaction(tx).GetTotalSize(); | ||||
totalVirtualSize += GetVirtualTransactionSize( | |||||
CTransaction(tx).GetTotalSize(), randSigOpCount); | |||||
totalSigOpCount += randSigOpCount; | totalSigOpCount += randSigOpCount; | ||||
CTxMemPoolEntry parentEntry = *testPool.mapTx.find(parentOfAllId); | CTxMemPoolEntry parentEntry = *testPool.mapTx.find(parentOfAllId); | ||||
CTxMemPoolEntry latestEntry = *testPool.mapTx.find(curId); | CTxMemPoolEntry latestEntry = *testPool.mapTx.find(curId); | ||||
// Ensure values are within the expected ranges | // Ensure values are within the expected ranges | ||||
BOOST_CHECK(latestEntry.GetCountWithAncestors() >= minAncestors); | BOOST_CHECK(latestEntry.GetCountWithAncestors() >= minAncestors); | ||||
BOOST_CHECK(latestEntry.GetCountWithAncestors() <= maxAncestors); | BOOST_CHECK(latestEntry.GetCountWithAncestors() <= maxAncestors); | ||||
BOOST_CHECK(latestEntry.GetSizeWithAncestors() >= minSize); | BOOST_CHECK(latestEntry.GetSizeWithAncestors() >= minSize); | ||||
BOOST_CHECK(latestEntry.GetSizeWithAncestors() <= maxSize); | BOOST_CHECK(latestEntry.GetSizeWithAncestors() <= maxSize); | ||||
BOOST_CHECK(latestEntry.GetVirtualSizeWithAncestors() >= | |||||
minVirtualSize); | |||||
BOOST_CHECK(latestEntry.GetVirtualSizeWithAncestors() <= | |||||
maxVirtualSize); | |||||
BOOST_CHECK(latestEntry.GetSigOpCountWithAncestors() >= minSigOpCount); | BOOST_CHECK(latestEntry.GetSigOpCountWithAncestors() >= minSigOpCount); | ||||
BOOST_CHECK(latestEntry.GetSigOpCountWithAncestors() <= maxSigOpCount); | BOOST_CHECK(latestEntry.GetSigOpCountWithAncestors() <= maxSigOpCount); | ||||
BOOST_CHECK(latestEntry.GetModFeesWithAncestors() >= minFees); | BOOST_CHECK(latestEntry.GetModFeesWithAncestors() >= minFees); | ||||
BOOST_CHECK(latestEntry.GetModFeesWithAncestors() <= maxFees); | BOOST_CHECK(latestEntry.GetModFeesWithAncestors() <= maxFees); | ||||
BOOST_CHECK_EQUAL(parentEntry.GetCountWithDescendants(), | BOOST_CHECK_EQUAL(parentEntry.GetCountWithDescendants(), | ||||
testPool.mapTx.size()); | testPool.mapTx.size()); | ||||
BOOST_CHECK_EQUAL(parentEntry.GetSizeWithDescendants(), totalSize); | BOOST_CHECK_EQUAL(parentEntry.GetSizeWithDescendants(), totalSize); | ||||
BOOST_CHECK_EQUAL(parentEntry.GetVirtualSizeWithDescendants(), | |||||
totalVirtualSize); | |||||
BOOST_CHECK_EQUAL(parentEntry.GetModFeesWithDescendants(), totalFee); | BOOST_CHECK_EQUAL(parentEntry.GetModFeesWithDescendants(), totalFee); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(MempoolRemoveTest) { | BOOST_AUTO_TEST_CASE(MempoolRemoveTest) { | ||||
// Test CTxMemPool::remove functionality | // Test CTxMemPool::remove functionality | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
▲ Show 20 Lines • Show All 904 Lines • Show Last 20 Lines |