Skip to content

Commit 25b1c6e

Browse files
committed
Add Bech32m test vectors
1 parent da2bb69 commit 25b1c6e

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

src/test/bech32_tests.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
BOOST_FIXTURE_TEST_SUITE(bech32_tests, BasicTestingSetup)
1212

13-
BOOST_AUTO_TEST_CASE(bip173_testvectors_valid)
13+
BOOST_AUTO_TEST_CASE(bech32_testvectors_valid)
1414
{
1515
static const std::string CASES[] = {
1616
"A12UEL5L",
@@ -30,7 +30,27 @@ BOOST_AUTO_TEST_CASE(bip173_testvectors_valid)
3030
}
3131
}
3232

33-
BOOST_AUTO_TEST_CASE(bip173_testvectors_invalid)
33+
BOOST_AUTO_TEST_CASE(bech32m_testvectors_valid)
34+
{
35+
static const std::string CASES[] = {
36+
"A1LQFN3A",
37+
"a1lqfn3a",
38+
"an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6",
39+
"abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx",
40+
"11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8",
41+
"split1checkupstagehandshakeupstreamerranterredcaperredlc445v",
42+
"?1v759aa"
43+
};
44+
for (const std::string& str : CASES) {
45+
const auto dec = bech32::Decode(str);
46+
BOOST_CHECK(dec.encoding == bech32::Encoding::BECH32M);
47+
std::string recode = bech32::Encode(bech32::Encoding::BECH32M, dec.hrp, dec.data);
48+
BOOST_CHECK(!recode.empty());
49+
BOOST_CHECK(CaseInsensitiveEqual(str, recode));
50+
}
51+
}
52+
53+
BOOST_AUTO_TEST_CASE(bech32_testvectors_invalid)
3454
{
3555
static const std::string CASES[] = {
3656
" 1nwldj5",
@@ -50,7 +70,31 @@ BOOST_AUTO_TEST_CASE(bip173_testvectors_invalid)
5070
};
5171
for (const std::string& str : CASES) {
5272
const auto dec = bech32::Decode(str);
53-
BOOST_CHECK(dec.encoding != bech32::Encoding::BECH32);
73+
BOOST_CHECK(dec.encoding == bech32::Encoding::INVALID);
74+
}
75+
}
76+
77+
BOOST_AUTO_TEST_CASE(bech32m_testvectors_invalid)
78+
{
79+
static const std::string CASES[] = {
80+
" 1xj0phk",
81+
"\x7f""1g6xzxy",
82+
"\x80""1vctc34",
83+
"an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4",
84+
"qyrz8wqd2c9m",
85+
"1qyrz8wqd2c9m",
86+
"y1b0jsk6g",
87+
"lt1igcx5c0",
88+
"in1muywd",
89+
"mm1crxm3i",
90+
"au1s5cgom",
91+
"M1VUXWEZ",
92+
"16plkw9",
93+
"1p2gdwpf"
94+
};
95+
for (const std::string& str : CASES) {
96+
const auto dec = bech32::Decode(str);
97+
BOOST_CHECK(dec.encoding == bech32::Encoding::INVALID);
5498
}
5599
}
56100

0 commit comments

Comments
 (0)