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

             Branch data     Line data    Source code
       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 <chainparams.h>
       6                 :             : #include <common/signmessage.h>
       7                 :             : #include <key_io.h>
       8                 :             : #include <test/fuzz/FuzzedDataProvider.h>
       9                 :             : #include <test/fuzz/fuzz.h>
      10                 :             : #include <test/fuzz/util.h>
      11                 :             : #include <util/chaintype.h>
      12                 :             : #include <util/strencodings.h>
      13                 :             : 
      14                 :             : #include <cassert>
      15                 :             : #include <cstdint>
      16                 :             : #include <iostream>
      17                 :             : #include <string>
      18                 :             : #include <vector>
      19                 :             : 
      20                 :           0 : void initialize_message()
      21                 :             : {
      22   [ #  #  #  #  :           0 :     static ECC_Context ecc_context{};
                   #  # ]
      23                 :           0 :     SelectParams(ChainType::REGTEST);
      24                 :           0 : }
      25                 :             : 
      26         [ #  # ]:           0 : FUZZ_TARGET(message, .init = initialize_message)
      27                 :             : {
      28                 :           0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      29                 :           0 :     const std::string random_message = fuzzed_data_provider.ConsumeRandomLengthString(1024);
      30                 :           0 :     {
      31                 :           0 :         CKey private_key = ConsumePrivateKey(fuzzed_data_provider);
      32         [ #  # ]:           0 :         std::string signature;
      33         [ #  # ]:           0 :         const bool message_signed = MessageSign(private_key, random_message, signature);
      34         [ #  # ]:           0 :         if (private_key.IsValid()) {
      35         [ #  # ]:           0 :             assert(message_signed);
      36   [ #  #  #  #  :           0 :             const MessageVerificationResult verification_result = MessageVerify(EncodeDestination(PKHash(private_key.GetPubKey().GetID())), signature, random_message);
          #  #  #  #  #  
                      # ]
      37         [ #  # ]:           0 :             assert(verification_result == MessageVerificationResult::OK);
      38                 :             :         }
      39                 :           0 :     }
      40                 :           0 :     {
      41         [ #  # ]:           0 :         (void)MessageHash(random_message);
      42   [ #  #  #  #  :           0 :         (void)MessageVerify(fuzzed_data_provider.ConsumeRandomLengthString(1024), fuzzed_data_provider.ConsumeRandomLengthString(1024), random_message);
                   #  # ]
      43         [ #  # ]:           0 :         (void)SigningResultString(fuzzed_data_provider.PickValueInArray({SigningResult::OK, SigningResult::PRIVATE_KEY_NOT_AVAILABLE, SigningResult::SIGNING_FAILED}));
      44                 :             :     }
      45                 :           0 : }
        

Generated by: LCOV version 2.0-1