mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 08:51:32 +00:00
test_mnemonic: add foreign lang tests
This commit is contained in:
parent
86733279f6
commit
999ae1f713
2 changed files with 56 additions and 6 deletions
|
@ -1,18 +1,68 @@
|
|||
from electrum import keystore
|
||||
from electrum import mnemonic
|
||||
from electrum import old_mnemonic
|
||||
from electrum.util import bh2u
|
||||
from electrum.util import bh2u, bfh
|
||||
from electrum.bitcoin import is_new_seed
|
||||
from electrum.version import SEED_PREFIX_SW
|
||||
|
||||
from . import SequentialTestCase
|
||||
from .test_wallet_vertical import UNICODE_HORROR
|
||||
|
||||
|
||||
SEED_WORDS_JAPANESE = 'なのか ひろい しなん まなぶ つぶす さがす おしゃれ かわく おいかける けさき かいとう さたん'
|
||||
assert bh2u(SEED_WORDS_JAPANESE.encode('utf8')) == 'e381aae381aee3818b20e381b2e3828de3818420e38197e381aae3829320e381bee381aae381b5e3829920e381a4e381b5e38299e3819920e38195e3818be38299e3819920e3818ae38197e38283e3828c20e3818be3828fe3818f20e3818ae38184e3818be38191e3828b20e38191e38195e3818d20e3818be38184e381a8e3818620e38195e3819fe38293'
|
||||
|
||||
SEED_WORDS_CHINESE = '眼 悲 叛 改 节 跃 衡 响 疆 股 遂 冬'
|
||||
assert bh2u(SEED_WORDS_CHINESE.encode('utf8')) == 'e79cbc20e682b220e58f9b20e694b920e88a8220e8b78320e8a1a120e5938d20e7968620e882a120e9818220e586ac'
|
||||
|
||||
PASSPHRASE_CHINESE = '给我一些测试向量谷歌'
|
||||
assert bh2u(PASSPHRASE_CHINESE.encode('utf8')) == 'e7bb99e68891e4b880e4ba9be6b58be8af95e59091e9878fe8b0b7e6ad8c'
|
||||
|
||||
|
||||
class Test_NewMnemonic(SequentialTestCase):
|
||||
|
||||
def test_to_seed(self):
|
||||
def test_mnemonic_to_seed_basic(self):
|
||||
seed = mnemonic.Mnemonic.mnemonic_to_seed(mnemonic='foobar', passphrase='none')
|
||||
self.assertEqual(bh2u(seed),
|
||||
'741b72fd15effece6bfe5a26a52184f66811bd2be363190e07a42cca442b1a5b'
|
||||
'b22b3ad0eb338197287e6d314866c7fba863ac65d3f156087a5052ebc7157fce')
|
||||
self.assertEqual('741b72fd15effece6bfe5a26a52184f66811bd2be363190e07a42cca442b1a5bb22b3ad0eb338197287e6d314866c7fba863ac65d3f156087a5052ebc7157fce',
|
||||
bh2u(seed))
|
||||
|
||||
def test_mnemonic_to_seed_japanese(self):
|
||||
words = SEED_WORDS_JAPANESE
|
||||
self.assertTrue(is_new_seed(words))
|
||||
|
||||
m = mnemonic.Mnemonic(lang='ja')
|
||||
self.assertEqual(1938439226660562861250521787963972783469, m.mnemonic_decode(words))
|
||||
|
||||
seed = mnemonic.Mnemonic.mnemonic_to_seed(mnemonic=words, passphrase='')
|
||||
self.assertEqual('d3eaf0e44ddae3a5769cb08a26918e8b308258bcb057bb704c6f69713245c0b35cb92c03df9c9ece5eff826091b4e74041e010b701d44d610976ce8bfb66a8ad',
|
||||
bh2u(seed))
|
||||
|
||||
def test_mnemonic_to_seed_japanese_with_unicode_horror(self):
|
||||
words = SEED_WORDS_JAPANESE
|
||||
self.assertTrue(is_new_seed(words))
|
||||
|
||||
seed = mnemonic.Mnemonic.mnemonic_to_seed(mnemonic=words, passphrase=UNICODE_HORROR)
|
||||
self.assertEqual('251ee6b45b38ba0849e8f40794540f7e2c6d9d604c31d68d3ac50c034f8b64e4bc037c5e1e985a2fed8aad23560e690b03b120daf2e84dceb1d7857dda042457',
|
||||
bh2u(seed))
|
||||
|
||||
def test_mnemonic_to_seed_chinese(self):
|
||||
words = SEED_WORDS_CHINESE
|
||||
self.assertTrue(is_new_seed(words, prefix=SEED_PREFIX_SW))
|
||||
|
||||
m = mnemonic.Mnemonic(lang='zh')
|
||||
self.assertEqual(3083737086352778425940060465574397809099, m.mnemonic_decode(words))
|
||||
|
||||
seed = mnemonic.Mnemonic.mnemonic_to_seed(mnemonic=words, passphrase='')
|
||||
self.assertEqual('0b9077db7b5a50dbb6f61821e2d35e255068a5847e221138048a20e12d80b673ce306b6fe7ac174ebc6751e11b7037be6ee9f17db8040bb44f8466d519ce2abf',
|
||||
bh2u(seed))
|
||||
|
||||
def test_mnemonic_to_seed_chinese_with_passphrase(self):
|
||||
words = SEED_WORDS_CHINESE
|
||||
passphrase = PASSPHRASE_CHINESE
|
||||
self.assertTrue(is_new_seed(words, prefix=SEED_PREFIX_SW))
|
||||
seed = mnemonic.Mnemonic.mnemonic_to_seed(mnemonic=words, passphrase=passphrase)
|
||||
self.assertEqual('6c03dd0615cf59963620c0af6840b52e867468cc64f20a1f4c8155705738e87b8edb0fc8a6cee4085776cb3a629ff88bb1a38f37085efdbf11ce9ec5a7fa5f71',
|
||||
bh2u(seed))
|
||||
|
||||
def test_random_seeds(self):
|
||||
iters = 10
|
||||
|
|
|
@ -20,7 +20,7 @@ from .test_bitcoin import needs_test_with_all_ecc_implementations
|
|||
|
||||
_UNICODE_HORROR_HEX = 'e282bf20f09f988020f09f98882020202020e3818620e38191e3819fe381be20e3828fe3828b2077cda2cda2cd9d68cda16fcda2cda120ccb8cda26bccb5cd9f6eccb4cd98c7ab77ccb8cc9b73cd9820cc80cc8177cd98cda2e1b8a9ccb561d289cca1cda27420cca7cc9568cc816fccb572cd8fccb5726f7273cca120ccb6cda1cda06cc4afccb665cd9fcd9f20ccb6cd9d696ecda220cd8f74cc9568ccb7cca1cd9f6520cd9fcd9f64cc9b61cd9c72cc95cda16bcca2cca820cda168ccb465cd8f61ccb7cca2cca17274cc81cd8f20ccb4ccb7cda0c3b2ccb5ccb666ccb82075cca7cd986ec3adcc9bcd9c63cda2cd8f6fccb7cd8f64ccb8cda265cca1cd9d3fcd9e'
|
||||
UNICODE_HORROR = bfh(_UNICODE_HORROR_HEX).decode('utf-8')
|
||||
# '₿ 😀 😈 う けたま わる w͢͢͝h͡o͢͡ ̸͢k̵͟n̴͘ǫw̸̛s͘ ̀́w͘͢ḩ̵a҉̡͢t ̧̕h́o̵r͏̵rors̡ ̶͡͠lį̶e͟͟ ̶͝in͢ ͏t̕h̷̡͟e ͟͟d̛a͜r̕͡k̢̨ ͡h̴e͏a̷̢̡rt́͏ ̴̷͠ò̵̶f̸ u̧͘ní̛͜c͢͏o̷͏d̸͢e̡͝?͞'
|
||||
assert UNICODE_HORROR == '₿ 😀 😈 う けたま わる w͢͢͝h͡o͢͡ ̸͢k̵͟n̴͘ǫw̸̛s͘ ̀́w͘͢ḩ̵a҉̡͢t ̧̕h́o̵r͏̵rors̡ ̶͡͠lį̶e͟͟ ̶͝in͢ ͏t̕h̷̡͟e ͟͟d̛a͜r̕͡k̢̨ ͡h̴e͏a̷̢̡rt́͏ ̴̷͠ò̵̶f̸ u̧͘ní̛͜c͢͏o̷͏d̸͢e̡͝?͞'
|
||||
|
||||
|
||||
class WalletIntegrityHelper:
|
||||
|
|
Loading…
Add table
Reference in a new issue