diff options
author | Pieter Wuille <pieter@wuille.net> | 2021-01-05 13:12:04 -0800 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2021-03-27 12:09:13 -0700 |
commit | 8944aaa6d6ce55faa6224e288fe0a14dbbf5ca4f (patch) | |
tree | d609c2264b2783673d3815b9dcdf2f117d8f5c3a /src/test/bech32_tests.cpp | |
parent | 1485533092a0732bae55313659a3e3f9669fd77a (diff) | |
download | bitcoin-8944aaa6d6ce55faa6224e288fe0a14dbbf5ca4f.tar.xz |
Add Bech32m test vectors
Github-Pull: #20861
Rebased-From: 25b1c6e13ddf1626210d5e3d37298d1f3a78a94f
Diffstat (limited to 'src/test/bech32_tests.cpp')
-rw-r--r-- | src/test/bech32_tests.cpp | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/src/test/bech32_tests.cpp b/src/test/bech32_tests.cpp index 2ddc284761..2651e46430 100644 --- a/src/test/bech32_tests.cpp +++ b/src/test/bech32_tests.cpp @@ -10,7 +10,7 @@ BOOST_FIXTURE_TEST_SUITE(bech32_tests, BasicTestingSetup) -BOOST_AUTO_TEST_CASE(bip173_testvectors_valid) +BOOST_AUTO_TEST_CASE(bech32_testvectors_valid) { static const std::string CASES[] = { "A12UEL5L", @@ -30,7 +30,27 @@ BOOST_AUTO_TEST_CASE(bip173_testvectors_valid) } } -BOOST_AUTO_TEST_CASE(bip173_testvectors_invalid) +BOOST_AUTO_TEST_CASE(bech32m_testvectors_valid) +{ + static const std::string CASES[] = { + "A1LQFN3A", + "a1lqfn3a", + "an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6", + "abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx", + "11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8", + "split1checkupstagehandshakeupstreamerranterredcaperredlc445v", + "?1v759aa" + }; + for (const std::string& str : CASES) { + const auto dec = bech32::Decode(str); + BOOST_CHECK(dec.encoding == bech32::Encoding::BECH32M); + std::string recode = bech32::Encode(bech32::Encoding::BECH32M, dec.hrp, dec.data); + BOOST_CHECK(!recode.empty()); + BOOST_CHECK(CaseInsensitiveEqual(str, recode)); + } +} + +BOOST_AUTO_TEST_CASE(bech32_testvectors_invalid) { static const std::string CASES[] = { " 1nwldj5", @@ -50,7 +70,31 @@ BOOST_AUTO_TEST_CASE(bip173_testvectors_invalid) }; for (const std::string& str : CASES) { const auto dec = bech32::Decode(str); - BOOST_CHECK(dec.encoding != bech32::Encoding::BECH32); + BOOST_CHECK(dec.encoding == bech32::Encoding::INVALID); + } +} + +BOOST_AUTO_TEST_CASE(bech32m_testvectors_invalid) +{ + static const std::string CASES[] = { + " 1xj0phk", + "\x7f""1g6xzxy", + "\x80""1vctc34", + "an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4", + "qyrz8wqd2c9m", + "1qyrz8wqd2c9m", + "y1b0jsk6g", + "lt1igcx5c0", + "in1muywd", + "mm1crxm3i", + "au1s5cgom", + "M1VUXWEZ", + "16plkw9", + "1p2gdwpf" + }; + for (const std::string& str : CASES) { + const auto dec = bech32::Decode(str); + BOOST_CHECK(dec.encoding == bech32::Encoding::INVALID); } } |