Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/peermanager_tests.cpp
Show First 20 Lines • Show All 1,524 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(score_ordering) { | ||||
} | } | ||||
auto peersScores = TestPeerManager::getOrderedScores(pm); | auto peersScores = TestPeerManager::getOrderedScores(pm); | ||||
BOOST_CHECK_EQUAL_COLLECTIONS(peersScores.begin(), peersScores.end(), | BOOST_CHECK_EQUAL_COLLECTIONS(peersScores.begin(), peersScores.end(), | ||||
expectedScores.begin(), expectedScores.end()); | expectedScores.begin(), expectedScores.end()); | ||||
} | } | ||||
BOOST_FIXTURE_TEST_CASE(known_score_tracking, NoCoolDownFixture) { | BOOST_FIXTURE_TEST_CASE(known_score_tracking, NoCoolDownFixture) { | ||||
gArgs.ForceSetArg("-avaproofstakeutxoconfirmations", "2"); | |||||
avalanche::PeerManager pm; | avalanche::PeerManager pm; | ||||
const CKey key = CKey::MakeCompressedKey(); | const CKey key = CKey::MakeCompressedKey(); | ||||
const Amount amount10(10 * COIN); | const Amount amount10(10 * COIN); | ||||
const Amount amount20(20 * COIN); | const Amount amount20(20 * COIN); | ||||
const COutPoint peer1ConflictingOutput = createUtxo(key, amount10); | const COutPoint peer1ConflictingOutput = createUtxo(key, amount10, 99); | ||||
const COutPoint peer1SecondaryOutpoint = createUtxo(key, amount20); | const COutPoint peer1SecondaryOutpoint = createUtxo(key, amount20, 99); | ||||
auto peer1Proof1 = buildProof(key, | auto peer1Proof1 = buildProof(key, | ||||
{{peer1ConflictingOutput, amount10}, | {{peer1ConflictingOutput, amount10}, | ||||
{peer1SecondaryOutpoint, amount20}}, | {peer1SecondaryOutpoint, amount20}}, | ||||
key, 10); | key, 10, 99); | ||||
auto peer1Proof2 = | auto peer1Proof2 = | ||||
buildProof(key, {{peer1ConflictingOutput, amount10}}, key, 20); | buildProof(key, {{peer1ConflictingOutput, amount10}}, key, 20, 99); | ||||
auto peer1Proof3 = | |||||
buildProof(key, | // Create a proof with an immature UTXO, so the proof will be orphaned | ||||
auto peer1Proof3 = buildProof(key, | |||||
{{peer1ConflictingOutput, amount10}, | {{peer1ConflictingOutput, amount10}, | ||||
{COutPoint{TxId(GetRandHash()), 0}, amount10}}, | {createUtxo(key, amount10), amount10}}, | ||||
key, 30); | key, 30); | ||||
const uint32_t peer1Score1 = Proof::amountToScore(amount10 + amount20); | const uint32_t peer1Score1 = Proof::amountToScore(amount10 + amount20); | ||||
const uint32_t peer1Score2 = Proof::amountToScore(amount10); | const uint32_t peer1Score2 = Proof::amountToScore(amount10); | ||||
// Add first peer and check that we have its score tracked | // Add first peer and check that we have its score tracked | ||||
BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), 0); | BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), 0); | ||||
BOOST_CHECK(pm.registerProof(peer1Proof2)); | BOOST_CHECK(pm.registerProof(peer1Proof2)); | ||||
BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), peer1Score2); | BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), peer1Score2); | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(known_score_tracking, NoCoolDownFixture) { | ||||
// The conflicting proof should also be promoted to a peer | // The conflicting proof should also be promoted to a peer | ||||
BOOST_CHECK(!pm.isInConflictingPool(peer1Proof2->getId())); | BOOST_CHECK(!pm.isInConflictingPool(peer1Proof2->getId())); | ||||
BOOST_CHECK(pm.isBoundToPeer(peer1Proof2->getId())); | BOOST_CHECK(pm.isBoundToPeer(peer1Proof2->getId())); | ||||
BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), peer1Score2); | BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), peer1Score2); | ||||
// Now add another peer and check that combined scores are correct | // Now add another peer and check that combined scores are correct | ||||
uint32_t peer2Score = 1 * MIN_VALID_PROOF_SCORE; | uint32_t peer2Score = 1 * MIN_VALID_PROOF_SCORE; | ||||
auto peer2Proof1 = buildRandomProof(peer2Score); | auto peer2Proof1 = buildRandomProof(peer2Score, 99); | ||||
PeerId peerid2 = TestPeerManager::registerAndGetPeerId(pm, peer2Proof1); | PeerId peerid2 = TestPeerManager::registerAndGetPeerId(pm, peer2Proof1); | ||||
BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), peer1Score2 + peer2Score); | BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), peer1Score2 + peer2Score); | ||||
// Trying to remove non-existent peer doesn't affect score | // Trying to remove non-existent peer doesn't affect score | ||||
BOOST_CHECK(!pm.removePeer(1234)); | BOOST_CHECK(!pm.removePeer(1234)); | ||||
BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), peer1Score2 + peer2Score); | BOOST_CHECK_EQUAL(pm.getTotalPeersScore(), peer1Score2 + peer2Score); | ||||
// Removing new peer removes its score | // Removing new peer removes its score | ||||
▲ Show 20 Lines • Show All 234 Lines • Show Last 20 Lines |