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

43 lines
1.5 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 (
2020-05-18 14:28:23 +02:00
get_languages, is_phrase_valid as is_valid,
sync_generate_phrase as generate,
sync_derive_key_from_phrase as derive
2020-05-10 00:33:23 +02:00
)
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)
2020-05-18 14:28:23 +02:00
def test_is_phrase_valid(self):
2020-05-10 00:33:23 +02:00
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', 'るいじ りんご'))
2020-05-18 14:28:23 +02:00
def test_generate_phrase(self):
2020-05-10 00:33:23 +02:00
self.assertGreaterEqual(len(generate('en').split()), 11)
self.assertGreaterEqual(len(generate('ja').split()), 11)
2020-05-18 14:28:23 +02:00
def test_phrase_to_key(self):
2018-05-25 08:03:25 +02:00
self.assertEqual(
2020-05-18 14:28:23 +02:00
hexlify(derive(
2020-05-10 00:33:23 +02:00
"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
)