1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 07:18:09 +00:00
trezor-firmware/core/tests/test_apps.cardano.bech32.py

41 lines
1.6 KiB
Python
Raw Normal View History

from common import * # isort:skip
2020-07-23 13:54:49 +00:00
from apps.cardano.helpers import bech32
2023-06-28 10:46:29 +00:00
2020-07-23 13:54:49 +00:00
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestCardanoBech32(unittest.TestCase):
def test_decode_and_encode(self):
expected_bechs = [
# human readable part, bech32
("a", "a12uel5l"),
2023-06-28 10:46:29 +00:00
(
"an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio",
"an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs",
),
2020-07-23 13:54:49 +00:00
("abcdef", "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw"),
2023-06-28 10:46:29 +00:00
(
"1",
"11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j",
),
2020-07-23 13:54:49 +00:00
("split", "split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w"),
2023-06-28 10:46:29 +00:00
(
"addr",
"addr1qzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsw8ezsk",
),
(
"addr_test",
"addr_test1qzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsu8d9w5",
),
2020-07-23 13:54:49 +00:00
]
for expected_human_readable_part, expected_bech in expected_bechs:
decoded = bech32._decode(expected_human_readable_part, expected_bech)
2020-07-23 13:54:49 +00:00
actual_bech = bech32.encode(expected_human_readable_part, decoded)
self.assertEqual(actual_bech, expected_bech)
if __name__ == "__main__":
unittest.main()