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 
5 #include <policy/rbf.h>
6 #include <primitives/transaction.h>
7 #include <sync.h>
8 #include <test/fuzz/FuzzedDataProvider.h>
9 #include <test/fuzz/fuzz.h>
10 #include <test/fuzz/util.h>
11 #include <txmempool.h>
12 
13 #include <cstdint>
14 #include <optional>
15 #include <string>
16 #include <vector>
17 
test_one_input(const std::vector<uint8_t> & buffer)18 void test_one_input(const std::vector<uint8_t>& buffer)
19 {
20     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
21     std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
22     if (!mtx) {
23         return;
24     }
25     CTxMemPool pool;
26     while (fuzzed_data_provider.ConsumeBool()) {
27         const std::optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
28         if (!another_mtx) {
29             break;
30         }
31         const CTransaction another_tx{*another_mtx};
32         if (fuzzed_data_provider.ConsumeBool() && !mtx->vin.empty()) {
33             mtx->vin[0].prevout = COutPoint{another_tx.GetHash(), 0};
34         }
35         LOCK2(cs_main, pool.cs);
36         pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, another_tx));
37     }
38     const CTransaction tx{*mtx};
39     if (fuzzed_data_provider.ConsumeBool()) {
40         LOCK2(cs_main, pool.cs);
41         pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx));
42     }
43     {
44         LOCK(pool.cs);
45         (void)IsRBFOptIn(tx, pool);
46     }
47 }
48