Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show All 12 Lines | |||||
#include <net_processing.h> // For ::PeerManager | #include <net_processing.h> // For ::PeerManager | ||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
#include <util/translation.h> // For bilingual_str | #include <util/translation.h> // For bilingual_str | ||||
// D6970 moved LookupBlockIndex from chain.h to validation.h TODO: remove this | // D6970 moved LookupBlockIndex from chain.h to validation.h TODO: remove this | ||||
// when LookupBlockIndex is refactored out of validation | // when LookupBlockIndex is refactored out of validation | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <avalanche/test/util.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> | ||||
using namespace avalanche; | using namespace avalanche; | ||||
namespace avalanche { | namespace avalanche { | ||||
namespace { | namespace { | ||||
▲ Show 20 Lines • Show All 948 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(destructor) { | ||||
// Now that avalanche is destroyed, there is no more scheduled tasks. | // Now that avalanche is destroyed, there is no more scheduled tasks. | ||||
BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 0); | BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 0); | ||||
// Wait for the scheduler to stop. | // Wait for the scheduler to stop. | ||||
s.StopWhenDrained(); | s.StopWhenDrained(); | ||||
schedulerThread.join(); | schedulerThread.join(); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(add_proof_to_reconcile) { | |||||
uint32_t score = MIN_VALID_PROOF_SCORE; | |||||
auto addProofToReconcile = [&](uint32_t proofScore) { | |||||
auto proof = std::make_shared<Proof>(buildRandomProof(proofScore)); | |||||
m_processor->addProofToReconcile(proof, GetRandInt(1)); | |||||
return proof; | |||||
}; | |||||
for (size_t i = 0; i < AVALANCHE_MAX_ELEMENT_POLL - 1; i++) { | |||||
auto proof = addProofToReconcile(++score); | |||||
auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), i + 1); | |||||
BOOST_CHECK(invs.front().IsMsgProof()); | |||||
BOOST_CHECK_EQUAL(invs.front().hash, proof->getId()); | |||||
} | |||||
// From here a new proof is only polled if its score is in the top | |||||
// AVALANCHE_MAX_ELEMENT_POLL - 1 | |||||
ProofId lastProofId; | |||||
for (size_t i = 0; i < 10; i++) { | |||||
auto proof = addProofToReconcile(++score); | |||||
auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), AVALANCHE_MAX_ELEMENT_POLL - 1); | |||||
BOOST_CHECK(invs.front().IsMsgProof()); | |||||
BOOST_CHECK_EQUAL(invs.front().hash, proof->getId()); | |||||
lastProofId = proof->getId(); | |||||
} | |||||
for (size_t i = 0; i < 10; i++) { | |||||
auto proof = addProofToReconcile(--score); | |||||
auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), AVALANCHE_MAX_ELEMENT_POLL - 1); | |||||
BOOST_CHECK(invs.front().IsMsgProof()); | |||||
BOOST_CHECK_EQUAL(invs.front().hash, lastProofId); | |||||
} | |||||
// The score is not high enough to get polled | |||||
auto proof = addProofToReconcile(--score); | |||||
auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
for (auto &inv : invs) { | |||||
BOOST_CHECK_NE(inv.hash, proof->getId()); | |||||
} | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |