10#include <test/util/setup_common.h>
12#include <boost/test/unit_test.hpp>
18 struct TestCompactProofs {
19 static std::vector<uint64_t> getShortProofIds(
const CompactProofs &cp) {
23 static std::vector<PrefilledProof>
28 static void addPrefilledProof(
CompactProofs &cp, uint32_t index,
40BOOST_FIXTURE_TEST_SUITE(compactproofs_tests, TestingSetup)
64 TestCompactProofs::addPrefilledProof(
66 TestCompactProofs::addPrefilledProof(
67 cp, std::numeric_limits<uint32_t>::max(),
73 auto prefilledProofs = TestCompactProofs::getPrefilledProofs(cp);
78 std::numeric_limits<uint32_t>::max());
81 auto checkCompactProof = [&](
size_t numofProof,
82 size_t numofPrefilledProof) {
84 for (
size_t i = 0; i < numofProof; i++) {
92 uint32_t prefilledProofIndex = 0;
93 for (
size_t i = 0; i < numofPrefilledProof; i++) {
94 TestCompactProofs::addPrefilledProof(
95 cpw, prefilledProofIndex++,
98 auto prefilledProofs = TestCompactProofs::getPrefilledProofs(cpw);
113 return lhs.
index == rhs.index &&
118 auto prefilledProofsCpr = TestCompactProofs::getPrefilledProofs(cpr);
120 prefilledProofsCpr.end(),
121 prefilledProofs.begin(), comparePrefilledProof));
123 auto shortIds = TestCompactProofs::getShortProofIds(cpr);
126 const ProofId &proofid = pLeaf->getId();
136 checkCompactProof(0, 0);
139 checkCompactProof(1000, 0);
142 checkCompactProof(0, 1000);
145 checkCompactProof(1000, 1000);
153 TestCompactProofs::addPrefilledProof(
155 TestCompactProofs::addPrefilledProof(
159 BOOST_CHECK_EXCEPTION(ss << cp, std::ios_base::failure,
160 HasReason(
"differential value overflow"));
166 TestCompactProofs::addPrefilledProof(
168 TestCompactProofs::addPrefilledProof(
172 BOOST_CHECK_EXCEPTION(ss << cp, std::ios_base::failure,
173 HasReason(
"differential value overflow"));
179 TestCompactProofs::addPrefilledProof(
180 cp, std::numeric_limits<uint32_t>::max(),
182 TestCompactProofs::addPrefilledProof(
186 BOOST_CHECK_EXCEPTION(ss << cp, std::ios_base::failure,
187 HasReason(
"differential value overflow"));
193 ss << uint64_t(0) << uint64_t(0);
198 BOOST_CHECK_EXCEPTION(ss >> cp, std::ios_base::failure,
199 HasReason(
"ReadCompactSize(): size too large"));
205 ss << uint64_t(0) << uint64_t(0);
212 BOOST_CHECK_EXCEPTION(ss >> cp, std::ios_base::failure,
213 HasReason(
"ReadCompactSize(): size too large"));
219 ss << uint64_t(0) << uint64_t(0);
230 BOOST_CHECK_EXCEPTION(ss >> cp, std::ios_base::failure,
231 HasReason(
"ReadCompactSize(): size too large"));
235 const uint64_t overflow =
236 uint64_t(std::numeric_limits<uint32_t>::max()) + 1;
239 BOOST_CHECK_GE(overflow,
MAX_SIZE + 1);
240 const uint64_t overflowIter = overflow / (
MAX_SIZE + 1);
243 BOOST_CHECK_LE(overflowIter, std::numeric_limits<uint32_t>::max());
244 BOOST_CHECK_LE(overflowIter,
MAX_SIZE);
245 uint32_t remainder = uint32_t(overflow - ((
MAX_SIZE + 1) * overflowIter));
250 ss << uint64_t(0) << uint64_t(0);
255 for (uint32_t i = 0; i < overflowIter; i++) {
266 BOOST_CHECK_EXCEPTION(ss >> cp, std::ios_base::failure,
267 HasReason(
"differential value overflow"));
273 ss << uint64_t(0) << uint64_t(0);
280 for (uint32_t i = 0; i < overflowIter; i++) {
293 BOOST_CHECK_EXCEPTION(ss >> cp, std::ios_base::failure,
294 HasReason(
"indexes overflowed 32 bits"));
300 ss << uint64_t(0) << uint64_t(0);
316 BOOST_CHECK_EXCEPTION(ss >> cp, std::ios_base::failure,
317 HasReason(
"non contiguous indexes"));
321BOOST_AUTO_TEST_SUITE_END()
#define Assert(val)
Identity function.
Double ended buffer combining vector and stream-like interfaces.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
std::vector< PrefilledProof > prefilledProofs
uint64_t getShortID(const ProofId &proofid) const
std::pair< uint64_t, uint64_t > getKeys() const
std::vector< uint64_t > shortproofids
const SchnorrSig & getSignature() const
const ProofId & getId() const
BOOST_AUTO_TEST_CASE(compactproofs_roundtrip)
ProofRef buildRandomProof(Chainstate &active_chainstate, uint32_t score, int height, const CKey &masterKey)
constexpr uint32_t MIN_VALID_PROOF_SCORE
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK_NO_THROW(stmt)
#define BOOST_CHECK(expr)
static constexpr uint64_t MAX_SIZE
The maximum size of a serialized object in bytes or number of elements (for eg vectors) when the size...
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
bool forEachLeaf(Callable &&func) const
bool insert(const RCUPtr< T > &value)
Insert a value into the tree.
avalanche::ProofRef proof
static const int PROTOCOL_VERSION
network protocol versioning