Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/proofpool_tests.cpp
Show First 20 Lines • Show All 460 Lines • ▼ Show 20 Lines | for (size_t i = 5; i < 10; i++) { | ||||
for (size_t i = 0; i < 10; i++) { | for (size_t i = 0; i < 10; i++) { | ||||
auto registrationTime = | auto registrationTime = | ||||
pool.getRegistrationTime(orphans[i]->getId()); | pool.getRegistrationTime(orphans[i]->getId()); | ||||
BOOST_CHECK_EQUAL(registrationTime.value_or(0), now + i); | BOOST_CHECK_EQUAL(registrationTime.value_or(0), now + i); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(remove_obsolete_proofs) { | |||||
ProofPool testPool; | |||||
// Calling when there is no proof has no effect | |||||
testPool.removeObsoleteProofs(0s); | |||||
testPool.removeObsoleteProofs(GetTime<std::chrono::seconds>()); | |||||
testPool.removeObsoleteProofs(-1s); | |||||
auto now = GetTime<std::chrono::seconds>(); | |||||
auto mocktime = now; | |||||
auto elapseTime = [&](std::chrono::seconds seconds) { | |||||
mocktime += seconds; | |||||
SetMockTime(mocktime.count()); | |||||
}; | |||||
elapseTime(0s); | |||||
std::vector<ProofRef> proofs; | |||||
for (size_t i = 0; i < 10; i++) { | |||||
auto proof = buildRandomProof(MIN_VALID_PROOF_SCORE); | |||||
BOOST_CHECK(testPool.addProofIfNoConflict(proof)); | |||||
proofs.push_back(std::move(proof)); | |||||
elapseTime(1s); | |||||
} | |||||
BOOST_CHECK_EQUAL(testPool.countProofs(), 10); | |||||
testPool.removeObsoleteProofs(0s); | |||||
BOOST_CHECK_EQUAL(testPool.countProofs(), 10); | |||||
testPool.removeObsoleteProofs(now); | |||||
BOOST_CHECK_EQUAL(testPool.countProofs(), 10); | |||||
for (size_t i = 0; i < 10; i++) { | |||||
testPool.removeObsoleteProofs(now + 5s); | |||||
BOOST_CHECK_EQUAL(testPool.countProofs(), 5); | |||||
for (size_t j = 0; j < 10; j++) { | |||||
BOOST_CHECK_EQUAL(!testPool.getRegistrationTime(proofs[j]->getId()), | |||||
j < 5); | |||||
} | |||||
} | |||||
testPool.removeObsoleteProofs(now + 10s); | |||||
BOOST_CHECK_EQUAL(testPool.countProofs(), 0); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |