|
| 1 | +// Copyright (c) 2020 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include <chain.h> |
| 6 | +#include <optional.h> |
| 7 | +#include <test/fuzz/FuzzedDataProvider.h> |
| 8 | +#include <test/fuzz/fuzz.h> |
| 9 | +#include <test/fuzz/util.h> |
| 10 | + |
| 11 | +#include <cstdint> |
| 12 | +#include <vector> |
| 13 | + |
| 14 | +void test_one_input(const std::vector<uint8_t>& buffer) |
| 15 | +{ |
| 16 | + FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); |
| 17 | + Optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider); |
| 18 | + if (!disk_block_index) { |
| 19 | + return; |
| 20 | + } |
| 21 | + |
| 22 | + const uint256 zero{}; |
| 23 | + disk_block_index->phashBlock = &zero; |
| 24 | + (void)disk_block_index->GetBlockHash(); |
| 25 | + (void)disk_block_index->GetBlockPos(); |
| 26 | + (void)disk_block_index->GetBlockTime(); |
| 27 | + (void)disk_block_index->GetBlockTimeMax(); |
| 28 | + (void)disk_block_index->GetMedianTimePast(); |
| 29 | + (void)disk_block_index->GetUndoPos(); |
| 30 | + (void)disk_block_index->HaveTxsDownloaded(); |
| 31 | + (void)disk_block_index->IsValid(); |
| 32 | + (void)disk_block_index->ToString(); |
| 33 | + |
| 34 | + const CBlockHeader block_header = disk_block_index->GetBlockHeader(); |
| 35 | + (void)CDiskBlockIndex{*disk_block_index}; |
| 36 | + (void)disk_block_index->BuildSkip(); |
| 37 | + |
| 38 | + while (fuzzed_data_provider.ConsumeBool()) { |
| 39 | + const BlockStatus block_status = fuzzed_data_provider.PickValueInArray({ |
| 40 | + BlockStatus::BLOCK_VALID_UNKNOWN, |
| 41 | + BlockStatus::BLOCK_VALID_RESERVED, |
| 42 | + BlockStatus::BLOCK_VALID_TREE, |
| 43 | + BlockStatus::BLOCK_VALID_TRANSACTIONS, |
| 44 | + BlockStatus::BLOCK_VALID_CHAIN, |
| 45 | + BlockStatus::BLOCK_VALID_SCRIPTS, |
| 46 | + BlockStatus::BLOCK_VALID_MASK, |
| 47 | + BlockStatus::BLOCK_HAVE_DATA, |
| 48 | + BlockStatus::BLOCK_HAVE_UNDO, |
| 49 | + BlockStatus::BLOCK_HAVE_MASK, |
| 50 | + BlockStatus::BLOCK_FAILED_VALID, |
| 51 | + BlockStatus::BLOCK_FAILED_CHILD, |
| 52 | + BlockStatus::BLOCK_FAILED_MASK, |
| 53 | + BlockStatus::BLOCK_OPT_WITNESS, |
| 54 | + }); |
| 55 | + if (block_status & ~BLOCK_VALID_MASK) { |
| 56 | + continue; |
| 57 | + } |
| 58 | + (void)disk_block_index->RaiseValidity(block_status); |
| 59 | + } |
| 60 | + |
| 61 | + CBlockIndex block_index{block_header}; |
| 62 | + block_index.phashBlock = &zero; |
| 63 | + (void)block_index.GetBlockHash(); |
| 64 | + (void)block_index.ToString(); |
| 65 | +} |
0 commit comments