Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
proofcomparator_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 The Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
7#include <random.h>
8
10#include <test/util/setup_common.h>
11
12#include <boost/test/unit_test.hpp>
13
14#include <cstdint>
15#include <limits>
16#include <memory>
17
18using namespace avalanche;
19
21
23 Chainstate &active_chainstate = Assert(m_node.chainman)->ActiveChainstate();
25
26 auto proofMinScore =
29 std::numeric_limits<uint32_t>::max());
30
32
34 for (size_t i = 0; i < 100; i++) {
35 score += 1000 + GetRand<int>(10000);
41 }
42
43 // Decrement slower than we incremented, so we don't have to check whether
44 // the score reached the minimal value.
45 for (size_t i = 0; i < 100; i++) {
46 score -= 1 + GetRand<int>(100);
52 }
53
54 for (size_t i = 0; i < 100; i++) {
58 anotherProofMinScore->getId() <
59 proofMinScore->getId());
60 }
61}
62
64 Chainstate &active_chainstate = Assert(m_node.chainman)->ActiveChainstate();
65 std::vector<ProofRef> proofs;
66 for (size_t i = 0; i < 100; i++) {
68 proofs.push_back(std::move(proof));
69 }
70
71 std::set<ProofRef, ProofRefComparatorByAddress> sortedProofs(proofs.begin(),
72 proofs.end());
73
75 for (const auto &p : sortedProofs) {
76 BOOST_CHECK_GE(reinterpret_cast<uintptr_t>(p.get()), prevAddr);
77 prevAddr = reinterpret_cast<uintptr_t>(p.get());
78 }
79}
80
#define Assert(val)
Identity function.
Definition check.h:84
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition validation.h:699
ProofRef buildRandomProof(Chainstate &active_chainstate, uint32_t score, int height, const CKey &masterKey)
Definition util.cpp:20
constexpr uint32_t MIN_VALID_PROOF_SCORE
Definition util.h:17
NodeContext & m_node
#define BOOST_CHECK_EQUAL(v1, v2)
Definition object.cpp:18
#define BOOST_CHECK(expr)
Definition object.cpp:17
BOOST_AUTO_TEST_CASE(proof_shared_pointer_comparator)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
Compare proofs by score, then by id in case of equality.