mirror of
https://github.com/SeedSigner/seedsigner.git
synced 2026-10-05 15:08:25 +00:00
Update test_mnemonic_generation.py
This commit is contained in:
@@ -2,17 +2,28 @@ import random
|
||||
|
||||
from embit import bip39
|
||||
from seedsigner.helpers import mnemonic_generation
|
||||
from seedsigner.models.settings_definition import SettingsConstants
|
||||
|
||||
|
||||
|
||||
def test_dice_rolls():
|
||||
""" Given 99 random dice rolls, the resulting mnemonic should be valid. """
|
||||
""" Given random dice rolls, the resulting mnemonic should be valid. """
|
||||
dice_rolls = ""
|
||||
for i in range(0, 99):
|
||||
# Do not need truly rigorous random for this test
|
||||
dice_rolls += str(random.randint(0, 5))
|
||||
|
||||
mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
|
||||
assert len(mnemonic) == 24
|
||||
assert bip39.mnemonic_is_valid(" ".join(mnemonic))
|
||||
|
||||
dice_rolls = ""
|
||||
for i in range(0, 50):
|
||||
# Do not need truly rigorous random for this test
|
||||
dice_rolls += str(random.randint(0, 5))
|
||||
|
||||
mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
|
||||
assert len(mnemonic) == 12
|
||||
assert bip39.mnemonic_is_valid(" ".join(mnemonic))
|
||||
|
||||
|
||||
@@ -23,11 +34,11 @@ def test_calculate_checksum():
|
||||
"""
|
||||
# Test mnemonics from https://iancoleman.io/bip39/
|
||||
partial_mnemonic = "crawl focus rescue cable view pledge rather dinner cousin unfair day"
|
||||
mnemonic = mnemonic_generation.calculate_checksum(partial_mnemonic.split(" "), wordlist_language_code=bip39.WORDLIST)
|
||||
mnemonic = mnemonic_generation.calculate_checksum(partial_mnemonic.split(" "), wordlist_language_code=SettingsConstants.WORDLIST_LANGUAGE__ENGLISH)
|
||||
assert bip39.mnemonic_is_valid(" ".join(mnemonic))
|
||||
|
||||
partial_mnemonic = "bubble father debate ankle injury fence mesh evolve section wet coyote violin pyramid flower rent arrow round clutch myth safe base skin mobile"
|
||||
mnemonic = mnemonic_generation.calculate_checksum(partial_mnemonic.split(" "), wordlist_language_code=bip39.WORDLIST)
|
||||
mnemonic = mnemonic_generation.calculate_checksum(partial_mnemonic.split(" "), wordlist_language_code=SettingsConstants.WORDLIST_LANGUAGE__ENGLISH)
|
||||
assert bip39.mnemonic_is_valid(" ".join(mnemonic))
|
||||
|
||||
|
||||
@@ -70,3 +81,28 @@ def test_known_dice_rolls():
|
||||
assert bip39.mnemonic_is_valid(actual)
|
||||
assert actual == expected
|
||||
|
||||
|
||||
|
||||
def test_50_dice_rolls():
|
||||
""" 50 dice roll input should yield the same 12-word mnemonic as iancoleman.io/bip39 """
|
||||
# Check "Show entropy details", paste in dice_rolls sequence, click "Hex", select "Mnemonic Length" as "12 Words"
|
||||
dice_rolls = "12345612345612345612345612345612345612345612345612"
|
||||
expected = "unveil nice picture region tragic fault cream strike tourist control recipe tourist"
|
||||
mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
|
||||
actual = " ".join(mnemonic)
|
||||
assert bip39.mnemonic_is_valid(actual)
|
||||
assert actual == expected
|
||||
|
||||
dice_rolls = "11111111111111111111111111111111111111111111111111"
|
||||
expected = "diet glad hat rural panther lawsuit act drop gallery urge where fit"
|
||||
mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
|
||||
actual = " ".join(mnemonic)
|
||||
assert bip39.mnemonic_is_valid(actual)
|
||||
assert actual == expected
|
||||
|
||||
dice_rolls = "66666666666666666666666666666666666666666666666666"
|
||||
expected = "senior morning song proud recycle toy search apple trigger lend vibrant arrest"
|
||||
mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
|
||||
actual = " ".join(mnemonic)
|
||||
assert bip39.mnemonic_is_valid(actual)
|
||||
assert actual == expected
|
||||
|
||||
Reference in New Issue
Block a user