Skip to content

Commit e93a236

Browse files
committed
add estimateSmartFee to the unit test
1 parent 6303051 commit e93a236

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/policyestimator_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
9090
BOOST_CHECK(mpool.estimateFee(3) == CFeeRate(0));
9191
BOOST_CHECK(mpool.estimateFee(4).GetFeePerK() < 8*baseRate.GetFeePerK() + deltaFee);
9292
BOOST_CHECK(mpool.estimateFee(4).GetFeePerK() > 8*baseRate.GetFeePerK() - deltaFee);
93+
int answerFound;
94+
BOOST_CHECK(mpool.estimateSmartFee(1, &answerFound) == mpool.estimateFee(4) && answerFound == 4);
95+
BOOST_CHECK(mpool.estimateSmartFee(3, &answerFound) == mpool.estimateFee(4) && answerFound == 4);
96+
BOOST_CHECK(mpool.estimateSmartFee(4, &answerFound) == mpool.estimateFee(4) && answerFound == 4);
97+
BOOST_CHECK(mpool.estimateSmartFee(8, &answerFound) == mpool.estimateFee(8) && answerFound == 8);
9398
}
9499
}
95100

@@ -142,9 +147,12 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
142147
mpool.removeForBlock(block, ++blocknum, dummyConflicted);
143148
}
144149

150+
int answerFound;
145151
for (int i = 1; i < 10;i++) {
146152
BOOST_CHECK(mpool.estimateFee(i) == CFeeRate(0) || mpool.estimateFee(i).GetFeePerK() > origFeeEst[i-1] - deltaFee);
153+
BOOST_CHECK(mpool.estimateSmartFee(i, &answerFound).GetFeePerK() > origFeeEst[answerFound-1] - deltaFee);
147154
BOOST_CHECK(mpool.estimatePriority(i) == -1 || mpool.estimatePriority(i) > origPriEst[i-1] - deltaPri);
155+
BOOST_CHECK(mpool.estimateSmartPriority(i, &answerFound) > origPriEst[answerFound-1] - deltaPri);
148156
}
149157

150158
// Mine all those transactions
@@ -184,6 +192,18 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
184192
BOOST_CHECK(mpool.estimateFee(i).GetFeePerK() < origFeeEst[i-1] - deltaFee);
185193
BOOST_CHECK(mpool.estimatePriority(i) < origPriEst[i-1] - deltaPri);
186194
}
195+
196+
// Test that if the mempool is limited, estimateSmartFee won't return a value below the mempool min fee
197+
// and that estimateSmartPriority returns essentially an infinite value
198+
mpool.addUnchecked(tx.GetHash(), CTxMemPoolEntry(tx, feeV[0][5], GetTime(), priV[1][5], blocknum, mpool.HasNoInputsOf(tx)));
199+
// evict that transaction which should set a mempool min fee of minRelayTxFee + feeV[0][5]
200+
mpool.TrimToSize(1);
201+
BOOST_CHECK(mpool.GetMinFee(1).GetFeePerK() > feeV[0][5]);
202+
for (int i = 1; i < 10; i++) {
203+
BOOST_CHECK(mpool.estimateSmartFee(i).GetFeePerK() >= mpool.estimateFee(i).GetFeePerK());
204+
BOOST_CHECK(mpool.estimateSmartFee(i).GetFeePerK() >= mpool.GetMinFee(1).GetFeePerK());
205+
BOOST_CHECK(mpool.estimateSmartPriority(i) == INF_PRIORITY);
206+
}
187207
}
188208

189209
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)