File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -169,3 +169,30 @@ describe('Testnet Extended Key (#553)', function testMnemonic() {
169
169
} ) ;
170
170
} ) ;
171
171
} ) ;
172
+
173
+ describe ( "Test Mnemonic is Case Agnostic" , function ( ) {
174
+ function randomCase ( seed , text ) {
175
+ return text . split ( "" ) . map ( function ( c , index ) {
176
+ if ( utils . randomNumber ( seed + "-" + index , 0 , 1000 ) > 500 ) {
177
+ return c . toUpperCase ( ) ;
178
+ }
179
+ return c
180
+ } ) . join ( "" ) ;
181
+ }
182
+
183
+ function addTest ( mnemonic , altMnemonic ) {
184
+ it ( altMnemonic , function ( ) {
185
+ var node = ethers . utils . HDNode . fromMnemonic ( mnemonic ) ;
186
+ var altNode = ethers . utils . HDNode . fromMnemonic ( altMnemonic ) ;
187
+ assert . equal ( node . privateKey , altNode . privateKey , altMnemonic ) ;
188
+ } ) ;
189
+ }
190
+
191
+ for ( var i = 0 ; i < 128 ; i ++ ) {
192
+ var seed = "test-" + i ;
193
+ var entropy = utils . randomBytes ( seed , 16 , 16 ) ;
194
+ var mnemonic = ethers . utils . HDNode . entropyToMnemonic ( entropy ) ;
195
+ var altMnemonic = randomCase ( seed , mnemonic ) ;
196
+ addTest ( mnemonic , altMnemonic ) ;
197
+ }
198
+ } ) ;
You can’t perform that action at this time.
0 commit comments