forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add fuzzing harness for functions in primitives/transaction.h
- Loading branch information
1 parent
d5a31b7
commit fd8e99d
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <optional.h> | ||
#include <primitives/transaction.h> | ||
#include <test/fuzz/FuzzedDataProvider.h> | ||
#include <test/fuzz/fuzz.h> | ||
#include <test/fuzz/util.h> | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <vector> | ||
|
||
void test_one_input(const std::vector<uint8_t>& buffer) | ||
{ | ||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); | ||
const CScript script = ConsumeScript(fuzzed_data_provider); | ||
const Optional<COutPoint> out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider); | ||
if (out_point) { | ||
const CTxIn tx_in{*out_point, script, fuzzed_data_provider.ConsumeIntegral<uint32_t>()}; | ||
(void)tx_in; | ||
} | ||
const CTxOut tx_out_1{ConsumeMoney(fuzzed_data_provider), script}; | ||
const CTxOut tx_out_2{ConsumeMoney(fuzzed_data_provider), ConsumeScript(fuzzed_data_provider)}; | ||
assert((tx_out_1 == tx_out_2) != (tx_out_1 != tx_out_2)); | ||
const Optional<CMutableTransaction> mutable_tx_1 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider); | ||
const Optional<CMutableTransaction> mutable_tx_2 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider); | ||
if (mutable_tx_1 && mutable_tx_2) { | ||
const CTransaction tx_1{*mutable_tx_1}; | ||
const CTransaction tx_2{*mutable_tx_2}; | ||
assert((tx_1 == tx_2) != (tx_1 != tx_2)); | ||
} | ||
} |