Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(TestPackageAccounting) { | ||||
} | } | ||||
Amount totalFee = Amount::zero(); | Amount totalFee = Amount::zero(); | ||||
size_t totalSize = CTransaction(parentOfAll).GetTotalSize(); | size_t totalSize = CTransaction(parentOfAll).GetTotalSize(); | ||||
// Generate 100 transactions | // Generate 100 transactions | ||||
for (size_t totalTransactions = 0; totalTransactions < 100; | for (size_t totalTransactions = 0; totalTransactions < 100; | ||||
totalTransactions++) { | totalTransactions++) { | ||||
CMutableTransaction mtx; | 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; | ||||
// 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())], | ||||
outpoints.back()); | outpoints.back()); | ||||
mtx.vin.emplace_back(outpoints.back()); | tx.vin.emplace_back(outpoints.back()); | ||||
outpoints.pop_back(); | outpoints.pop_back(); | ||||
// We don't know exactly how many ancestors this transaction has | // We don't know exactly how many ancestors this transaction has | ||||
// due to possible duplicates. Calculate a valid range based on | // due to possible duplicates. Calculate a valid range based on | ||||
// parents. | // parents. | ||||
CTxMemPoolEntry parent = | CTxMemPoolEntry parent = | ||||
*testPool.mapTx.find(mtx.vin.back().prevout.GetTxId()); | *testPool.mapTx.find(tx.vin.back().prevout.GetTxId()); | ||||
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(); | ||||
} | } | ||||
// 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--) { | ||||
mtx.vout.emplace_back(10 * SATOSHI, CScript() << OP_TRUE); | tx.vout.emplace_back(10 * SATOSHI, CScript() << OP_TRUE); | ||||
} | } | ||||
CTransaction tx(mtx); | |||||
TxId curId = tx.GetId(); | TxId curId = tx.GetId(); | ||||
// Record the outputs | // Record the outputs | ||||
for (size_t output = tx.vout.size(); output > 0; output--) { | for (size_t output = tx.vout.size(); output > 0; output--) { | ||||
outpoints.emplace_back(COutPoint(curId, output)); | outpoints.emplace_back(COutPoint(curId, output)); | ||||
} | } | ||||
Amount randFee = int64_t(InsecureRandRange(300)) * SATOSHI; | Amount randFee = int64_t(InsecureRandRange(300)) * SATOSHI; | ||||
▲ Show 20 Lines • Show All 778 Lines • Show Last 20 Lines |