Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "policy/policy.h" | #include "policy/policy.h" | ||||
#include "txmempool.h" | #include "txmempool.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <list> | #include <list> | ||||
#include <vector> | #include <vector> | ||||
BOOST_FIXTURE_TEST_SUITE(mempool_tests, TestingSetup) | 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<TxId> 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) { | 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 20 Lines • Show All 643 Lines • Show Last 20 Lines |