Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/proof_tests.cpp
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <avalanche/proof.h> | #include <avalanche/proof.h> | ||||
#include <avalanche/proofbuilder.h> | #include <avalanche/proofbuilder.h> | ||||
#include <avalanche/proofcomparator.h> | |||||
#include <avalanche/test/util.h> | #include <avalanche/test/util.h> | ||||
#include <avalanche/validation.h> | #include <avalanche/validation.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
▲ Show 20 Lines • Show All 591 Lines • ▼ Show 20 Lines | auto computeProofId = [&]() { | ||||
return p.getId(); | return p.getId(); | ||||
}; | }; | ||||
const ProofId proofid = computeProofId(); | const ProofId proofid = computeProofId(); | ||||
Shuffle(outpoints.begin(), outpoints.end(), FastRandomContext()); | Shuffle(outpoints.begin(), outpoints.end(), FastRandomContext()); | ||||
BOOST_CHECK_EQUAL(proofid, computeProofId()); | BOOST_CHECK_EQUAL(proofid, computeProofId()); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(proof_shared_pointer_comparator) { | |||||
uint32_t score = MIN_VALID_PROOF_SCORE; | |||||
auto proofMinScore = | |||||
std::make_shared<Proof>(buildRandomProof(MIN_VALID_PROOF_SCORE)); | |||||
auto proofMaxScore = std::make_shared<Proof>( | |||||
buildRandomProof(std::numeric_limits<uint32_t>::max())); | |||||
const ProofSharedPointerComparator comparator; | |||||
auto prevProof = proofMinScore; | |||||
for (size_t i = 0; i < 100; i++) { | |||||
score += 1000 + GetRandInt(10000); | |||||
auto higherScoreProof = | |||||
std::make_shared<Proof>(buildRandomProof(score)); | |||||
BOOST_CHECK(comparator(higherScoreProof, proofMinScore)); | |||||
BOOST_CHECK(comparator(higherScoreProof, prevProof)); | |||||
BOOST_CHECK(!comparator(higherScoreProof, proofMaxScore)); | |||||
prevProof = higherScoreProof; | |||||
} | |||||
// Decrement slower than we incremented, so we don't have to check whether | |||||
// the score reached the minimal value. | |||||
for (size_t i = 0; i < 100; i++) { | |||||
score -= 1 + GetRandInt(100); | |||||
auto lowerScoreProof = std::make_shared<Proof>(buildRandomProof(score)); | |||||
BOOST_CHECK(comparator(lowerScoreProof, proofMinScore)); | |||||
BOOST_CHECK(!comparator(lowerScoreProof, prevProof)); | |||||
BOOST_CHECK(!comparator(lowerScoreProof, proofMaxScore)); | |||||
prevProof = lowerScoreProof; | |||||
} | |||||
for (size_t i = 0; i < 100; i++) { | |||||
auto anotherProofMinScore = | |||||
std::make_shared<Proof>(buildRandomProof(MIN_VALID_PROOF_SCORE)); | |||||
BOOST_CHECK_EQUAL(comparator(anotherProofMinScore, proofMinScore), | |||||
anotherProofMinScore->getId() < | |||||
proofMinScore->getId()); | |||||
} | |||||
} | |||||
deadalnix: Put it in its own test, no? That is this much less to recompile at once and it can run in… | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |
Put it in its own test, no? That is this much less to recompile at once and it can run in parallel. If the header is different, then the test might as well be.