Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/peermanager_tests.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | for (int c = 0; c < 1000; c++) { | ||||
auto i = selectPeerImpl(slots, s, max); | auto i = selectPeerImpl(slots, s, max); | ||||
// /!\ Because of the way we construct the vector, the peer id is | // /!\ Because of the way we construct the vector, the peer id is | ||||
// always the index. This might not be the case in practice. | // always the index. This might not be the case in practice. | ||||
BOOST_CHECK(i == NO_PEER || slots[i].contains(s)); | BOOST_CHECK(i == NO_PEER || slots[i].contains(s)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static std::shared_ptr<Proof> getRandomProofPtr(uint32_t score) { | static ProofRef getRandomProofPtr(uint32_t score) { | ||||
return std::make_shared<Proof>(buildRandomProof(score)); | return std::make_shared<Proof>(buildRandomProof(score)); | ||||
deadalnix: If you make the type more opaque, then wrap this as well. This code makes no sense in the… | |||||
FabienAuthorUnsubmitted Done Inline ActionsI should just remove this one and update buildRandomProof to return a shared pointer, since most of the API uses that. Will do in another diff. Fabien: I should just remove this one and update buildRandomProof to return a shared pointer, since… | |||||
} | } | ||||
static void addNodeWithScore(avalanche::PeerManager &pm, NodeId node, | static void addNodeWithScore(avalanche::PeerManager &pm, NodeId node, | ||||
uint32_t score) { | uint32_t score) { | ||||
auto proof = getRandomProofPtr(score); | auto proof = getRandomProofPtr(score); | ||||
BOOST_CHECK_NE(pm.getPeerId(proof), NO_PEER); | BOOST_CHECK_NE(pm.getPeerId(proof), NO_PEER); | ||||
BOOST_CHECK(pm.addNode(node, proof->getId())); | BOOST_CHECK(pm.addNode(node, proof->getId())); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 456 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(orphan_proofs) { | ||||
// Good | // Good | ||||
BOOST_CHECK(!pm.isOrphan(proof1->getId())); | BOOST_CHECK(!pm.isOrphan(proof1->getId())); | ||||
// MISSING_UTXO | // MISSING_UTXO | ||||
BOOST_CHECK(pm.isOrphan(proof2->getId())); | BOOST_CHECK(pm.isOrphan(proof2->getId())); | ||||
// HEIGHT_MISMATCH | // HEIGHT_MISMATCH | ||||
BOOST_CHECK(pm.isOrphan(proof3->getId())); | BOOST_CHECK(pm.isOrphan(proof3->getId())); | ||||
const auto isGoodPeer = [&pm](const std::shared_ptr<Proof> &p) { | const auto isGoodPeer = [&pm](const ProofRef &p) { | ||||
bool ret = false; | bool ret = false; | ||||
pm.forEachPeer([&](const Peer &peer) { | pm.forEachPeer([&](const Peer &peer) { | ||||
if (p->getId() == peer.proof->getId()) { | if (p->getId() == peer.proof->getId()) { | ||||
ret = true; | ret = true; | ||||
} | } | ||||
}); | }); | ||||
return ret; | return ret; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(dangling_node) { | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(proof_accessors) { | BOOST_AUTO_TEST_CASE(proof_accessors) { | ||||
avalanche::PeerManager pm; | avalanche::PeerManager pm; | ||||
constexpr int numProofs = 10; | constexpr int numProofs = 10; | ||||
std::vector<std::shared_ptr<Proof>> proofs; | std::vector<ProofRef> proofs; | ||||
proofs.reserve(numProofs); | proofs.reserve(numProofs); | ||||
for (int i = 0; i < numProofs; i++) { | for (int i = 0; i < numProofs; i++) { | ||||
proofs.push_back(getRandomProofPtr(MIN_VALID_PROOF_SCORE)); | proofs.push_back(getRandomProofPtr(MIN_VALID_PROOF_SCORE)); | ||||
} | } | ||||
for (int i = 0; i < numProofs; i++) { | for (int i = 0; i < numProofs; i++) { | ||||
BOOST_CHECK(pm.registerProof(proofs[i])); | BOOST_CHECK(pm.registerProof(proofs[i])); | ||||
// Fail to add an existing proof | // Fail to add an existing proof | ||||
Show All 23 Lines |
If you make the type more opaque, then wrap this as well. This code makes no sense in the current state of affair, because it pretends to abstract away the use of the shared_ptr but doesn't in this case.