9#include <boost/test/unit_test.hpp>
13BOOST_AUTO_TEST_SUITE(bech32_tests)
17 static const std::string CASES[] = {
20 "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs",
21 "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw",
22 "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j",
23 "split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w",
26 for (
const std::string& str : CASES) {
37 static const std::string CASES[] = {
40 "an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6",
41 "abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx",
42 "11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8",
43 "split1checkupstagehandshakeupstreamerranterredcaperredlc445v",
46 for (
const std::string& str : CASES) {
57 static const std::string CASES[] = {
61 "an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
72 "abcdef1qpzrz9x8gf2tvdw0s3jn54khce6mua7lmqqqxw",
73 "test1zg69w7y6hn0aqy352euf40x77qddq3dc",
75 static const std::pair<std::string, std::vector<int>> ERRORS[] = {
76 {
"Invalid character or mixed case", {0}},
77 {
"Invalid character or mixed case", {0}},
78 {
"Invalid character or mixed case", {0}},
79 {
"Bech32 string too long", {90}},
80 {
"Missing separator", {}},
81 {
"Invalid separator position", {0}},
82 {
"Invalid Base 32 character", {2}},
83 {
"Invalid separator position", {2}},
84 {
"Invalid character or mixed case", {8}},
85 {
"Invalid checksum", {}},
86 {
"Invalid separator position", {0}},
87 {
"Invalid separator position", {0}},
88 {
"Invalid character or mixed case", {3, 4, 5, 7}},
89 {
"Invalid character or mixed case", {3}},
90 {
"Invalid Bech32 checksum", {11}},
91 {
"Invalid Bech32 checksum", {9, 16}},
93 static_assert(std::size(CASES) == std::size(ERRORS),
"Bech32 CASES and ERRORS should have the same length");
96 for (
const std::string& str : CASES) {
97 const auto& err = ERRORS[i];
109 static const std::string CASES[] = {
113 "an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4",
124 "abcdef1l7aum6echk45nj2s0wdvt2fg8x9yrzpqzd3ryx",
125 "test1zg69v7y60n00qy352euf40x77qcusag6",
127 static const std::pair<std::string, std::vector<int>> ERRORS[] = {
128 {
"Invalid character or mixed case", {0}},
129 {
"Invalid character or mixed case", {0}},
130 {
"Invalid character or mixed case", {0}},
131 {
"Bech32 string too long", {90}},
132 {
"Missing separator", {}},
133 {
"Invalid separator position", {0}},
134 {
"Invalid Base 32 character", {2}},
135 {
"Invalid Base 32 character", {3}},
136 {
"Invalid separator position", {2}},
137 {
"Invalid Base 32 character", {8}},
138 {
"Invalid Base 32 character", {7}},
139 {
"Invalid checksum", {}},
140 {
"Invalid separator position", {0}},
141 {
"Invalid separator position", {0}},
142 {
"Invalid Bech32m checksum", {21}},
143 {
"Invalid Bech32m checksum", {13, 32}},
145 static_assert(std::size(CASES) == std::size(ERRORS),
"Bech32m CASES and ERRORS should have the same length");
148 for (
const std::string& str : CASES) {
149 const auto& err = ERRORS[i];
BOOST_AUTO_TEST_CASE(bech32_testvectors_valid)
BOOST_AUTO_TEST_SUITE_END()
std::pair< std::string, std::vector< int > > LocateErrors(const std::string &str, CharLimit limit)
Find index of an incorrect character in a Bech32 string.
@ INVALID
Failed decoding.
@ BECH32
Bech32 encoding as defined in BIP173.
@ BECH32M
Bech32m encoding as defined in BIP350.
DecodeResult Decode(const std::string &str, CharLimit limit)
Decode a Bech32 or Bech32m string.
std::string Encode(Encoding encoding, const std::string &hrp, const data &values)
Encode a Bech32 or Bech32m string.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool CaseInsensitiveEqual(const std::string &s1, const std::string &s2)