2021-01-18 22:30:46 +03:00
|
|
|
# Based on this specification from Pieter Wuille:
|
|
|
|
# https://github.com/sipa/bips/blob/bip-bech32m/bip-bech32m.mediawiki
|
|
|
|
|
2022-09-30 11:40:22 +03:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-04-04 06:55:26 +03:00
|
|
|
from chia.util.bech32m import bech32_decode
|
2021-01-12 19:37:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_valid_imports():
|
|
|
|
test_strings = [
|
|
|
|
"A1LQFN3A",
|
|
|
|
"a1lqfn3a",
|
2022-10-31 18:45:08 +03:00
|
|
|
"\n a1lqfn3a \n",
|
2021-01-12 19:37:58 +03:00
|
|
|
"an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6",
|
|
|
|
"abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx",
|
|
|
|
"11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8",
|
|
|
|
"split1checkupstagehandshakeupstreamerranterredcaperredlc445v",
|
|
|
|
"?1v759aa",
|
|
|
|
]
|
|
|
|
for test_str in test_strings:
|
|
|
|
hrp, data = bech32_decode(test_str)
|
|
|
|
assert data is not None
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_imports():
|
|
|
|
test_strings = [
|
|
|
|
f"{0x20}1xj0phk",
|
|
|
|
f"{0x7F}1g6xzxy",
|
|
|
|
f"{0x80}1vctc34",
|
|
|
|
"an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4",
|
|
|
|
"qyrz8wqd2c9m",
|
|
|
|
"1qyrz8wqd2c9m",
|
2022-10-31 18:45:08 +03:00
|
|
|
"\n 1qyrz8wqd2c9m \n",
|
2021-01-12 19:37:58 +03:00
|
|
|
"y1b0jsk6g",
|
|
|
|
"lt1igcx5c0",
|
|
|
|
"in1muywd",
|
|
|
|
"mm1crxm3i",
|
|
|
|
"au1s5cgom",
|
|
|
|
"M1VUXWEZ",
|
|
|
|
"16plkw9",
|
|
|
|
"1p2gdwpf",
|
|
|
|
]
|
|
|
|
for test_str in test_strings:
|
|
|
|
hrp, data = bech32_decode(test_str)
|
|
|
|
assert data is None
|