Skip to content

Commit 32b9c93

Browse files
committed
Work toward exercising full spectrum of extendable mnemonics
1 parent 2191ccd commit 32b9c93

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

slip39/recovery_test.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from collections import deque
1717

1818
import shamir_mnemonic
19+
from shamir_mnemonic.constants import MAX_SHARE_COUNT
1920

2021
from .api import create, account, path_hardened
2122
from .recovery import recover, recover_bip39, shannon_entropy, signal_entropy, analyze_entropy
@@ -478,14 +479,23 @@ def test_create_recover_smoke_extendable():
478479
slip_simple_mnems[0][:1] + slip_extend_b_mnems[2][:2]
479480
)
480481

481-
# OK, extended allows you to create a SLIP-39 system with a certain number of groups of certain
482-
# sizes, and later, produce *additional* cards in any of those same groups. The number of
483-
# groups, group required and cards required in each group stays the same.
482+
# OK, extended allows you to create a SLIP-39 mnemonic system with a certain number of groups of
483+
# certain sizes, and later, produce *additional* cards in any of those same groups (w/ mnemonics
484+
# required > 1). The number of groups, group required and mnemonics required in each group
485+
# stays the same.
486+
487+
for _ in range( 10 ):
488+
group_count = random.choice( range( 1, MAX_SHARE_COUNT + 1 ))
489+
group_threshold = random.choice( range( 1, group_count + 1 ))
490+
groups = {}
491+
for gn in range( group_count ):
492+
gn_req = random.choice( range( 1, MAX_SHARE_COUNT + 1 ))
493+
gn_req_of = random.choice( range( gn_req, gn_req + ( 1 if gn_req == 1 else MAX_SHARE_COUNT - gn_req + 1 )))
494+
groups[ordinal( gn+1 )] = (gn_req, gn_req_of)
495+
log.warning( f"SLIP-39 {group_threshold} of {group_count}: {commas( ': '.join(map(str, i)) for i in groups.items() )}" )
496+
g = create( "non-extendable", group_threshold, groups, SEED_ONES, extendable=False )
497+
g_ext = create( "non-extendable", group_threshold, groups, SEED_ONES, extendable=True )
484498

485-
for _ in range( 100 ):
486-
groups = random.choice( range( 1, 5 ))
487-
groups_required = random.choice( range( 1, groups + 1 ))
488-
#xxx
489499

490500
@substitute( shamir_mnemonic.shamir, 'RANDOM_BYTES', nonrandom_bytes )
491501
def test_create_recover_bip39_extendable():

0 commit comments

Comments
 (0)