aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2020-02-19 16:42:42 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2020-03-09 19:24:50 +0000
commiteb7c50ca1f4eafed4bb9a20d3012776545a6a433 (patch)
tree7f348c32720b22ca51c5ed0fa0ee809150513adb
parent5518eeec2727d40e1105901a8751bf584ab69402 (diff)
tests: Add common Consume* fuzzing functions
-rw-r--r--src/test/fuzz/util.h18
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