mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
tests: Add fuzzing harness for various hex related functions
This commit is contained in:
parent
526dd78bed
commit
c18405732e
2 changed files with 29 additions and 0 deletions
|
@ -28,6 +28,7 @@ FUZZ_TARGETS = \
|
||||||
test/fuzz/eval_script \
|
test/fuzz/eval_script \
|
||||||
test/fuzz/fee_rate_deserialize \
|
test/fuzz/fee_rate_deserialize \
|
||||||
test/fuzz/flat_file_pos_deserialize \
|
test/fuzz/flat_file_pos_deserialize \
|
||||||
|
test/fuzz/hex \
|
||||||
test/fuzz/integer \
|
test/fuzz/integer \
|
||||||
test/fuzz/inv_deserialize \
|
test/fuzz/inv_deserialize \
|
||||||
test/fuzz/key_origin_info_deserialize \
|
test/fuzz/key_origin_info_deserialize \
|
||||||
|
@ -363,6 +364,12 @@ test_fuzz_address_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||||
test_fuzz_address_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
test_fuzz_address_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||||
test_fuzz_address_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
test_fuzz_address_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||||
|
|
||||||
|
test_fuzz_hex_SOURCES = $(FUZZ_SUITE) test/fuzz/hex.cpp
|
||||||
|
test_fuzz_hex_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||||
|
test_fuzz_hex_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||||
|
test_fuzz_hex_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||||
|
test_fuzz_hex_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||||
|
|
||||||
test_fuzz_inv_deserialize_SOURCES = $(FUZZ_SUITE) test/fuzz/deserialize.cpp
|
test_fuzz_inv_deserialize_SOURCES = $(FUZZ_SUITE) test/fuzz/deserialize.cpp
|
||||||
test_fuzz_inv_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DINV_DESERIALIZE=1
|
test_fuzz_inv_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DINV_DESERIALIZE=1
|
||||||
test_fuzz_inv_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
test_fuzz_inv_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||||
|
|
22
src/test/fuzz/hex.cpp
Normal file
22
src/test/fuzz/hex.cpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright (c) 2019 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <test/fuzz/fuzz.h>
|
||||||
|
|
||||||
|
#include <util/strencodings.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
|
{
|
||||||
|
const std::string random_hex_string(buffer.begin(), buffer.end());
|
||||||
|
const std::vector<unsigned char> data = ParseHex(random_hex_string);
|
||||||
|
const std::string hex_data = HexStr(data);
|
||||||
|
if (IsHex(random_hex_string)) {
|
||||||
|
assert(ToLower(random_hex_string) == hex_data);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue