Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show All 35 Lines | struct AvalancheTest { | ||||
return p.getInvsForNextPoll(false); | return p.getInvsForNextPoll(false); | ||||
} | } | ||||
static NodeId getSuitableNodeToQuery(Processor &p) { | static NodeId getSuitableNodeToQuery(Processor &p) { | ||||
return p.getSuitableNodeToQuery(); | return p.getSuitableNodeToQuery(); | ||||
} | } | ||||
static uint64_t getRound(const Processor &p) { return p.round; } | static uint64_t getRound(const Processor &p) { return p.round; } | ||||
static void clearProofVoteRecords(Processor &p) { | |||||
auto w = p.proofVoteRecords.getWriteView(); | |||||
w->erase(w.begin(), w.end()); | |||||
} | |||||
static void clearBlockVoteRecords(Processor &p) { | |||||
auto w = p.blockVoteRecords.getWriteView(); | |||||
w->erase(w.begin(), w.end()); | |||||
} | |||||
}; | }; | ||||
} // namespace | } // namespace | ||||
} // namespace avalanche | } // namespace avalanche | ||||
namespace { | namespace { | ||||
struct CConnmanTest : public CConnman { | struct CConnmanTest : public CConnman { | ||||
using CConnman::CConnman; | using CConnman::CConnman; | ||||
void AddNode(CNode &node) { | void AddNode(CNode &node) { | ||||
▲ Show 20 Lines • Show All 1,121 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(proof_record) { | ||||
m_processor->addProofToReconcile(proofB, true); | m_processor->addProofToReconcile(proofB, true); | ||||
BOOST_CHECK(!m_processor->isAccepted(proofA)); | BOOST_CHECK(!m_processor->isAccepted(proofA)); | ||||
BOOST_CHECK(m_processor->isAccepted(proofB)); | BOOST_CHECK(m_processor->isAccepted(proofB)); | ||||
BOOST_CHECK_EQUAL(m_processor->getConfidence(proofA), 0); | BOOST_CHECK_EQUAL(m_processor->getConfidence(proofA), 0); | ||||
BOOST_CHECK_EQUAL(m_processor->getConfidence(proofB), 0); | BOOST_CHECK_EQUAL(m_processor->getConfidence(proofB), 0); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(max_element_poll) { | |||||
auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), 0); | |||||
auto checkMaxElementPoll = [&](auto &provider) { | |||||
// Fill the invs up to the limit | |||||
for (size_t i = 0; i < AVALANCHE_MAX_ELEMENT_POLL; i++) { | |||||
auto item = provider.buildVoteItem(); | |||||
BOOST_CHECK(provider.addToReconcile(item)); | |||||
invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), i + 1); | |||||
} | |||||
// More items will not result in more invs | |||||
for (size_t i = 0; i < 10; i++) { | |||||
auto item = provider.buildVoteItem(); | |||||
BOOST_CHECK(provider.addToReconcile(item)); | |||||
invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), AVALANCHE_MAX_ELEMENT_POLL); | |||||
} | |||||
}; | |||||
// Check the inv limit when filled with proofs | |||||
ProofProvider proofProvider(this); | |||||
checkMaxElementPoll(proofProvider); | |||||
AvalancheTest::clearProofVoteRecords(*m_processor); | |||||
invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), 0); | |||||
// Check the inv limit when filled with blocks | |||||
BlockProvider blockProvider(this); | |||||
checkMaxElementPoll(blockProvider); | |||||
AvalancheTest::clearBlockVoteRecords(*m_processor); | |||||
invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), 0); | |||||
// Check the inv limit with both proofs and blocks | |||||
for (size_t i = 0; i < AVALANCHE_MAX_ELEMENT_POLL / 2; i++) { | |||||
auto proof = proofProvider.buildVoteItem(); | |||||
BOOST_CHECK(proofProvider.addToReconcile(proof)); | |||||
invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), i + 1); | |||||
} | |||||
for (size_t i = AVALANCHE_MAX_ELEMENT_POLL / 2; | |||||
i < AVALANCHE_MAX_ELEMENT_POLL; i++) { | |||||
auto blockIndex = blockProvider.buildVoteItem(); | |||||
BOOST_CHECK(blockProvider.addToReconcile(blockIndex)); | |||||
invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), i + 1); | |||||
} | |||||
// Add enough proofs and block indexes so that there is more than | |||||
// AVALANCHE_MAX_ELEMENT_POLL of each type. | |||||
for (size_t i = 0; i < AVALANCHE_MAX_ELEMENT_POLL; i++) { | |||||
auto proof = proofProvider.buildVoteItem(); | |||||
BOOST_CHECK(proofProvider.addToReconcile(proof)); | |||||
auto blockIndex = blockProvider.buildVoteItem(); | |||||
BOOST_CHECK(blockProvider.addToReconcile(blockIndex)); | |||||
invs = AvalancheTest::getInvsForNextPoll(*m_processor); | |||||
BOOST_CHECK_EQUAL(invs.size(), AVALANCHE_MAX_ELEMENT_POLL); | |||||
} | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |