Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show All 33 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 setLocalPeerId(Processor &p, PeerId peerid) { | |||||
p.setPeerData(std::make_shared<Proof>(), Delegation(), peerid); | |||||
} | |||||
static std::optional<VoteRecord> | |||||
getVoteForProof(const Processor &p, | |||||
const std::shared_ptr<Proof> &proof) { | |||||
auto conflictingProofsReadView = p.proofsVoteRecords.getReadView(); | |||||
for (auto it = conflictingProofsReadView.begin(); | |||||
it != conflictingProofsReadView.end(); it++) { | |||||
if (it->first->getId() == proof->getId()) { | |||||
return std::make_optional(VoteRecord(it->second)); | |||||
} | |||||
} | |||||
return std::nullopt; | |||||
} | |||||
}; | }; | ||||
} // 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 933 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(destructor) { | ||||
schedulerThread.join(); | schedulerThread.join(); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(add_proof_to_reconcile) { | BOOST_AUTO_TEST_CASE(add_proof_to_reconcile) { | ||||
uint32_t score = MIN_VALID_PROOF_SCORE; | uint32_t score = MIN_VALID_PROOF_SCORE; | ||||
auto addProofToReconcile = [&](uint32_t proofScore) { | auto addProofToReconcile = [&](uint32_t proofScore) { | ||||
auto proof = std::make_shared<Proof>(buildRandomProof(proofScore)); | auto proof = std::make_shared<Proof>(buildRandomProof(proofScore)); | ||||
m_processor->addProofToReconcile(proof, GetRandInt(1)); | m_processor->addProofToReconcile(proof, {}, GetRandInt(1)); | ||||
return proof; | return proof; | ||||
}; | }; | ||||
for (size_t i = 0; i < AVALANCHE_MAX_ELEMENT_POLL - 1; i++) { | for (size_t i = 0; i < AVALANCHE_MAX_ELEMENT_POLL - 1; i++) { | ||||
auto proof = addProofToReconcile(++score); | auto proof = addProofToReconcile(++score); | ||||
auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); | auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); | ||||
BOOST_CHECK_EQUAL(invs.size(), i + 1); | BOOST_CHECK_EQUAL(invs.size(), i + 1); | ||||
Show All 27 Lines | BOOST_AUTO_TEST_CASE(add_proof_to_reconcile) { | ||||
// The score is not high enough to get polled | // The score is not high enough to get polled | ||||
auto proof = addProofToReconcile(--score); | auto proof = addProofToReconcile(--score); | ||||
auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); | auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); | ||||
for (auto &inv : invs) { | for (auto &inv : invs) { | ||||
BOOST_CHECK_NE(inv.hash, proof->getId()); | BOOST_CHECK_NE(inv.hash, proof->getId()); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(localProofConflict) { | |||||
const PeerId localPeerId = 42; | |||||
AvalancheTest::setLocalPeerId(*m_processor, localPeerId); | |||||
auto checkVote = [&](const std::unordered_set<PeerId> &conflictingPeerIds, | |||||
bool expectedVote) { | |||||
auto proof = GetProof(); | |||||
m_processor->addProofToReconcile(proof, conflictingPeerIds, true); | |||||
auto vote = AvalancheTest::getVoteForProof(*m_processor, proof); | |||||
BOOST_CHECK(vote); | |||||
BOOST_CHECK_EQUAL(vote->isAccepted(), expectedVote); | |||||
}; | |||||
checkVote({41}, true); | |||||
checkVote({42}, false); | |||||
checkVote({43}, true); | |||||
checkVote({41, 43}, true); | |||||
checkVote({41, 42, 43}, false); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |