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

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2019-2022 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 <test/fuzz/fuzz.h>
       6                 :             : 
       7                 :             : #include <base58.h>
       8                 :             : #include <psbt.h>
       9                 :             : #include <util/strencodings.h>
      10                 :             : #include <util/string.h>
      11                 :             : 
      12                 :             : #include <cassert>
      13                 :             : #include <cstdint>
      14                 :             : #include <string>
      15                 :             : #include <vector>
      16                 :             : 
      17                 :             : using util::TrimString;
      18                 :             : using util::TrimStringView;
      19                 :             : 
      20   [ +  -  +  - ]:        2252 : FUZZ_TARGET(base_encode_decode)
      21                 :             : {
      22         [ +  - ]:        2249 :     const std::string random_encoded_string(buffer.begin(), buffer.end());
      23                 :             : 
      24                 :        2249 :     std::vector<unsigned char> decoded;
      25   [ +  -  +  + ]:        2249 :     if (DecodeBase58(random_encoded_string, decoded, 100)) {
      26   [ +  -  +  - ]:         177 :         const std::string encoded_string = EncodeBase58(decoded);
      27   [ +  -  +  - ]:         177 :         assert(encoded_string == TrimStringView(encoded_string));
      28   [ +  -  +  -  :         177 :         assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
             +  -  +  - ]
      29                 :         177 :     }
      30                 :             : 
      31   [ +  -  +  + ]:        2249 :     if (DecodeBase58Check(random_encoded_string, decoded, 100)) {
      32   [ +  -  +  - ]:          21 :         const std::string encoded_string = EncodeBase58Check(decoded);
      33   [ +  -  +  - ]:          21 :         assert(encoded_string == TrimString(encoded_string));
      34   [ +  -  +  -  :          21 :         assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
             +  -  +  - ]
      35                 :          21 :     }
      36                 :             : 
      37         [ +  - ]:        2249 :     auto result = DecodeBase32(random_encoded_string);
      38         [ +  + ]:        2249 :     if (result) {
      39   [ +  -  +  - ]:          33 :         const std::string encoded_string = EncodeBase32(*result);
      40   [ +  -  +  - ]:          33 :         assert(encoded_string == TrimStringView(encoded_string));
      41   [ +  -  +  -  :          33 :         assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
             +  -  +  - ]
      42                 :          33 :     }
      43                 :             : 
      44         [ +  - ]:        2249 :     result = DecodeBase64(random_encoded_string);
      45         [ +  + ]:        2249 :     if (result) {
      46   [ +  -  +  - ]:        2081 :         const std::string encoded_string = EncodeBase64(*result);
      47   [ +  -  +  - ]:        2081 :         assert(encoded_string == TrimString(encoded_string));
      48   [ +  -  +  -  :        2081 :         assert(ToLower(encoded_string) == ToLower(TrimString(random_encoded_string)));
             +  -  +  - ]
      49                 :        2081 :     }
      50                 :             : 
      51                 :        2249 :     PartiallySignedTransaction psbt;
      52                 :        2249 :     std::string error;
      53         [ +  - ]:        2249 :     (void)DecodeBase64PSBT(psbt, random_encoded_string, error);
      54                 :        2249 : }
        

Generated by: LCOV version 2.0-1