5#include <boost/test/unit_test.hpp>
21 BOOST_REQUIRE_EQUAL(a->
nHeight, height);
38 BOOST_REQUIRE_EQUAL(a, b);
47 std::vector<std::unique_ptr<CBlockIndex>> block_index;
49 for (
int i = 0; i < 10; ++i) {
52 auto genesis = std::make_unique<CBlockIndex>();
54 block_index.push_back(std::move(genesis));
56 for (
int b = 0; b < 10000; ++b) {
57 auto new_index = std::make_unique<CBlockIndex>();
60 new_index->pprev = block_index.back().get();
62 new_index->pprev = block_index[ctx.
randrange(block_index.size())].get();
64 new_index->nHeight = new_index->pprev->nHeight + 1;
65 new_index->BuildSkip();
66 block_index.push_back(std::move(new_index));
69 for (
int q = 0; q < 10000; ++q) {
73 BOOST_CHECK(result == NaiveGetAncestor(block, height));
76 for (
int q = 0; q < 10000; ++q) {
80 BOOST_CHECK(result == NaiveLastCommonAncestor(block1, block2));
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the last common ancestor two blocks have.
BOOST_AUTO_TEST_CASE(chain_test)
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK(expr)