diff --git a/src/avalanche/proofpool.h b/src/avalanche/proofpool.h --- a/src/avalanche/proofpool.h +++ b/src/avalanche/proofpool.h @@ -69,6 +69,8 @@ AddProofStatus addProof(const ProofRef &proof); bool removeProof(ProofRef proof); + + ProofRef getProof(const ProofId &proofid) const; }; } // namespace avalanche diff --git a/src/avalanche/proofpool.cpp b/src/avalanche/proofpool.cpp --- a/src/avalanche/proofpool.cpp +++ b/src/avalanche/proofpool.cpp @@ -53,4 +53,10 @@ return poolView.erase(proof->getId()); } +ProofRef ProofPool::getProof(const ProofId &proofid) const { + auto &poolView = pool.get(); + auto it = poolView.find(proofid); + return it == poolView.end() ? nullptr : it->proof; +} + } // namespace avalanche diff --git a/src/avalanche/test/proofpool_tests.cpp b/src/avalanche/test/proofpool_tests.cpp --- a/src/avalanche/test/proofpool_tests.cpp +++ b/src/avalanche/test/proofpool_tests.cpp @@ -67,4 +67,22 @@ BOOST_CHECK(testPool.pool.empty()); } +BOOST_AUTO_TEST_CASE(get_proof) { + ProofPool testPool; + + for (size_t i = 0; i < 10; i++) { + BOOST_CHECK(!testPool.getProof(ProofId(GetRandHash()))); + } + + for (size_t i = 0; i < 10; i++) { + auto proof = buildRandomProof(MIN_VALID_PROOF_SCORE); + BOOST_CHECK_EQUAL(testPool.addProof(proof), + ProofPool::AddProofStatus::SUCCEED); + + auto retrievedProof = testPool.getProof(proof->getId()); + BOOST_CHECK_NE(retrievedProof, nullptr); + BOOST_CHECK_EQUAL(retrievedProof->getId(), proof->getId()); + } +} + BOOST_AUTO_TEST_SUITE_END()