Changeset View
Changeset View
Standalone View
Standalone View
src/test/policyestimator_tests.cpp
// Copyright (c) 2011-2019 The Bitcoin Core developers | // Copyright (c) 2011-2019 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/fees.h> | #include <policy/fees.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
BOOST_FIXTURE_TEST_SUITE(policyestimator_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(policyestimator_tests, TestingSetup) | ||||
BOOST_AUTO_TEST_CASE(MempoolMinimumFeeEstimate) { | BOOST_AUTO_TEST_CASE(MempoolMinimumFeeEstimate) { | ||||
CTxMemPool mpool; | CTxMemPool mpool; | ||||
LOCK2(cs_main, mpool.cs); | LOCK2(cs_main, mpool.cs); | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
// Create a transaction template | // Create a transaction template | ||||
CScript garbage; | CScript garbage; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | for (int64_t i = 0; i < 10000; i++) { | ||||
// The average should end up as 1/2 * 100 * | // The average should end up as 1/2 * 100 * | ||||
// DEFAULT_BLOCK_MIN_TX_FEE_PER_KB | // DEFAULT_BLOCK_MIN_TX_FEE_PER_KB | ||||
mpool.addUnchecked(entry.Fee((i + 1) * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB) | mpool.addUnchecked(entry.Fee((i + 1) * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB) | ||||
.Time(GetTime()) | .Time(GetTime()) | ||||
.Height(blocknum) | .Height(blocknum) | ||||
.FromTx(tx)); | .FromTx(tx)); | ||||
} | } | ||||
// Trim to size. GetMinFee should be more than 10000 * | // Trim to size. GetMinFee should be more than 10000 * | ||||
// DEFAULT_BLOCK_MIN_TX_FEE_PER_KB But the estimateFee should be | // DEFAULT_BLOCK_MIN_TX_FEE_PER_KB, but the estimateFee should remain | ||||
// unchanged. | // unchanged. | ||||
mpool.TrimToSize(1); | mpool.TrimToSize(1); | ||||
BOOST_CHECK(mpool.GetMinFee(1) >= | BOOST_CHECK(mpool.GetMinFee(1) >= | ||||
CFeeRate(10000 * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB, | CFeeRate(10000 * DEFAULT_BLOCK_MIN_TX_FEE_PER_KB, | ||||
CTransaction(tx).GetTotalSize())); | CTransaction(tx).GetTotalSize())); | ||||
BOOST_CHECK_MESSAGE(mpool.estimateFee() == mpool.GetMinFee(1), | BOOST_CHECK_MESSAGE(mpool.estimateFee() == mpool.GetMinFee(1), | ||||
"Confirm blocks has failed"); | "Confirm blocks has failed"); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |