Skip to content

Commit fabf170

Browse files
author
MarcoFalke
committed
fuzz: Move CTxDestination fuzzing to script fuzz target
No need to split it over several targets
1 parent fa42800 commit fabf170

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

src/test/fuzz/integer.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include <pow.h>
1717
#include <protocol.h>
1818
#include <pubkey.h>
19-
#include <rpc/util.h>
20-
#include <script/signingprovider.h>
2119
#include <script/standard.h>
2220
#include <serialize.h>
2321
#include <streams.h>
@@ -158,20 +156,6 @@ FUZZ_TARGET_INIT(integer, initialize_integer)
158156

159157
const CKeyID key_id{u160};
160158
const CScriptID script_id{u160};
161-
// CTxDestination = CNoDestination ∪ PKHash ∪ ScriptHash ∪ WitnessV0ScriptHash ∪ WitnessV0KeyHash ∪ WitnessUnknown
162-
const PKHash pk_hash{u160};
163-
const ScriptHash script_hash{u160};
164-
const WitnessV0KeyHash witness_v0_key_hash{u160};
165-
const WitnessV0ScriptHash witness_v0_script_hash{u256};
166-
const std::vector<CTxDestination> destinations{pk_hash, script_hash, witness_v0_key_hash, witness_v0_script_hash};
167-
const SigningProvider store;
168-
for (const CTxDestination& destination : destinations) {
169-
(void)DescribeAddress(destination);
170-
(void)EncodeDestination(destination);
171-
(void)GetKeyForDestination(store, destination);
172-
(void)GetScriptForDestination(destination);
173-
(void)IsValidDestination(destination);
174-
}
175159

176160
{
177161
CDataStream stream(SER_NETWORK, INIT_PROTO_VERSION);

src/test/fuzz/key_io.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
#include <chainparams.h>
66
#include <key_io.h>
7-
#include <rpc/util.h>
8-
#include <script/signingprovider.h>
9-
#include <script/standard.h>
107
#include <test/fuzz/fuzz.h>
118

129
#include <cassert>
@@ -39,12 +36,4 @@ FUZZ_TARGET_INIT(key_io, initialize_key_io)
3936
if (ext_pub_key.pubkey.size() == CPubKey::COMPRESSED_SIZE) {
4037
assert(ext_pub_key == DecodeExtPubKey(EncodeExtPubKey(ext_pub_key)));
4138
}
42-
43-
const CTxDestination tx_destination = DecodeDestination(random_string);
44-
(void)DescribeAddress(tx_destination);
45-
(void)GetKeyForDestination(/* store */ {}, tx_destination);
46-
(void)GetScriptForDestination(tx_destination);
47-
(void)IsValidDestination(tx_destination);
48-
49-
(void)IsValidDestinationString(random_string);
5039
}

src/test/fuzz/script.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#include <compressor.h>
77
#include <core_io.h>
88
#include <core_memusage.h>
9+
#include <key_io.h>
910
#include <policy/policy.h>
1011
#include <pubkey.h>
12+
#include <rpc/util.h>
1113
#include <script/descriptor.h>
1214
#include <script/interpreter.h>
1315
#include <script/script.h>
@@ -188,9 +190,22 @@ FUZZ_TARGET_INIT(script, initialize_script)
188190
fuzzed_data_provider.ConsumeBool() ?
189191
DecodeDestination(fuzzed_data_provider.ConsumeRandomLengthString()) :
190192
ConsumeTxDestination(fuzzed_data_provider)};
191-
const CTxDestination tx_destination_2 = ConsumeTxDestination(fuzzed_data_provider);
193+
const CTxDestination tx_destination_2{ConsumeTxDestination(fuzzed_data_provider)};
194+
const std::string encoded_dest{EncodeDestination(tx_destination_1)};
195+
const UniValue json_dest{DescribeAddress(tx_destination_1)};
196+
Assert(tx_destination_1 == DecodeDestination(encoded_dest));
197+
(void)GetKeyForDestination(/* store */ {}, tx_destination_1);
198+
const CScript dest{GetScriptForDestination(tx_destination_1)};
199+
const bool valid{IsValidDestination(tx_destination_1)};
200+
Assert(dest.empty() != valid);
201+
202+
Assert(valid == IsValidDestinationString(encoded_dest));
192203

193-
(void)(tx_destination_1 == tx_destination_2);
194204
(void)(tx_destination_1 < tx_destination_2);
205+
if (tx_destination_1 == tx_destination_2) {
206+
Assert(encoded_dest == EncodeDestination(tx_destination_2));
207+
Assert(json_dest.write() == DescribeAddress(tx_destination_2).write());
208+
Assert(dest == GetScriptForDestination(tx_destination_2));
209+
}
195210
}
196211
}

0 commit comments

Comments
 (0)