diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -304,7 +304,7 @@ tx.vin.resize(1); tx.vout.resize(1); // Keep txs unique unless intended to duplicate. - tx.vout[0].nValue = i; + tx.vout[0].nValue = Amount(i); // Random sizes so we can test memory usage accounting tx.vout[0].scriptPubKey.assign(insecure_rand() & 0x3F, 0); unsigned int height = insecure_rand(); @@ -500,7 +500,7 @@ Coin c1; ss1 >> c1; BOOST_CHECK_EQUAL(c1.IsCoinBase(), false); - BOOST_CHECK_EQUAL(c1.GetHeight(), 203998); + BOOST_CHECK_EQUAL(c1.GetHeight(), 203998U); BOOST_CHECK_EQUAL(c1.GetTxOut().nValue, Amount(60000000000LL)); BOOST_CHECK_EQUAL(HexStr(c1.GetTxOut().scriptPubKey), HexStr(GetScriptForDestination(CKeyID(uint160(ParseHex( @@ -552,12 +552,12 @@ } static const COutPoint OUTPOINT; -static const Amount PRUNED = -1; -static const Amount ABSENT = -2; -static const Amount FAIL = -3; -static const Amount VALUE1 = 100; -static const Amount VALUE2 = 200; -static const Amount VALUE3 = 300; +static const Amount PRUNED(-1); +static const Amount ABSENT(-2); +static const Amount FAIL(-3); +static const Amount VALUE1(100); +static const Amount VALUE2(200); +static const Amount VALUE3(300); static const char DIRTY = CCoinsCacheEntry::DIRTY; static const char FRESH = CCoinsCacheEntry::FRESH; static const char NO_ENTRY = -1; @@ -601,7 +601,7 @@ if (it->second.coin.IsSpent()) { value = PRUNED; } else { - value = it->second.coin.GetTxOut().nValue.GetSatoshis(); + value = it->second.coin.GetTxOut().nValue; } flags = it->second.flags; assert(flags != NO_ENTRY); diff --git a/src/test/compress_tests.cpp b/src/test/compress_tests.cpp --- a/src/test/compress_tests.cpp +++ b/src/test/compress_tests.cpp @@ -40,15 +40,15 @@ } BOOST_AUTO_TEST_CASE(compress_amounts) { - BOOST_CHECK(TestPair(0, 0x0)); - BOOST_CHECK(TestPair(1, 0x1)); + BOOST_CHECK(TestPair(Amount(0), 0x0)); + BOOST_CHECK(TestPair(Amount(1), 0x1)); BOOST_CHECK(TestPair(CENT, 0x7)); BOOST_CHECK(TestPair(COIN, 0x9)); BOOST_CHECK(TestPair(50 * COIN, 0x32)); BOOST_CHECK(TestPair(21000000 * COIN, 0x1406f40)); for (int64_t i = 1; i <= NUM_MULTIPLES_UNIT; i++) { - BOOST_CHECK(TestEncode(i)); + BOOST_CHECK(TestEncode(Amount(i))); } for (int64_t i = 1; i <= NUM_MULTIPLES_CENT; i++) { diff --git a/src/test/main_tests.cpp b/src/test/main_tests.cpp --- a/src/test/main_tests.cpp +++ b/src/test/main_tests.cpp @@ -29,7 +29,7 @@ BOOST_CHECK_EQUAL( GetBlockSubsidy(maxHalvings * consensusParams.nSubsidyHalvingInterval, consensusParams), - 0); + Amount(0)); } static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval) { @@ -48,14 +48,14 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test) { const Consensus::Params &consensusParams = Params(CBaseChainParams::MAIN).GetConsensus(); - Amount nSum = 0; + Amount nSum(0); for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) { Amount nSubsidy = GetBlockSubsidy(nHeight, consensusParams); BOOST_CHECK(nSubsidy <= 50 * COIN); nSum += 1000 * nSubsidy; BOOST_CHECK(MoneyRange(nSum)); } - BOOST_CHECK_EQUAL(nSum, 2099999997690000ULL); + BOOST_CHECK_EQUAL(nSum, Amount(2099999997690000ULL)); } bool ReturnFalse() { 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 @@ -25,7 +25,7 @@ txParent.vout.resize(3); for (int i = 0; i < 3; i++) { txParent.vout[i].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - txParent.vout[i].nValue = 33000LL; + txParent.vout[i].nValue = Amount(33000LL); } CMutableTransaction txChild[3]; for (int i = 0; i < 3; i++) { @@ -35,7 +35,7 @@ txChild[i].vin[0].prevout.n = i; txChild[i].vout.resize(1); txChild[i].vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - txChild[i].vout[0].nValue = 11000LL; + txChild[i].vout[0].nValue = Amount(11000LL); } CMutableTransaction txGrandChild[3]; for (int i = 0; i < 3; i++) { @@ -45,10 +45,10 @@ txGrandChild[i].vin[0].prevout.n = 0; txGrandChild[i].vout.resize(1); txGrandChild[i].vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - txGrandChild[i].vout[0].nValue = 11000LL; + txGrandChild[i].vout[0].nValue = Amount(11000LL); } - CTxMemPool testPool(CFeeRate(0)); + CTxMemPool testPool(CFeeRate(Amount(0))); // Nothing in pool, remove should do nothing: unsigned int poolSize = testPool.size(); @@ -83,7 +83,7 @@ poolSize = testPool.size(); testPool.removeRecursive(txParent); BOOST_CHECK_EQUAL(testPool.size(), poolSize - 5); - BOOST_CHECK_EQUAL(testPool.size(), 0); + BOOST_CHECK_EQUAL(testPool.size(), 0UL); // Add children and grandchildren, but NOT the parent (simulate the parent // being in a block) @@ -98,7 +98,7 @@ poolSize = testPool.size(); testPool.removeRecursive(txParent); BOOST_CHECK_EQUAL(testPool.size(), poolSize - 6); - BOOST_CHECK_EQUAL(testPool.size(), 0); + BOOST_CHECK_EQUAL(testPool.size(), 0UL); } BOOST_AUTO_TEST_CASE(MempoolClearTest) { @@ -112,28 +112,28 @@ txParent.vout.resize(3); for (int i = 0; i < 3; i++) { txParent.vout[i].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - txParent.vout[i].nValue = 33000LL; + txParent.vout[i].nValue = Amount(33000LL); } - CTxMemPool testPool(CFeeRate(0)); + CTxMemPool testPool(CFeeRate(Amount(0))); // Nothing in pool, clear should do nothing: testPool.clear(); - BOOST_CHECK_EQUAL(testPool.size(), 0); + BOOST_CHECK_EQUAL(testPool.size(), 0UL); // Add the transaction testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); - BOOST_CHECK_EQUAL(testPool.size(), 1); - BOOST_CHECK_EQUAL(testPool.mapTx.size(), 1); - BOOST_CHECK_EQUAL(testPool.mapNextTx.size(), 1); - BOOST_CHECK_EQUAL(testPool.vTxHashes.size(), 1); + BOOST_CHECK_EQUAL(testPool.size(), 1UL); + BOOST_CHECK_EQUAL(testPool.mapTx.size(), 1UL); + BOOST_CHECK_EQUAL(testPool.mapNextTx.size(), 1UL); + BOOST_CHECK_EQUAL(testPool.vTxHashes.size(), 1UL); // CTxMemPool's members should be empty after a clear testPool.clear(); - BOOST_CHECK_EQUAL(testPool.size(), 0); - BOOST_CHECK_EQUAL(testPool.mapTx.size(), 0); - BOOST_CHECK_EQUAL(testPool.mapNextTx.size(), 0); - BOOST_CHECK_EQUAL(testPool.vTxHashes.size(), 0); + BOOST_CHECK_EQUAL(testPool.size(), 0UL); + BOOST_CHECK_EQUAL(testPool.mapTx.size(), 0UL); + BOOST_CHECK_EQUAL(testPool.mapNextTx.size(), 0UL); + BOOST_CHECK_EQUAL(testPool.vTxHashes.size(), 0UL); } template @@ -148,49 +148,50 @@ } BOOST_AUTO_TEST_CASE(MempoolIndexingTest) { - CTxMemPool pool(CFeeRate(0)); + CTxMemPool pool(CFeeRate(Amount(0))); TestMemPoolEntryHelper entry; /* 3rd highest fee */ CMutableTransaction tx1 = CMutableTransaction(); tx1.vout.resize(1); tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx1.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx1.vout[0].nValue = 10 * COIN; pool.addUnchecked(tx1.GetId(), - entry.Fee(10000LL).Priority(10.0).FromTx(tx1)); + entry.Fee(Amount(10000LL)).Priority(10.0).FromTx(tx1)); /* highest fee */ CMutableTransaction tx2 = CMutableTransaction(); tx2.vout.resize(1); tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx2.vout[0].nValue = 2 * COIN.GetSatoshis(); + tx2.vout[0].nValue = 2 * COIN; pool.addUnchecked(tx2.GetId(), - entry.Fee(20000LL).Priority(9.0).FromTx(tx2)); + entry.Fee(Amount(20000LL)).Priority(9.0).FromTx(tx2)); /* lowest fee */ CMutableTransaction tx3 = CMutableTransaction(); tx3.vout.resize(1); tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx3.vout[0].nValue = 5 * COIN.GetSatoshis(); - pool.addUnchecked(tx3.GetId(), entry.Fee(0LL).Priority(100.0).FromTx(tx3)); + tx3.vout[0].nValue = 5 * COIN; + pool.addUnchecked(tx3.GetId(), + entry.Fee(Amount(0LL)).Priority(100.0).FromTx(tx3)); /* 2nd highest fee */ CMutableTransaction tx4 = CMutableTransaction(); tx4.vout.resize(1); tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx4.vout[0].nValue = 6 * COIN.GetSatoshis(); + tx4.vout[0].nValue = 6 * COIN; pool.addUnchecked(tx4.GetId(), - entry.Fee(15000LL).Priority(1.0).FromTx(tx4)); + entry.Fee(Amount(15000LL)).Priority(1.0).FromTx(tx4)); /* equal fee rate to tx1, but newer */ CMutableTransaction tx5 = CMutableTransaction(); tx5.vout.resize(1); tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx5.vout[0].nValue = 11 * COIN.GetSatoshis(); + tx5.vout[0].nValue = 11 * COIN; entry.nTime = 1; entry.dPriority = 10.0; - pool.addUnchecked(tx5.GetId(), entry.Fee(10000LL).FromTx(tx5)); - BOOST_CHECK_EQUAL(pool.size(), 5); + pool.addUnchecked(tx5.GetId(), entry.Fee(Amount(10000LL)).FromTx(tx5)); + BOOST_CHECK_EQUAL(pool.size(), 5UL); std::vector sortedOrder; sortedOrder.resize(5); @@ -206,9 +207,9 @@ CMutableTransaction tx6 = CMutableTransaction(); tx6.vout.resize(1); tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx6.vout[0].nValue = 20 * COIN.GetSatoshis(); - pool.addUnchecked(tx6.GetId(), entry.Fee(0LL).FromTx(tx6)); - BOOST_CHECK_EQUAL(pool.size(), 6); + tx6.vout[0].nValue = 20 * COIN; + pool.addUnchecked(tx6.GetId(), entry.Fee(Amount(0LL)).FromTx(tx6)); + BOOST_CHECK_EQUAL(pool.size(), 6UL); // Check that at this point, tx6 is sorted low sortedOrder.insert(sortedOrder.begin(), tx6.GetId().ToString()); CheckSort(pool, sortedOrder); @@ -221,21 +222,21 @@ tx7.vin[0].scriptSig = CScript() << OP_11; tx7.vout.resize(2); tx7.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx7.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx7.vout[0].nValue = 10 * COIN; tx7.vout[1].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx7.vout[1].nValue = 1 * COIN.GetSatoshis(); + tx7.vout[1].nValue = 1 * COIN; CTxMemPool::setEntries setAncestorsCalculated; std::string dummy; BOOST_CHECK_EQUAL( - pool.CalculateMemPoolAncestors(entry.Fee(2000000LL).FromTx(tx7), + pool.CalculateMemPoolAncestors(entry.Fee(Amount(2000000LL)).FromTx(tx7), setAncestorsCalculated, 100, 1000000, 1000, 1000000, dummy), true); BOOST_CHECK(setAncestorsCalculated == setAncestors); pool.addUnchecked(tx7.GetId(), entry.FromTx(tx7), setAncestors); - BOOST_CHECK_EQUAL(pool.size(), 7); + BOOST_CHECK_EQUAL(pool.size(), 7UL); // Now tx6 should be sorted higher (high fee child): tx7, tx6, tx2, ... sortedOrder.erase(sortedOrder.begin()); @@ -250,9 +251,9 @@ tx8.vin[0].scriptSig = CScript() << OP_11; tx8.vout.resize(1); tx8.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx8.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx8.vout[0].nValue = 10 * COIN; setAncestors.insert(pool.mapTx.find(tx7.GetId())); - pool.addUnchecked(tx8.GetId(), entry.Fee(0LL).Time(2).FromTx(tx8), + pool.addUnchecked(tx8.GetId(), entry.Fee(Amount(0LL)).Time(2).FromTx(tx8), setAncestors); // Now tx8 should be sorted low, but tx6/tx both high @@ -266,12 +267,12 @@ tx9.vin[0].scriptSig = CScript() << OP_11; tx9.vout.resize(1); tx9.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx9.vout[0].nValue = 1 * COIN.GetSatoshis(); - pool.addUnchecked(tx9.GetId(), entry.Fee(0LL).Time(3).FromTx(tx9), + tx9.vout[0].nValue = 1 * COIN; + pool.addUnchecked(tx9.GetId(), entry.Fee(Amount(0LL)).Time(3).FromTx(tx9), setAncestors); // tx9 should be sorted low - BOOST_CHECK_EQUAL(pool.size(), 9); + BOOST_CHECK_EQUAL(pool.size(), 9UL); sortedOrder.insert(sortedOrder.begin(), tx9.GetId().ToString()); CheckSort(pool, sortedOrder); @@ -288,14 +289,14 @@ tx10.vin[1].scriptSig = CScript() << OP_11; tx10.vout.resize(1); tx10.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx10.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx10.vout[0].nValue = 10 * COIN; setAncestorsCalculated.clear(); - BOOST_CHECK_EQUAL( - pool.CalculateMemPoolAncestors(entry.Fee(200000LL).Time(4).FromTx(tx10), - setAncestorsCalculated, 100, 1000000, - 1000, 1000000, dummy), - true); + BOOST_CHECK_EQUAL(pool.CalculateMemPoolAncestors( + entry.Fee(Amount(200000LL)).Time(4).FromTx(tx10), + setAncestorsCalculated, 100, 1000000, 1000, 1000000, + dummy), + true); BOOST_CHECK(setAncestorsCalculated == setAncestors); pool.addUnchecked(tx10.GetId(), entry.FromTx(tx10), setAncestors); @@ -324,7 +325,7 @@ CheckSort(pool, sortedOrder); // there should be 10 transactions in the mempool - BOOST_CHECK_EQUAL(pool.size(), 10); + BOOST_CHECK_EQUAL(pool.size(), 10UL); // Now try removing tx10 and verify the sort order returns to normal pool.removeRecursive(pool.mapTx.find(tx10.GetId())->GetTx()); @@ -364,48 +365,49 @@ } BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest) { - CTxMemPool pool(CFeeRate(0)); + CTxMemPool pool(CFeeRate(Amount(0))); TestMemPoolEntryHelper entry; /* 3rd highest fee */ CMutableTransaction tx1 = CMutableTransaction(); tx1.vout.resize(1); tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx1.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx1.vout[0].nValue = 10 * COIN; pool.addUnchecked(tx1.GetId(), - entry.Fee(10000LL).Priority(10.0).FromTx(tx1)); + entry.Fee(Amount(10000LL)).Priority(10.0).FromTx(tx1)); /* highest fee */ CMutableTransaction tx2 = CMutableTransaction(); tx2.vout.resize(1); tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx2.vout[0].nValue = 2 * COIN.GetSatoshis(); + tx2.vout[0].nValue = 2 * COIN; pool.addUnchecked(tx2.GetId(), - entry.Fee(20000LL).Priority(9.0).FromTx(tx2)); + entry.Fee(Amount(20000LL)).Priority(9.0).FromTx(tx2)); uint64_t tx2Size = GetTransactionSize(tx2); /* lowest fee */ CMutableTransaction tx3 = CMutableTransaction(); tx3.vout.resize(1); tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx3.vout[0].nValue = 5 * COIN.GetSatoshis(); - pool.addUnchecked(tx3.GetId(), entry.Fee(0LL).Priority(100.0).FromTx(tx3)); + tx3.vout[0].nValue = 5 * COIN; + pool.addUnchecked(tx3.GetId(), + entry.Fee(Amount(0LL)).Priority(100.0).FromTx(tx3)); /* 2nd highest fee */ CMutableTransaction tx4 = CMutableTransaction(); tx4.vout.resize(1); tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx4.vout[0].nValue = 6 * COIN.GetSatoshis(); + tx4.vout[0].nValue = 6 * COIN; pool.addUnchecked(tx4.GetId(), - entry.Fee(15000LL).Priority(1.0).FromTx(tx4)); + entry.Fee(Amount(15000LL)).Priority(1.0).FromTx(tx4)); /* equal fee rate to tx1, but newer */ CMutableTransaction tx5 = CMutableTransaction(); tx5.vout.resize(1); tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx5.vout[0].nValue = 11 * COIN.GetSatoshis(); - pool.addUnchecked(tx5.GetId(), entry.Fee(10000LL).FromTx(tx5)); - BOOST_CHECK_EQUAL(pool.size(), 5); + tx5.vout[0].nValue = 11 * COIN; + pool.addUnchecked(tx5.GetId(), entry.Fee(Amount(10000LL)).FromTx(tx5)); + BOOST_CHECK_EQUAL(pool.size(), 5UL); std::vector sortedOrder; sortedOrder.resize(5); @@ -430,11 +432,11 @@ CMutableTransaction tx6 = CMutableTransaction(); tx6.vout.resize(1); tx6.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx6.vout[0].nValue = 20 * COIN.GetSatoshis(); + tx6.vout[0].nValue = 20 * COIN; uint64_t tx6Size = GetTransactionSize(tx6); - pool.addUnchecked(tx6.GetId(), entry.Fee(0LL).FromTx(tx6)); - BOOST_CHECK_EQUAL(pool.size(), 6); + pool.addUnchecked(tx6.GetId(), entry.Fee(Amount(0LL)).FromTx(tx6)); + BOOST_CHECK_EQUAL(pool.size(), 6UL); // Ties are broken by hash if (tx3.GetId() < tx6.GetId()) { sortedOrder.push_back(tx6.GetId().ToString()); @@ -450,15 +452,15 @@ tx7.vin[0].scriptSig = CScript() << OP_11; tx7.vout.resize(1); tx7.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; - tx7.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx7.vout[0].nValue = 10 * COIN; uint64_t tx7Size = GetTransactionSize(tx7); /* set the fee to just below tx2's feerate when including ancestor */ Amount fee((20000 / tx2Size) * (tx7Size + tx6Size) - 1); // CTxMemPoolEntry entry7(tx7, fee, 2, 10.0, 1, true); - pool.addUnchecked(tx7.GetId(), entry.Fee(fee).FromTx(tx7)); - BOOST_CHECK_EQUAL(pool.size(), 7); + pool.addUnchecked(tx7.GetId(), entry.Fee(Amount(fee)).FromTx(tx7)); + BOOST_CHECK_EQUAL(pool.size(), 7UL); sortedOrder.insert(sortedOrder.begin() + 1, tx7.GetId().ToString()); CheckSort(pool, sortedOrder); @@ -478,7 +480,7 @@ } BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) { - CTxMemPool pool(CFeeRate(1000)); + CTxMemPool pool(CFeeRate(Amount(1000))); TestMemPoolEntryHelper entry; entry.dPriority = 10.0; @@ -487,16 +489,18 @@ tx1.vin[0].scriptSig = CScript() << OP_1; tx1.vout.resize(1); tx1.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL; - tx1.vout[0].nValue = 10 * COIN.GetSatoshis(); - pool.addUnchecked(tx1.GetId(), entry.Fee(10000LL).FromTx(tx1, &pool)); + tx1.vout[0].nValue = 10 * COIN; + pool.addUnchecked(tx1.GetId(), + entry.Fee(Amount(10000LL)).FromTx(tx1, &pool)); CMutableTransaction tx2 = CMutableTransaction(); tx2.vin.resize(1); tx2.vin[0].scriptSig = CScript() << OP_2; tx2.vout.resize(1); tx2.vout[0].scriptPubKey = CScript() << OP_2 << OP_EQUAL; - tx2.vout[0].nValue = 10 * COIN.GetSatoshis(); - pool.addUnchecked(tx2.GetId(), entry.Fee(5000LL).FromTx(tx2, &pool)); + tx2.vout[0].nValue = 10 * COIN; + pool.addUnchecked(tx2.GetId(), + entry.Fee(Amount(5000LL)).FromTx(tx2, &pool)); // should do nothing pool.TrimToSize(pool.DynamicMemoryUsage()); @@ -515,8 +519,9 @@ tx3.vin[0].scriptSig = CScript() << OP_2; tx3.vout.resize(1); tx3.vout[0].scriptPubKey = CScript() << OP_3 << OP_EQUAL; - tx3.vout[0].nValue = 10 * COIN.GetSatoshis(); - pool.addUnchecked(tx3.GetId(), entry.Fee(20000LL).FromTx(tx3, &pool)); + tx3.vout[0].nValue = 10 * COIN; + pool.addUnchecked(tx3.GetId(), + entry.Fee(Amount(20000LL)).FromTx(tx3, &pool)); // tx3 should pay for tx2 (CPFP) pool.TrimToSize(pool.DynamicMemoryUsage() * 3 / 4); @@ -530,10 +535,10 @@ BOOST_CHECK(!pool.exists(tx2.GetId())); BOOST_CHECK(!pool.exists(tx3.GetId())); - CFeeRate maxFeeRateRemoved(25000, GetTransactionSize(tx3) + - GetTransactionSize(tx2)); + CFeeRate maxFeeRateRemoved(Amount(25000), GetTransactionSize(tx3) + + GetTransactionSize(tx2)); BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), - maxFeeRateRemoved.GetFeePerK() + 1000); + maxFeeRateRemoved.GetFeePerK() + Amount(1000)); CMutableTransaction tx4 = CMutableTransaction(); tx4.vin.resize(2); @@ -543,9 +548,9 @@ tx4.vin[1].scriptSig = CScript() << OP_4; tx4.vout.resize(2); tx4.vout[0].scriptPubKey = CScript() << OP_4 << OP_EQUAL; - tx4.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx4.vout[0].nValue = 10 * COIN; tx4.vout[1].scriptPubKey = CScript() << OP_4 << OP_EQUAL; - tx4.vout[1].nValue = 10 * COIN.GetSatoshis(); + tx4.vout[1].nValue = 10 * COIN; CMutableTransaction tx5 = CMutableTransaction(); tx5.vin.resize(2); @@ -555,9 +560,9 @@ tx5.vin[1].scriptSig = CScript() << OP_5; tx5.vout.resize(2); tx5.vout[0].scriptPubKey = CScript() << OP_5 << OP_EQUAL; - tx5.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx5.vout[0].nValue = 10 * COIN; tx5.vout[1].scriptPubKey = CScript() << OP_5 << OP_EQUAL; - tx5.vout[1].nValue = 10 * COIN.GetSatoshis(); + tx5.vout[1].nValue = 10 * COIN; CMutableTransaction tx6 = CMutableTransaction(); tx6.vin.resize(2); @@ -567,9 +572,9 @@ tx6.vin[1].scriptSig = CScript() << OP_6; tx6.vout.resize(2); tx6.vout[0].scriptPubKey = CScript() << OP_6 << OP_EQUAL; - tx6.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx6.vout[0].nValue = 10 * COIN; tx6.vout[1].scriptPubKey = CScript() << OP_6 << OP_EQUAL; - tx6.vout[1].nValue = 10 * COIN.GetSatoshis(); + tx6.vout[1].nValue = 10 * COIN; CMutableTransaction tx7 = CMutableTransaction(); tx7.vin.resize(2); @@ -579,14 +584,18 @@ tx7.vin[1].scriptSig = CScript() << OP_6; tx7.vout.resize(2); tx7.vout[0].scriptPubKey = CScript() << OP_7 << OP_EQUAL; - tx7.vout[0].nValue = 10 * COIN.GetSatoshis(); + tx7.vout[0].nValue = 10 * COIN; tx7.vout[1].scriptPubKey = CScript() << OP_7 << OP_EQUAL; - tx7.vout[1].nValue = 10 * COIN.GetSatoshis(); + tx7.vout[1].nValue = 10 * COIN; - pool.addUnchecked(tx4.GetId(), entry.Fee(7000LL).FromTx(tx4, &pool)); - pool.addUnchecked(tx5.GetId(), entry.Fee(1000LL).FromTx(tx5, &pool)); - pool.addUnchecked(tx6.GetId(), entry.Fee(1100LL).FromTx(tx6, &pool)); - pool.addUnchecked(tx7.GetId(), entry.Fee(9000LL).FromTx(tx7, &pool)); + pool.addUnchecked(tx4.GetId(), + entry.Fee(Amount(7000LL)).FromTx(tx4, &pool)); + pool.addUnchecked(tx5.GetId(), + entry.Fee(Amount(1000LL)).FromTx(tx5, &pool)); + pool.addUnchecked(tx6.GetId(), + entry.Fee(Amount(1100LL)).FromTx(tx6, &pool)); + pool.addUnchecked(tx7.GetId(), + entry.Fee(Amount(9000LL)).FromTx(tx7, &pool)); // we only require this remove, at max, 2 txn, because its not clear what // we're really optimizing for aside from that @@ -596,8 +605,10 @@ BOOST_CHECK(!pool.exists(tx7.GetId())); if (!pool.exists(tx5.GetId())) - pool.addUnchecked(tx5.GetId(), entry.Fee(1000LL).FromTx(tx5, &pool)); - pool.addUnchecked(tx7.GetId(), entry.Fee(9000LL).FromTx(tx7, &pool)); + pool.addUnchecked(tx5.GetId(), + entry.Fee(Amount(1000LL)).FromTx(tx5, &pool)); + pool.addUnchecked(tx7.GetId(), + entry.Fee(Amount(9000LL)).FromTx(tx7, &pool)); // should maximize mempool size by only removing 5/7 pool.TrimToSize(pool.DynamicMemoryUsage() / 2); @@ -606,26 +617,28 @@ BOOST_CHECK(pool.exists(tx6.GetId())); BOOST_CHECK(!pool.exists(tx7.GetId())); - pool.addUnchecked(tx5.GetId(), entry.Fee(1000LL).FromTx(tx5, &pool)); - pool.addUnchecked(tx7.GetId(), entry.Fee(9000LL).FromTx(tx7, &pool)); + pool.addUnchecked(tx5.GetId(), + entry.Fee(Amount(1000LL)).FromTx(tx5, &pool)); + pool.addUnchecked(tx7.GetId(), + entry.Fee(Amount(9000LL)).FromTx(tx7, &pool)); std::vector vtx; SetMockTime(42); SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE); BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), - maxFeeRateRemoved.GetFeePerK() + 1000); + maxFeeRateRemoved.GetFeePerK() + Amount(1000)); // ... we should keep the same min fee until we get a block pool.removeForBlock(vtx, 1); SetMockTime(42 + 2 * CTxMemPool::ROLLING_FEE_HALFLIFE); BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), - (maxFeeRateRemoved.GetFeePerK() + 1000) / 2); + (maxFeeRateRemoved.GetFeePerK() + Amount(1000)) / 2); // ... then feerate should drop 1/2 each halflife SetMockTime(42 + 2 * CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE / 2); BOOST_CHECK_EQUAL( pool.GetMinFee(pool.DynamicMemoryUsage() * 5 / 2).GetFeePerK(), - (maxFeeRateRemoved.GetFeePerK() + 1000) / 4); + (maxFeeRateRemoved.GetFeePerK() + Amount(1000)) / 4); // ... with a 1/2 halflife when mempool is < 1/2 its target size SetMockTime(42 + 2 * CTxMemPool::ROLLING_FEE_HALFLIFE + @@ -633,19 +646,19 @@ CTxMemPool::ROLLING_FEE_HALFLIFE / 4); BOOST_CHECK_EQUAL( pool.GetMinFee(pool.DynamicMemoryUsage() * 9 / 2).GetFeePerK(), - (maxFeeRateRemoved.GetFeePerK() + 1000) / 8); + (maxFeeRateRemoved.GetFeePerK() + Amount(1000)) / 8); // ... with a 1/4 halflife when mempool is < 1/4 its target size SetMockTime(42 + 7 * CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE / 2 + CTxMemPool::ROLLING_FEE_HALFLIFE / 4); - BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), 1000); + BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), Amount(1000)); // ... but feerate should never drop below 1000 SetMockTime(42 + 8 * CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE / 2 + CTxMemPool::ROLLING_FEE_HALFLIFE / 4); - BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), 0); + BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), Amount(0)); // ... unless it has gone all the way to 0 (after getting past 1000/2) SetMockTime(0);