6767 "sec_val, sec_error" ,
6868 [
6969 (None , "Secret must be a hex string." ),
70+ (True , "Secret must be a hex string." ),
71+ (False , "Secret must be a hex string." ),
7072 (1234 , "Secret must be a hex string." ),
7173 (- 256 , "Secret must be a hex string." ),
72- ("hello world" , "Invalid hex character: " ),
74+ ("hello world" , "Secret must be a hex string. " ),
7375 (None , None ),
7476 ],
7577)
8284 (- 22 , "Number of shares must be an integer >= 2." ),
8385 (
8486 "hello" ,
85- "Threshold number of shares must be less than or equal to the total shares specified." ,
87+ "Number of shares must be an integer >= 2." ,
88+ ),
89+ (
90+ lambda : settings .maxShares + 1 ,
91+ "Number of shares must be <=" ,
92+ ),
93+ (None , None ),
94+ ],
95+ )
96+ @pytest .mark .parametrize (
97+ "th_val, th_error" ,
98+ [
99+ (False , "Number of shares must be an integer >= 2." ),
100+ (2 , "Threshold number of shares must be an integer >= 2." ),
101+ (0 , "Threshold number of shares must be an integer >= 2." ),
102+ (- 22 , "Threshold number of shares must be an integer >= 2." ),
103+ (
104+ "hello" ,
105+ "Threshold number of shares must be an integer >= 2." ,
86106 ),
87107 (
88108 lambda : settings .maxShares + 1 ,
89109 "Threshold number of shares must be <=" ,
90110 ),
111+ (
112+ lambda : numShares + 1 ,
113+ "Threshold number of shares must be less than or equal to the" ,
114+ ),
91115 (None , None ),
92116 ],
93117)
118+
94119@pytest .mark .skip (reason = "WIP: started seeing odd failures" )
95120def test_py_init_with_errors (
96121 bits ,
@@ -101,9 +126,11 @@ def test_py_init_with_errors(
101126 sec_error ,
102127 num_val ,
103128 num_error ,
129+ th_val ,
130+ th_error
104131):
105132
106- expected_error = check_error (bits_error , rand_error , sec_error , num_error )
133+ expected_error = check_error (bits_error , rand_error , sec_error , num_error , th_error )
107134
108135 if expected_error :
109136 with pytest .raises (ValueError , match = expected_error ):
@@ -112,33 +139,42 @@ def test_py_init_with_errors(
112139 secret = secrets .random (rand_bits )
113140 if sec_error :
114141 secret = sec_val
115- if not bits_error or rand_error or num_error :
142+ if not bits_error or rand_error or num_error or th_error :
116143 num_shares = base_value (num_val ) or 6
117144 shares = secrets .share (secret , num_shares , 3 )
118- if not bits_error or rand_error :
145+ if not bits_error or rand_error or th_error :
119146 num_shares = base_value (num_val )
120147 shares = secrets .share (secret , num_shares , 3 )
148+ if not bits_error or rand_error :
149+
150+ numShares = low_random (settings .maxShares , settings .bits )
151+ threshold = base_value (th_val )
152+ shares = secrets .share (secret , numShares , threshold )
153+
121154 assert len (caught_warnings ) == 1
122155 assert issubclass (caught_warnings [0 ].category , Warning )
123156 assert expected_error in str (caught_warnings [0 ].message )
124157 else :
125158 secrets .init (bits )
126159 assert bits == settings .bits or settings .get_defaults ().bits
127160
161+ numShares = low_random (settings .maxShares , settings .bits )
162+ threshold = low_random (numShares , settings .bits )
163+
128164 secret = secrets .random (rand_bits )
129- shares = secrets .share (secret , 6 , 3 )
165+ shares = secrets .share (secret , numShares , threshold )
130166
131167
132168# Used to catch the expected error
133- def check_error (bits_error , rand_error , sec_error , num_error ):
169+ def check_error (bits_error , rand_error , sec_error , num_error , th_error ):
134170 expected_error = (
135171 bits_error
136172 if bits_error
137173 else (
138174 rand_error
139175 if rand_error
140176 else (
141- sec_error if sec_error else (num_error if num_error else None )
177+ sec_error if sec_error else (num_error if num_error else ( th_error if th_error else None ) )
142178 )
143179 )
144180 )
0 commit comments