LCOV - code coverage report
Current view: top level - src/test - bech32_tests.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 40 40 100.0 %
Date: 2020-09-26 01:30:44 Functions: 18 18 100.0 %

          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          89 : BOOST_FIXTURE_TEST_SUITE(bech32_tests, BasicTestingSetup)
      12             : 
      13          95 : BOOST_AUTO_TEST_CASE(bip173_testvectors_valid)
      14             : {
      15           2 :     static const std::string CASES[] = {
      16           1 :         "A12UEL5L",
      17           1 :         "a12uel5l",
      18           1 :         "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs",
      19           1 :         "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw",
      20           1 :         "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j",
      21           1 :         "split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w",
      22           8 :         "?1ezyfcl",
      23             :     };
      24           8 :     for (const std::string& str : CASES) {
      25           7 :         auto ret = bech32::Decode(str);
      26           7 :         BOOST_CHECK(!ret.first.empty());
      27           7 :         std::string recode = bech32::Encode(ret.first, ret.second);
      28           7 :         BOOST_CHECK(!recode.empty());
      29           7 :         BOOST_CHECK(CaseInsensitiveEqual(str, recode));
      30           7 :     }
      31           1 : }
      32             : 
      33          95 : BOOST_AUTO_TEST_CASE(bip173_testvectors_invalid)
      34             : {
      35           2 :     static const std::string CASES[] = {
      36           1 :         " 1nwldj5",
      37           1 :         "\x7f""1axkwrx",
      38           1 :         "\x80""1eym55h",
      39           1 :         "an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
      40           1 :         "pzry9x0s0muk",
      41           1 :         "1pzry9x0s0muk",
      42           1 :         "x1b4n0q5v",
      43           1 :         "li1dgmt3",
      44           1 :         "de1lg7wt\xff",
      45           1 :         "A1G7SGD8",
      46           1 :         "10a06t8",
      47           1 :         "1qzzfhee",
      48           1 :         "a12UEL5L",
      49          15 :         "A12uEL5L",
      50             :     };
      51          15 :     for (const std::string& str : CASES) {
      52          14 :         auto ret = bech32::Decode(str);
      53          14 :         BOOST_CHECK(ret.first.empty());
      54          14 :     }
      55           1 : }
      56             : 
      57          89 : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.15