diff options
| author | practicalswift <[email protected]> | 2020-04-26 19:29:03 +0000 |
|---|---|---|
| committer | practicalswift <[email protected]> | 2020-04-30 13:19:24 +0000 |
| commit | 13c1f6b24fa5e53f100d90d36b47b7dd3bc91b9f (patch) | |
| tree | b390f9ac3c8692799c95bad76daf8d7df3923b80 /src/test | |
| parent | tests: Add fuzzing harness for CBlockPolicyEstimator (diff) | |
| download | discoin-13c1f6b24fa5e53f100d90d36b47b7dd3bc91b9f.tar.xz discoin-13c1f6b24fa5e53f100d90d36b47b7dd3bc91b9f.zip | |
tests: Add fuzzing harness for IsRBFOptIn(...)
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/fuzz/rbf.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/fuzz/rbf.cpp b/src/test/fuzz/rbf.cpp new file mode 100644 index 000000000..eb54b05df --- /dev/null +++ b/src/test/fuzz/rbf.cpp @@ -0,0 +1,47 @@ +// 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 <policy/rbf.h> +#include <primitives/transaction.h> +#include <sync.h> +#include <test/fuzz/FuzzedDataProvider.h> +#include <test/fuzz/fuzz.h> +#include <test/fuzz/util.h> +#include <txmempool.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()); + Optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider); + if (!mtx) { + return; + } + CTxMemPool pool; + while (fuzzed_data_provider.ConsumeBool()) { + const Optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider); + if (!another_mtx) { + break; + } + const CTransaction another_tx{*another_mtx}; + if (fuzzed_data_provider.ConsumeBool() && !mtx->vin.empty()) { + mtx->vin[0].prevout = COutPoint{another_tx.GetHash(), 0}; + } + LOCK2(cs_main, pool.cs); + pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, another_tx)); + } + const CTransaction tx{*mtx}; + if (fuzzed_data_provider.ConsumeBool()) { + LOCK2(cs_main, pool.cs); + pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx)); + } + { + LOCK(pool.cs); + (void)IsRBFOptIn(tx, pool); + } +} |