tests: Fill fuzzing coverage gaps for functions in script/script.h, script/script_error.h and script/standard.h

This commit is contained in:
practicalswift 2020-05-16 18:15:13 +00:00
parent c571ecb071
commit 8de72711c6
2 changed files with 44 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include <script/descriptor.h>
#include <script/interpreter.h>
#include <script/script.h>
#include <script/script_error.h>
#include <script/sign.h>
#include <script/signingprovider.h>
#include <script/standard.h>
@ -21,6 +22,8 @@
#include <univalue.h>
#include <util/memory.h>
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <optional>
#include <string>
@ -124,4 +127,40 @@ void test_one_input(const std::vector<uint8_t>& buffer)
wit.SetNull();
}
}
(void)GetOpName(ConsumeOpcodeType(fuzzed_data_provider));
(void)ScriptErrorString(static_cast<ScriptError>(fuzzed_data_provider.ConsumeIntegralInRange<int>(0, SCRIPT_ERR_ERROR_COUNT)));
{
const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
CScript append_script{bytes.begin(), bytes.end()};
append_script << fuzzed_data_provider.ConsumeIntegral<int64_t>();
append_script << ConsumeOpcodeType(fuzzed_data_provider);
append_script << CScriptNum{fuzzed_data_provider.ConsumeIntegral<int64_t>()};
append_script << ConsumeRandomLengthByteVector(fuzzed_data_provider);
}
{
WitnessUnknown witness_unknown_1{};
witness_unknown_1.version = fuzzed_data_provider.ConsumeIntegral<int>();
const std::vector<uint8_t> witness_unknown_program_1 = fuzzed_data_provider.ConsumeBytes<uint8_t>(40);
witness_unknown_1.length = witness_unknown_program_1.size();
std::copy(witness_unknown_program_1.begin(), witness_unknown_program_1.end(), witness_unknown_1.program);
WitnessUnknown witness_unknown_2{};
witness_unknown_2.version = fuzzed_data_provider.ConsumeIntegral<int>();
const std::vector<uint8_t> witness_unknown_program_2 = fuzzed_data_provider.ConsumeBytes<uint8_t>(40);
witness_unknown_2.length = witness_unknown_program_2.size();
std::copy(witness_unknown_program_2.begin(), witness_unknown_program_2.end(), witness_unknown_2.program);
(void)(witness_unknown_1 == witness_unknown_2);
(void)(witness_unknown_1 < witness_unknown_2);
}
{
const CTxDestination tx_destination_1 = ConsumeTxDestination(fuzzed_data_provider);
const CTxDestination tx_destination_2 = ConsumeTxDestination(fuzzed_data_provider);
(void)(tx_destination_1 == tx_destination_2);
(void)(tx_destination_1 < tx_destination_2);
}
}

View File

@ -12,6 +12,7 @@
#include <rpc/server.h>
#include <rpc/util.h>
#include <script/descriptor.h>
#include <script/script.h>
#include <serialize.h>
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
@ -89,6 +90,10 @@ void test_one_input(const std::vector<uint8_t>& buffer)
(void)urlDecode(random_string_1);
(void)ValidAsCString(random_string_1);
(void)_(random_string_1.c_str());
try {
throw scriptnum_error{random_string_1};
} catch (const std::runtime_error&) {
}
{
CDataStream data_stream{SER_NETWORK, INIT_PROTO_VERSION};