diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2020-02-19 16:42:42 +0000 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2020-03-09 19:24:50 +0000 |
commit | eb7c50ca1f4eafed4bb9a20d3012776545a6a433 (patch) | |
tree | 7f348c32720b22ca51c5ed0fa0ee809150513adb /src/test/fuzz | |
parent | 5518eeec2727d40e1105901a8751bf584ab69402 (diff) | |
download | bitcoin-eb7c50ca1f4eafed4bb9a20d3012776545a6a433.tar.xz |
tests: Add common Consume* fuzzing functions
Diffstat (limited to 'src/test/fuzz')
-rw-r--r-- | src/test/fuzz/util.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index 62907c7e0b..a2b7d804ea 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -7,9 +7,11 @@ #include <attributes.h> #include <optional.h> +#include <script/script.h> #include <serialize.h> #include <streams.h> #include <test/fuzz/FuzzedDataProvider.h> +#include <test/fuzz/fuzz.h> #include <version.h> #include <cstdint> @@ -36,4 +38,20 @@ NODISCARD inline Optional<T> ConsumeDeserializable(FuzzedDataProvider& fuzzed_da return obj; } +NODISCARD inline opcodetype ConsumeOpcodeType(FuzzedDataProvider& fuzzed_data_provider) noexcept +{ + return static_cast<opcodetype>(fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, MAX_OPCODE)); +} + +NODISCARD inline CScript ConsumeScript(FuzzedDataProvider& fuzzed_data_provider) noexcept +{ + const std::vector<uint8_t> b = ConsumeRandomLengthByteVector(fuzzed_data_provider); + return {b.begin(), b.end()}; +} + +NODISCARD inline CScriptNum ConsumeScriptNum(FuzzedDataProvider& fuzzed_data_provider) noexcept +{ + return CScriptNum{fuzzed_data_provider.ConsumeIntegral<int64_t>()}; +} + #endif // BITCOIN_TEST_FUZZ_UTIL_H |