LCOV - code coverage report
Current view: top level - src/test/fuzz - hex.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 24 24 100.0 %
Date: 2023-10-05 15:40:34 Functions: 7 7 100.0 %
Branches: 29 54 53.7 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2019-2021 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 <core_io.h>
       6                 :            : #include <primitives/block.h>
       7                 :            : #include <pubkey.h>
       8                 :            : #include <rpc/util.h>
       9                 :            : #include <test/fuzz/fuzz.h>
      10                 :            : #include <uint256.h>
      11                 :            : #include <univalue.h>
      12                 :            : #include <util/strencodings.h>
      13                 :            : 
      14                 :            : #include <cassert>
      15                 :            : #include <cstdint>
      16                 :            : #include <string>
      17         [ +  - ]:        173 : #include <vector>
      18         [ +  - ]:        173 : 
      19         [ -  + ]:        560 : FUZZ_TARGET(hex)
      20                 :            : {
      21         [ +  - ]:        214 :     const std::string random_hex_string(buffer.begin(), buffer.end());
      22         [ +  - ]:        214 :     const std::vector<unsigned char> data = ParseHex(random_hex_string);
      23         [ +  - ]:        214 :     const std::vector<std::byte> bytes{ParseHex<std::byte>(random_hex_string)};
      24   [ +  -  +  -  :        214 :     assert(AsBytes(Span{data}) == Span{bytes});
                   +  - ]
      25   [ +  -  +  -  :        387 :     const std::string hex_data = HexStr(data);
                   +  - ]
      26   [ +  -  +  + ]:        214 :     if (IsHex(random_hex_string)) {
      27   [ +  -  +  - ]:        338 :         assert(ToLower(random_hex_string) == hex_data);
      28                 :        165 :     }
      29         [ +  - ]:        214 :     (void)IsHexNumber(random_hex_string);
      30         [ +  - ]:        214 :     uint256 result;
      31         [ +  - ]:        214 :     (void)ParseHashStr(random_hex_string, result);
      32         [ +  - ]:        214 :     (void)uint256S(random_hex_string);
      33                 :            :     try {
      34         [ +  + ]:        214 :         (void)HexToPubKey(random_hex_string);
      35         [ +  - ]:        214 :     } catch (const UniValue&) {
      36         [ +  - ]:        213 :     }
      37         [ +  - ]:        214 :     CBlockHeader block_header;
      38         [ +  - ]:        214 :     (void)DecodeHexBlockHeader(block_header, random_hex_string);
      39         [ +  - ]:        214 :     CBlock block;
      40         [ +  - ]:        214 :     (void)DecodeHexBlk(block, random_hex_string);
      41                 :        427 : }

Generated by: LCOV version 1.14