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