mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
tests: Fuzz additional functions in the script fuzzing harness
This commit is contained in:
parent
5fc10f3cb5
commit
52fed696d2
@ -15,12 +15,15 @@
|
||||
#include <script/standard.h>
|
||||
#include <streams.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <univalue.h>
|
||||
#include <util/memory.h>
|
||||
|
||||
void initialize()
|
||||
{
|
||||
// Fuzzers using pubkey must hold an ECCVerifyHandle.
|
||||
static const auto verify_handle = MakeUnique<ECCVerifyHandle>();
|
||||
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
}
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
@ -28,7 +31,20 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
const CScript script(buffer.begin(), buffer.end());
|
||||
|
||||
std::vector<unsigned char> compressed;
|
||||
(void)CompressScript(script, compressed);
|
||||
if (CompressScript(script, compressed)) {
|
||||
const unsigned int size = compressed[0];
|
||||
assert(size >= 0 && size <= 5);
|
||||
CScript decompressed_script;
|
||||
const bool ok = DecompressScript(decompressed_script, size, compressed);
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
for (unsigned int size = 0; size < 6; ++size) {
|
||||
std::vector<unsigned char> vch(GetSpecialScriptSize(size), 0x00);
|
||||
vch.insert(vch.end(), buffer.begin(), buffer.end());
|
||||
CScript decompressed_script;
|
||||
(void)DecompressScript(decompressed_script, size, vch);
|
||||
}
|
||||
|
||||
CTxDestination address;
|
||||
(void)ExtractDestination(script, address);
|
||||
@ -61,4 +77,17 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
(void)script.IsPushOnly();
|
||||
(void)script.IsUnspendable();
|
||||
(void)script.GetSigOpCount(/* fAccurate= */ false);
|
||||
|
||||
(void)FormatScript(script);
|
||||
(void)ScriptToAsmStr(script, false);
|
||||
(void)ScriptToAsmStr(script, true);
|
||||
|
||||
UniValue o1(UniValue::VOBJ);
|
||||
ScriptPubKeyToUniv(script, o1, true);
|
||||
UniValue o2(UniValue::VOBJ);
|
||||
ScriptPubKeyToUniv(script, o2, false);
|
||||
UniValue o3(UniValue::VOBJ);
|
||||
ScriptToUniv(script, o3, true);
|
||||
UniValue o4(UniValue::VOBJ);
|
||||
ScriptToUniv(script, o4, false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user