mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 20:32:35 -03:00
fuzz: Move CTxDestination fuzzing to script fuzz target
No need to split it over several targets
This commit is contained in:
parent
fa42800a51
commit
fabf17056c
3 changed files with 17 additions and 29 deletions
|
@ -16,8 +16,6 @@
|
|||
#include <pow.h>
|
||||
#include <protocol.h>
|
||||
#include <pubkey.h>
|
||||
#include <rpc/util.h>
|
||||
#include <script/signingprovider.h>
|
||||
#include <script/standard.h>
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
|
@ -158,20 +156,6 @@ FUZZ_TARGET_INIT(integer, initialize_integer)
|
|||
|
||||
const CKeyID key_id{u160};
|
||||
const CScriptID script_id{u160};
|
||||
// CTxDestination = CNoDestination ∪ PKHash ∪ ScriptHash ∪ WitnessV0ScriptHash ∪ WitnessV0KeyHash ∪ WitnessUnknown
|
||||
const PKHash pk_hash{u160};
|
||||
const ScriptHash script_hash{u160};
|
||||
const WitnessV0KeyHash witness_v0_key_hash{u160};
|
||||
const WitnessV0ScriptHash witness_v0_script_hash{u256};
|
||||
const std::vector<CTxDestination> destinations{pk_hash, script_hash, witness_v0_key_hash, witness_v0_script_hash};
|
||||
const SigningProvider store;
|
||||
for (const CTxDestination& destination : destinations) {
|
||||
(void)DescribeAddress(destination);
|
||||
(void)EncodeDestination(destination);
|
||||
(void)GetKeyForDestination(store, destination);
|
||||
(void)GetScriptForDestination(destination);
|
||||
(void)IsValidDestination(destination);
|
||||
}
|
||||
|
||||
{
|
||||
CDataStream stream(SER_NETWORK, INIT_PROTO_VERSION);
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
|
||||
#include <chainparams.h>
|
||||
#include <key_io.h>
|
||||
#include <rpc/util.h>
|
||||
#include <script/signingprovider.h>
|
||||
#include <script/standard.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
|
||||
#include <cassert>
|
||||
|
@ -39,12 +36,4 @@ FUZZ_TARGET_INIT(key_io, initialize_key_io)
|
|||
if (ext_pub_key.pubkey.size() == CPubKey::COMPRESSED_SIZE) {
|
||||
assert(ext_pub_key == DecodeExtPubKey(EncodeExtPubKey(ext_pub_key)));
|
||||
}
|
||||
|
||||
const CTxDestination tx_destination = DecodeDestination(random_string);
|
||||
(void)DescribeAddress(tx_destination);
|
||||
(void)GetKeyForDestination(/* store */ {}, tx_destination);
|
||||
(void)GetScriptForDestination(tx_destination);
|
||||
(void)IsValidDestination(tx_destination);
|
||||
|
||||
(void)IsValidDestinationString(random_string);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
#include <compressor.h>
|
||||
#include <core_io.h>
|
||||
#include <core_memusage.h>
|
||||
#include <key_io.h>
|
||||
#include <policy/policy.h>
|
||||
#include <pubkey.h>
|
||||
#include <rpc/util.h>
|
||||
#include <script/descriptor.h>
|
||||
#include <script/interpreter.h>
|
||||
#include <script/script.h>
|
||||
|
@ -188,9 +190,22 @@ FUZZ_TARGET_INIT(script, initialize_script)
|
|||
fuzzed_data_provider.ConsumeBool() ?
|
||||
DecodeDestination(fuzzed_data_provider.ConsumeRandomLengthString()) :
|
||||
ConsumeTxDestination(fuzzed_data_provider)};
|
||||
const CTxDestination tx_destination_2 = ConsumeTxDestination(fuzzed_data_provider);
|
||||
const CTxDestination tx_destination_2{ConsumeTxDestination(fuzzed_data_provider)};
|
||||
const std::string encoded_dest{EncodeDestination(tx_destination_1)};
|
||||
const UniValue json_dest{DescribeAddress(tx_destination_1)};
|
||||
Assert(tx_destination_1 == DecodeDestination(encoded_dest));
|
||||
(void)GetKeyForDestination(/* store */ {}, tx_destination_1);
|
||||
const CScript dest{GetScriptForDestination(tx_destination_1)};
|
||||
const bool valid{IsValidDestination(tx_destination_1)};
|
||||
Assert(dest.empty() != valid);
|
||||
|
||||
Assert(valid == IsValidDestinationString(encoded_dest));
|
||||
|
||||
(void)(tx_destination_1 == tx_destination_2);
|
||||
(void)(tx_destination_1 < tx_destination_2);
|
||||
if (tx_destination_1 == tx_destination_2) {
|
||||
Assert(encoded_dest == EncodeDestination(tx_destination_2));
|
||||
Assert(json_dest.write() == DescribeAddress(tx_destination_2).write());
|
||||
Assert(dest == GetScriptForDestination(tx_destination_2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue