Changeset View
Changeset View
Standalone View
Standalone View
src/test/blockfilter_index_tests.cpp
// Copyright (c) 2017-2018 The Bitcoin Core developers | // Copyright (c) 2017-2018 The Bitcoin Core 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 <blockfilter.h> | #include <blockfilter.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <consensus/validation.h> | #include <consensus/validation.h> | ||||
#include <index/blockfilterindex.h> | #include <index/blockfilterindex.h> | ||||
#include <miner.h> | #include <miner.h> | ||||
#include <pow.h> | #include <pow.h> | ||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <test/lib/blockfilter.h> | |||||
#include <test/setup_common.h> | #include <test/setup_common.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
BOOST_AUTO_TEST_SUITE(blockfilter_index_tests) | BOOST_AUTO_TEST_SUITE(blockfilter_index_tests) | ||||
static bool ComputeFilter(BlockFilterType filter_type, | |||||
const CBlockIndex *block_index, BlockFilter &filter) { | |||||
CBlock block; | |||||
if (!ReadBlockFromDisk(block, block_index->GetBlockPos(), | |||||
Params().GetConsensus())) { | |||||
return false; | |||||
} | |||||
CBlockUndo block_undo; | |||||
if (block_index->nHeight > 0 && | |||||
!UndoReadFromDisk(block_undo, block_index)) { | |||||
return false; | |||||
} | |||||
filter = BlockFilter(filter_type, block, block_undo); | |||||
return true; | |||||
} | |||||
static bool CheckFilterLookups(BlockFilterIndex &filter_index, | static bool CheckFilterLookups(BlockFilterIndex &filter_index, | ||||
const CBlockIndex *block_index, | const CBlockIndex *block_index, | ||||
uint256 &last_header) { | uint256 &last_header) { | ||||
BlockFilter expected_filter; | BlockFilter expected_filter; | ||||
if (!ComputeFilter(filter_index.GetFilterType(), block_index, | if (!ComputeFilter(filter_index.GetFilterType(), block_index, | ||||
expected_filter)) { | expected_filter)) { | ||||
BOOST_ERROR("ComputeFilter failed on block " << block_index->nHeight); | BOOST_ERROR("ComputeFilter failed on block " << block_index->nHeight); | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines |