aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2020-01-15 23:37:27 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2020-03-07 14:35:49 +0000
commit52fed696d251dc38211eb2fa7f144b6a989dd479 (patch)
treeaad1021fe8df5a9d09b82da6bf3fe0add98a987f /src/test
parent5fc10f3cb5991684f10c589fa5ccf2d694ffa32a (diff)
tests: Fuzz additional functions in the script fuzzing harness
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/script.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/test/fuzz/script.cpp b/src/test/fuzz/script.cpp
index 0469e87de6..ed4fe21957 100644
--- a/src/test/fuzz/script.cpp
+++ b/src/test/fuzz/script.cpp
@@ -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);
}