LCOV - code coverage report
Current view: top level - src/test/fuzz - hex.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 27 27
Test Date: 2024-09-01 05:20:30 Functions: 100.0 % 2 2
Branches: 55.6 % 72 40

             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                 :             : #include <util/transaction_identifier.h>
      14                 :             : 
      15                 :             : #include <algorithm>
      16                 :             : #include <cassert>
      17                 :             : #include <cstdint>
      18                 :             : #include <string>
      19                 :             : #include <vector>
      20                 :             : 
      21   [ +  -  +  - ]:         457 : FUZZ_TARGET(hex)
      22                 :             : {
      23         [ +  - ]:         454 :     const std::string random_hex_string(buffer.begin(), buffer.end());
      24         [ +  - ]:         454 :     const std::vector<unsigned char> data = ParseHex(random_hex_string);
      25         [ +  - ]:         454 :     const std::vector<std::byte> bytes{ParseHex<std::byte>(random_hex_string)};
      26   [ +  -  +  -  :         454 :     assert(std::ranges::equal(AsBytes(Span{data}), bytes));
                   +  - ]
      27   [ +  -  +  - ]:         454 :     const std::string hex_data = HexStr(data);
      28   [ +  -  +  + ]:         454 :     if (IsHex(random_hex_string)) {
      29   [ +  -  +  - ]:         366 :         assert(ToLower(random_hex_string) == hex_data);
      30                 :         366 :     }
      31   [ +  -  +  + ]:         454 :     if (uint256::FromHex(random_hex_string)) {
      32         [ +  - ]:           5 :         assert(random_hex_string.length() == 64);
      33   [ +  -  +  - ]:           5 :         assert(Txid::FromHex(random_hex_string));
      34   [ +  -  +  - ]:           5 :         assert(Wtxid::FromHex(random_hex_string));
      35   [ +  -  +  - ]:           5 :         assert(uint256::FromUserHex(random_hex_string));
      36                 :           5 :     }
      37   [ +  -  +  + ]:         484 :     if (const auto result{uint256::FromUserHex(random_hex_string)}) {
      38   [ +  -  +  -  :          30 :         assert(uint256::FromHex(result->ToString()));
                   +  - ]
      39                 :          30 :     }
      40         [ +  - ]:         454 :     (void)uint256S(random_hex_string);
      41                 :             :     try {
      42         [ +  + ]:         454 :         (void)HexToPubKey(random_hex_string);
      43         [ -  + ]:         454 :     } catch (const UniValue&) {
      44         [ +  - ]:         447 :     }
      45         [ +  - ]:         454 :     CBlockHeader block_header;
      46         [ +  - ]:         454 :     (void)DecodeHexBlockHeader(block_header, random_hex_string);
      47         [ +  - ]:         454 :     CBlock block;
      48         [ +  - ]:         454 :     (void)DecodeHexBlk(block, random_hex_string);
      49                 :         901 : }
        

Generated by: LCOV version 2.0-1