lbry-sdk/tests/unit/wallet/test_mnemonic.py

43 lines
1.4 KiB
Python
Raw Normal View History

2020-05-10 00:33:23 +02:00
from unittest import TestCase
2018-05-25 08:03:25 +02:00
from binascii import hexlify
2020-05-10 00:33:23 +02:00
from lbry.wallet import words
from lbry.wallet.mnemonic import (
get_languages, is_valid,
sync_generate as generate,
sync_to_seed as to_seed
)
2018-05-25 08:03:25 +02:00
2020-05-10 00:33:23 +02:00
class TestMnemonic(TestCase):
2018-05-25 08:03:25 +02:00
2020-05-10 00:33:23 +02:00
def test_get_languages(self):
languages = get_languages()
self.assertEqual(len(languages), 6)
for lang in languages:
self.assertEqual(len(getattr(words, lang)), 2048)
def test_is_valid(self):
self.assertFalse(is_valid('en', ''))
self.assertFalse(is_valid('en', 'foo'))
self.assertFalse(is_valid('en', 'awesomeball'))
self.assertTrue(is_valid('en', 'awesome ball'))
# check normalize works (these are not the same)
self.assertTrue(is_valid('ja', 'るいじ りんご'))
self.assertTrue(is_valid('ja', 'るいじ りんご'))
def test_generate(self):
self.assertGreaterEqual(len(generate('en').split()), 11)
self.assertGreaterEqual(len(generate('ja').split()), 11)
def test_to_seed(self):
2018-05-25 08:03:25 +02:00
self.assertEqual(
2020-05-10 00:33:23 +02:00
hexlify(to_seed(
"carbon smart garage balance margin twelve che"
"st sword toast envelope bottom stomach absent"
)),
b'919455c9f65198c3b0f8a2a656f13bd0ecc436abfabcb6a2a1f063affbccb628'
b'230200066117a30b1aa3aec2800ddbd3bf405f088dd7c98ba4f25f58d47e1baf'
2018-05-25 08:03:25 +02:00
)