@@ -24,6 +24,10 @@ const fixturePublicKeyBuffer = Buffer.from(fixturePublicKey, 'hex')
24
24
const fixtureWallet = Wallet . fromPrivateKey ( fixturePrivateKeyBuffer )
25
25
const fixtureEthersWallet = new ethersWallet ( fixtureWallet . getPrivateKeyString ( ) )
26
26
27
+ const isRunningInKarma = ( ) => {
28
+ return typeof ( global as any ) . window !== 'undefined' && ( global as any ) . window . __karma__
29
+ }
30
+
27
31
describe ( '.getPrivateKey()' , function ( ) {
28
32
it ( 'should work' , function ( ) {
29
33
assert . strictEqual ( fixtureWallet . getPrivateKey ( ) . toString ( 'hex' ) , fixturePrivateKey )
@@ -212,7 +216,7 @@ describe('.toV3()', function() {
212
216
const makePermutations = ( ...objs : Array < object > ) : Array < object > => {
213
217
const permus = [ ]
214
218
const keys = Array . from (
215
- objs . reduce ( ( acc : Set < string > , curr : object ) => {
219
+ objs . reduce ( ( acc : any , curr : object ) => {
216
220
Object . keys ( curr ) . forEach ( key => {
217
221
acc . add ( key )
218
222
} )
@@ -246,7 +250,13 @@ describe('.toV3()', function() {
246
250
return obj
247
251
}
248
252
249
- const permutations = makePermutations ( strKdfOptions , buffKdfOptions )
253
+ let permutations = makePermutations ( strKdfOptions , buffKdfOptions )
254
+
255
+ if ( isRunningInKarma ( ) ) {
256
+ // These tests take a long time in the browser due to
257
+ // the amount of permutations so we will shorten them.
258
+ permutations = permutations . slice ( 1 )
259
+ }
250
260
251
261
it ( 'should work with PBKDF2' , async function ( ) {
252
262
this . timeout ( 0 ) // never
@@ -669,19 +679,22 @@ describe('.fromV3()', function() {
669
679
it ( 'should fail with invalid password' , function ( ) {
670
680
const w =
671
681
'{"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"id":"3198bc9c-6672-5ab3-d995-4942343ae5b6","version":3}'
682
+ this . timeout ( 0 ) // never
672
683
assert . throws ( function ( ) {
673
684
Wallet . fromV3 ( w , 'wrongtestpassword' )
674
685
} , / ^ E r r o r : K e y d e r i v a t i o n f a i l e d - p o s s i b l y w r o n g p a s s p h r a s e $ / )
675
686
} )
676
687
it ( 'should work with (broken) mixed-case input files' , function ( ) {
677
688
const w =
678
689
'{"Crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"id":"3198bc9c-6672-5ab3-d995-4942343ae5b6","version":3}'
690
+ this . timeout ( 0 ) // never
679
691
const wallet = Wallet . fromV3 ( w , 'testpassword' , true )
680
692
assert . strictEqual ( wallet . getAddressString ( ) , '0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b' )
681
693
} )
682
694
it ( "shouldn't work with (broken) mixed-case input files in strict mode" , function ( ) {
683
695
const w =
684
696
'{"Crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"id":"3198bc9c-6672-5ab3-d995-4942343ae5b6","version":3}'
697
+ this . timeout ( 0 ) // never
685
698
assert . throws ( function ( ) {
686
699
Wallet . fromV3 ( w , 'testpassword' )
687
700
} ) // FIXME: check for assert message(s)
@@ -760,6 +773,7 @@ describe('.fromKryptoKit()', function() {
760
773
'qhah1VeT0RgTvff1UKrUrxtFViiQuki16dd353d59888c25' ,
761
774
'testtest' ,
762
775
)
776
+ this . timeout ( 0 ) // never
763
777
assert . strictEqual ( wallet . getAddressString ( ) , '0x3c753e27834db67329d1ec1fab67970ec1e27112' )
764
778
} )
765
779
} )
0 commit comments