Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show All 32 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.conflicting_proofs.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; | |||||
} | |||||
}; | |||||
class TestConflictingProofHandler | |||||
: public PeerManager::ConflictingProofHandler { | |||||
public: | |||||
std::shared_ptr<Proof> lastProof; | |||||
bool lastVote; | |||||
void | |||||
onConflictingProof(const std::shared_ptr<Proof> &proof, | |||||
const std::unordered_set<PeerId> &conflictingPeerIds, | |||||
bool accepted) override { | |||||
lastProof = proof; | |||||
lastVote = accepted; | |||||
} | |||||
}; | }; | ||||
} // 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 928 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(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() |