LCOV - code coverage report
Current view: top level - src/test/fuzz - bloom_filter.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 0.0 % 43 0
Test Date: 2024-08-28 04:44:32 Functions: 0.0 % 6 0
Branches: 0.0 % 38 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020-2021 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 <common/bloom.h>
       6                 :             : #include <primitives/transaction.h>
       7                 :             : #include <test/fuzz/FuzzedDataProvider.h>
       8                 :             : #include <test/fuzz/fuzz.h>
       9                 :             : #include <test/fuzz/util.h>
      10                 :             : #include <uint256.h>
      11                 :             : 
      12                 :             : #include <cassert>
      13                 :             : #include <limits>
      14                 :             : #include <optional>
      15                 :             : #include <vector>
      16                 :             : 
      17         [ #  # ]:           0 : FUZZ_TARGET(bloom_filter)
      18                 :             : {
      19                 :           0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      20                 :           0 :     bool good_data{true};
      21                 :             : 
      22                 :           0 :     CBloomFilter bloom_filter{
      23                 :             :         fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(1, 10000000),
      24                 :           0 :         1.0 / fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(1, std::numeric_limits<unsigned int>::max()),
      25                 :             :         fuzzed_data_provider.ConsumeIntegral<unsigned int>(),
      26                 :           0 :         static_cast<unsigned char>(fuzzed_data_provider.PickValueInArray({BLOOM_UPDATE_NONE, BLOOM_UPDATE_ALL, BLOOM_UPDATE_P2PUBKEY_ONLY, BLOOM_UPDATE_MASK}))};
      27   [ #  #  #  #  :           0 :     LIMITED_WHILE(good_data && fuzzed_data_provider.remaining_bytes() > 0, 10'000)
                   #  # ]
      28                 :             :     {
      29         [ #  # ]:           0 :         CallOneOf(
      30                 :             :             fuzzed_data_provider,
      31                 :           0 :             [&] {
      32                 :           0 :                 const std::vector<unsigned char> b = ConsumeRandomLengthByteVector(fuzzed_data_provider);
      33         [ #  # ]:           0 :                 (void)bloom_filter.contains(b);
      34         [ #  # ]:           0 :                 bloom_filter.insert(b);
      35         [ #  # ]:           0 :                 const bool present = bloom_filter.contains(b);
      36         [ #  # ]:           0 :                 assert(present);
      37                 :           0 :             },
      38                 :           0 :             [&] {
      39                 :           0 :                 const std::optional<COutPoint> out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
      40         [ #  # ]:           0 :                 if (!out_point) {
      41                 :           0 :                     good_data = false;
      42                 :           0 :                     return;
      43                 :             :                 }
      44                 :           0 :                 (void)bloom_filter.contains(*out_point);
      45                 :           0 :                 bloom_filter.insert(*out_point);
      46                 :           0 :                 const bool present = bloom_filter.contains(*out_point);
      47         [ #  # ]:           0 :                 assert(present);
      48                 :             :             },
      49                 :           0 :             [&] {
      50                 :           0 :                 const std::optional<uint256> u256 = ConsumeDeserializable<uint256>(fuzzed_data_provider);
      51         [ #  # ]:           0 :                 if (!u256) {
      52                 :           0 :                     good_data = false;
      53                 :           0 :                     return;
      54                 :             :                 }
      55                 :           0 :                 (void)bloom_filter.contains(*u256);
      56                 :           0 :                 bloom_filter.insert(*u256);
      57                 :           0 :                 const bool present = bloom_filter.contains(*u256);
      58         [ #  # ]:           0 :                 assert(present);
      59                 :             :             },
      60                 :           0 :             [&] {
      61                 :           0 :                 const std::optional<CMutableTransaction> mut_tx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
      62         [ #  # ]:           0 :                 if (!mut_tx) {
      63                 :           0 :                     good_data = false;
      64         [ #  # ]:           0 :                     return;
      65                 :             :                 }
      66         [ #  # ]:           0 :                 const CTransaction tx{*mut_tx};
      67         [ #  # ]:           0 :                 (void)bloom_filter.IsRelevantAndUpdate(tx);
      68         [ #  # ]:           0 :             });
      69         [ #  # ]:           0 :         (void)bloom_filter.IsWithinSizeConstraints();
      70                 :             :     }
      71                 :           0 : }
        

Generated by: LCOV version 2.0-1