Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/peermanager_tests.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | struct TestPeerManager { | ||||
auto &peerView = pm.peers.get<by_score>(); | auto &peerView = pm.peers.get<by_score>(); | ||||
for (const Peer &peer : peerView) { | for (const Peer &peer : peerView) { | ||||
scores.push_back(peer.getScore()); | scores.push_back(peer.getScore()); | ||||
} | } | ||||
return scores; | return scores; | ||||
} | } | ||||
static void cleanupDanglingProofs(PeerManager &pm) { | static void | ||||
pm.cleanupDanglingProofs(); | cleanupDanglingProofs(PeerManager &pm, | ||||
const ProofRef &localProof = ProofRef()) { | |||||
pm.cleanupDanglingProofs(localProof); | |||||
} | } | ||||
}; | }; | ||||
static void addCoin(CChainState &chainstate, const COutPoint &outpoint, | static void addCoin(CChainState &chainstate, const COutPoint &outpoint, | ||||
const CKey &key, const Amount amount = 10 * COIN, | const CKey &key, const Amount amount = 10 * COIN, | ||||
uint32_t height = 100, bool is_coinbase = false) { | uint32_t height = 100, bool is_coinbase = false) { | ||||
CScript script = GetScriptForDestination(PKHash(key.GetPubKey())); | CScript script = GetScriptForDestination(PKHash(key.GetPubKey())); | ||||
▲ Show 20 Lines • Show All 1,855 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < numProofs; i++) { | ||||
!hadNodeAttached); | !hadNodeAttached); | ||||
BOOST_CHECK(!pm.isInConflictingPool(conflictingProofs[i]->getId())); | BOOST_CHECK(!pm.isInConflictingPool(conflictingProofs[i]->getId())); | ||||
BOOST_CHECK_EQUAL(pm.isBoundToPeer(conflictingProofs[i]->getId()), | BOOST_CHECK_EQUAL(pm.isBoundToPeer(conflictingProofs[i]->getId()), | ||||
hadNodeAttached); | hadNodeAttached); | ||||
} | } | ||||
// Elapse the timeout for the newly promoted conflicting proofs | // Elapse the timeout for the newly promoted conflicting proofs | ||||
elapseTime(avalanche::Peer::DANGLING_TIMEOUT); | elapseTime(avalanche::Peer::DANGLING_TIMEOUT); | ||||
// Use the first conflicting proof as our local proof | |||||
TestPeerManager::cleanupDanglingProofs(pm, conflictingProofs[1]); | |||||
for (size_t i = 0; i < numProofs; i++) { | |||||
// All other proofs have now been discarded | |||||
BOOST_CHECK(!pm.exists(proofs[i]->getId())); | |||||
BOOST_CHECK_EQUAL(!pm.exists(conflictingProofs[i]->getId()), i != 1); | |||||
} | |||||
// Cleanup one more time with no local proof | |||||
TestPeerManager::cleanupDanglingProofs(pm); | TestPeerManager::cleanupDanglingProofs(pm); | ||||
for (size_t i = 0; i < numProofs; i++) { | for (size_t i = 0; i < numProofs; i++) { | ||||
// All proofs have now been discarded | // All proofs have finally been discarded | ||||
BOOST_CHECK(!pm.exists(proofs[i]->getId())); | BOOST_CHECK(!pm.exists(proofs[i]->getId())); | ||||
BOOST_CHECK(!pm.exists(conflictingProofs[i]->getId())); | BOOST_CHECK(!pm.exists(conflictingProofs[i]->getId())); | ||||
} | } | ||||
gArgs.ClearForcedArg("-enableavalancheproofreplacement"); | gArgs.ClearForcedArg("-enableavalancheproofreplacement"); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |