LCOV - code coverage report
Current view: top level - src/test/fuzz - script_descriptor_cache.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 26 26
Test Date: 2024-09-01 05:20:30 Functions: 100.0 % 2 2
Branches: 57.7 % 52 30

             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 <pubkey.h>
       6                 :             : #include <script/descriptor.h>
       7                 :             : #include <test/fuzz/FuzzedDataProvider.h>
       8                 :             : #include <test/fuzz/fuzz.h>
       9                 :             : #include <test/fuzz/util.h>
      10                 :             : 
      11                 :             : #include <cstdint>
      12                 :             : #include <optional>
      13                 :             : #include <string>
      14                 :             : #include <vector>
      15                 :             : 
      16   [ +  -  +  - ]:         257 : FUZZ_TARGET(script_descriptor_cache)
      17                 :             : {
      18                 :         254 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      19                 :         254 :     DescriptorCache descriptor_cache;
      20   [ +  -  +  +  :       66914 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
                   +  + ]
      21         [ -  + ]:       66660 :         const std::vector<uint8_t> code = fuzzed_data_provider.ConsumeBytes<uint8_t>(BIP32_EXTKEY_SIZE);
      22         [ +  + ]:       66660 :         if (code.size() == BIP32_EXTKEY_SIZE) {
      23         [ +  - ]:       66565 :             CExtPubKey xpub;
      24         [ +  - ]:       66565 :             xpub.Decode(code.data());
      25         [ -  + ]:       66565 :             const uint32_t key_exp_pos = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
      26         [ +  - ]:       66565 :             CExtPubKey xpub_fetched;
      27   [ +  -  +  + ]:       66565 :             if (fuzzed_data_provider.ConsumeBool()) {
      28         [ +  - ]:       57994 :                 (void)descriptor_cache.GetCachedParentExtPubKey(key_exp_pos, xpub_fetched);
      29         [ +  - ]:       57994 :                 descriptor_cache.CacheParentExtPubKey(key_exp_pos, xpub);
      30   [ +  -  +  - ]:       57994 :                 assert(descriptor_cache.GetCachedParentExtPubKey(key_exp_pos, xpub_fetched));
      31                 :       57994 :             } else {
      32         [ +  - ]:        8571 :                 const uint32_t der_index = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
      33         [ +  - ]:        8571 :                 (void)descriptor_cache.GetCachedDerivedExtPubKey(key_exp_pos, der_index, xpub_fetched);
      34         [ +  - ]:        8571 :                 descriptor_cache.CacheDerivedExtPubKey(key_exp_pos, der_index, xpub);
      35   [ +  -  +  - ]:        8571 :                 assert(descriptor_cache.GetCachedDerivedExtPubKey(key_exp_pos, der_index, xpub_fetched));
      36                 :        8571 :             }
      37   [ +  -  -  + ]:       66565 :             assert(xpub == xpub_fetched);
      38                 :       66565 :         }
      39         [ +  - ]:       66660 :         (void)descriptor_cache.GetCachedParentExtPubKeys();
      40         [ +  - ]:       66660 :         (void)descriptor_cache.GetCachedDerivedExtPubKeys();
      41                 :       66660 :     }
      42                 :         254 : }
        

Generated by: LCOV version 2.0-1