Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/peermanager_tests.cpp
Show First 20 Lines • Show All 782 Lines • ▼ Show 20 Lines | const std::string badProofHex( | ||||
"3e95b02cacfd357b64e4fb6c92e92dd00"); | "3e95b02cacfd357b64e4fb6c92e92dd00"); | ||||
bilingual_str error; | bilingual_str error; | ||||
Proof badProof; | Proof badProof; | ||||
BOOST_CHECK(Proof::FromHex(badProof, badProofHex, error)); | BOOST_CHECK(Proof::FromHex(badProof, badProofHex, error)); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
!pm.registerProof(std::make_shared<Proof>(std::move(badProof)))); | !pm.registerProof(std::make_shared<Proof>(std::move(badProof)))); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(nodesForPeer) { | |||||
avalanche::PeerManager pm; | |||||
const auto firstProof = getRandomProofPtr(MIN_VALID_PROOF_SCORE); | |||||
const auto firstPeerId = pm.getPeerId(firstProof); | |||||
// firstPeerId has no nodes | |||||
BOOST_CHECK(pm.nodesForPeer(firstPeerId).empty()); | |||||
const auto theFuture(std::chrono::steady_clock::now() + | |||||
std::chrono::hours(24)); | |||||
// Add nodes to this peer and update their request time far in the future | |||||
int i = 0; | |||||
for (; i < 10; i++) { | |||||
BOOST_CHECK(pm.addNode(i, firstProof->getId())); | |||||
BOOST_CHECK(pm.updateNextRequestTime(i, theFuture)); | |||||
} | |||||
// firstPeerId now should have 10 nodes associated with it | |||||
BOOST_CHECK(pm.nodesForPeer(firstPeerId).size() == 10); | |||||
// add another peer | |||||
const auto secondProof = getRandomProofPtr(MIN_VALID_PROOF_SCORE); | |||||
const auto secondPeerId = pm.getPeerId(secondProof); | |||||
// now add a new set of nodes to secondPeerId as well | |||||
for (; i < 30; i++) { | |||||
BOOST_CHECK(pm.addNode(i, secondProof->getId())); | |||||
BOOST_CHECK(pm.updateNextRequestTime(i, theFuture)); | |||||
} | |||||
// secondPeerId should have 20 nodes | |||||
BOOST_CHECK(pm.nodesForPeer(secondPeerId).size() == 20); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |