Bitcoin Core  22.99.0
P2P Digital Currency
primitives_transaction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
7 #include <test/fuzz/fuzz.h>
8 #include <test/fuzz/util.h>
9 
10 #include <cstdint>
11 #include <optional>
12 #include <string>
13 #include <vector>
14 
15 FUZZ_TARGET(primitives_transaction)
16 {
17  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
18  const CScript script = ConsumeScript(fuzzed_data_provider);
19  const std::optional<COutPoint> out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
20  if (out_point) {
21  const CTxIn tx_in{*out_point, script, fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
22  (void)tx_in;
23  }
24  const CTxOut tx_out_1{ConsumeMoney(fuzzed_data_provider), script};
25  const CTxOut tx_out_2{ConsumeMoney(fuzzed_data_provider), ConsumeScript(fuzzed_data_provider)};
26  assert((tx_out_1 == tx_out_2) != (tx_out_1 != tx_out_2));
27  const std::optional<CMutableTransaction> mutable_tx_1 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
28  const std::optional<CMutableTransaction> mutable_tx_2 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
29  if (mutable_tx_1 && mutable_tx_2) {
30  const CTransaction tx_1{*mutable_tx_1};
31  const CTransaction tx_2{*mutable_tx_2};
32  assert((tx_1 == tx_2) != (tx_1 != tx_2));
33  }
34 }
CTxIn
An input of a transaction.
Definition: transaction.h:65
assert
assert(!tx.IsCoinBase())
transaction.h
util.h
FUZZ_TARGET
FUZZ_TARGET(primitives_transaction)
Definition: primitives_transaction.cpp:15
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:259
ConsumeScript
CScript ConsumeScript(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length, const bool maybe_p2wsh) noexcept
Definition: util.cpp:285
CTxOut
An output of a transaction.
Definition: transaction.h:128
FuzzedDataProvider.h
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
fuzz.h
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition: FuzzedDataProvider.h:194
ConsumeMoney
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
Definition: util.cpp:221