LCOV - code coverage report
Current view: top level - src/test - bech32_tests.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 80 80 100.0 %
Date: 2021-06-29 14:35:33 Functions: 4 4 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 8 8 100.0 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2017 Pieter Wuille
#       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 <bech32.h>
#       6                 :            : #include <test/util/setup_common.h>
#       7                 :            : #include <test/util/str.h>
#       8                 :            : 
#       9                 :            : #include <boost/test/unit_test.hpp>
#      10                 :            : 
#      11                 :            : BOOST_FIXTURE_TEST_SUITE(bech32_tests, BasicTestingSetup)
#      12                 :            : 
#      13                 :            : BOOST_AUTO_TEST_CASE(bech32_testvectors_valid)
#      14                 :          2 : {
#      15                 :          2 :     static const std::string CASES[] = {
#      16                 :          2 :         "A12UEL5L",
#      17                 :          2 :         "a12uel5l",
#      18                 :          2 :         "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs",
#      19                 :          2 :         "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw",
#      20                 :          2 :         "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j",
#      21                 :          2 :         "split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w",
#      22                 :          2 :         "?1ezyfcl",
#      23                 :          2 :     };
#      24         [ +  + ]:         14 :     for (const std::string& str : CASES) {
#      25                 :         14 :         const auto dec = bech32::Decode(str);
#      26                 :         14 :         BOOST_CHECK(dec.encoding == bech32::Encoding::BECH32);
#      27                 :         14 :         std::string recode = bech32::Encode(bech32::Encoding::BECH32, dec.hrp, dec.data);
#      28                 :         14 :         BOOST_CHECK(!recode.empty());
#      29                 :         14 :         BOOST_CHECK(CaseInsensitiveEqual(str, recode));
#      30                 :         14 :     }
#      31                 :          2 : }
#      32                 :            : 
#      33                 :            : BOOST_AUTO_TEST_CASE(bech32m_testvectors_valid)
#      34                 :          2 : {
#      35                 :          2 :     static const std::string CASES[] = {
#      36                 :          2 :         "A1LQFN3A",
#      37                 :          2 :         "a1lqfn3a",
#      38                 :          2 :         "an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6",
#      39                 :          2 :         "abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx",
#      40                 :          2 :         "11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8",
#      41                 :          2 :         "split1checkupstagehandshakeupstreamerranterredcaperredlc445v",
#      42                 :          2 :         "?1v759aa"
#      43                 :          2 :     };
#      44         [ +  + ]:         14 :     for (const std::string& str : CASES) {
#      45                 :         14 :         const auto dec = bech32::Decode(str);
#      46                 :         14 :         BOOST_CHECK(dec.encoding == bech32::Encoding::BECH32M);
#      47                 :         14 :         std::string recode = bech32::Encode(bech32::Encoding::BECH32M, dec.hrp, dec.data);
#      48                 :         14 :         BOOST_CHECK(!recode.empty());
#      49                 :         14 :         BOOST_CHECK(CaseInsensitiveEqual(str, recode));
#      50                 :         14 :     }
#      51                 :          2 : }
#      52                 :            : 
#      53                 :            : BOOST_AUTO_TEST_CASE(bech32_testvectors_invalid)
#      54                 :          2 : {
#      55                 :          2 :     static const std::string CASES[] = {
#      56                 :          2 :         " 1nwldj5",
#      57                 :          2 :         "\x7f""1axkwrx",
#      58                 :          2 :         "\x80""1eym55h",
#      59                 :          2 :         "an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
#      60                 :          2 :         "pzry9x0s0muk",
#      61                 :          2 :         "1pzry9x0s0muk",
#      62                 :          2 :         "x1b4n0q5v",
#      63                 :          2 :         "li1dgmt3",
#      64                 :          2 :         "de1lg7wt\xff",
#      65                 :          2 :         "A1G7SGD8",
#      66                 :          2 :         "10a06t8",
#      67                 :          2 :         "1qzzfhee",
#      68                 :          2 :         "a12UEL5L",
#      69                 :          2 :         "A12uEL5L",
#      70                 :          2 :     };
#      71         [ +  + ]:         28 :     for (const std::string& str : CASES) {
#      72                 :         28 :         const auto dec = bech32::Decode(str);
#      73                 :         28 :         BOOST_CHECK(dec.encoding == bech32::Encoding::INVALID);
#      74                 :         28 :     }
#      75                 :          2 : }
#      76                 :            : 
#      77                 :            : BOOST_AUTO_TEST_CASE(bech32m_testvectors_invalid)
#      78                 :          2 : {
#      79                 :          2 :     static const std::string CASES[] = {
#      80                 :          2 :         " 1xj0phk",
#      81                 :          2 :         "\x7f""1g6xzxy",
#      82                 :          2 :         "\x80""1vctc34",
#      83                 :          2 :         "an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4",
#      84                 :          2 :         "qyrz8wqd2c9m",
#      85                 :          2 :         "1qyrz8wqd2c9m",
#      86                 :          2 :         "y1b0jsk6g",
#      87                 :          2 :         "lt1igcx5c0",
#      88                 :          2 :         "in1muywd",
#      89                 :          2 :         "mm1crxm3i",
#      90                 :          2 :         "au1s5cgom",
#      91                 :          2 :         "M1VUXWEZ",
#      92                 :          2 :         "16plkw9",
#      93                 :          2 :         "1p2gdwpf"
#      94                 :          2 :     };
#      95         [ +  + ]:         28 :     for (const std::string& str : CASES) {
#      96                 :         28 :         const auto dec = bech32::Decode(str);
#      97                 :         28 :         BOOST_CHECK(dec.encoding == bech32::Encoding::INVALID);
#      98                 :         28 :     }
#      99                 :          2 : }
#     100                 :            : 
#     101                 :            : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.14