@@ -24,6 +24,10 @@ const fixturePublicKeyBuffer = Buffer.from(fixturePublicKey, 'hex')
2424const fixtureWallet = Wallet . fromPrivateKey ( fixturePrivateKeyBuffer )
2525const fixtureEthersWallet = new ethersWallet ( fixtureWallet . getPrivateKeyString ( ) )
2626
27+ const isRunningInKarma = ( ) => {
28+ return typeof ( global as any ) . window !== 'undefined' && ( global as any ) . window . __karma__
29+ }
30+
2731describe ( '.getPrivateKey()' , function ( ) {
2832 it ( 'should work' , function ( ) {
2933 assert . strictEqual ( fixtureWallet . getPrivateKey ( ) . toString ( 'hex' ) , fixturePrivateKey )
@@ -212,7 +216,7 @@ describe('.toV3()', function() {
212216 const makePermutations = ( ...objs : Array < object > ) : Array < object > => {
213217 const permus = [ ]
214218 const keys = Array . from (
215- objs . reduce ( ( acc : Set < string > , curr : object ) => {
219+ objs . reduce ( ( acc : any , curr : object ) => {
216220 Object . keys ( curr ) . forEach ( key => {
217221 acc . add ( key )
218222 } )
@@ -246,7 +250,13 @@ describe('.toV3()', function() {
246250 return obj
247251 }
248252
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+ }
250260
251261 it ( 'should work with PBKDF2' , async function ( ) {
252262 this . timeout ( 0 ) // never
@@ -669,19 +679,22 @@ describe('.fromV3()', function() {
669679 it ( 'should fail with invalid password' , function ( ) {
670680 const w =
671681 '{"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
672683 assert . throws ( function ( ) {
673684 Wallet . fromV3 ( w , 'wrongtestpassword' )
674685 } , / ^ 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 $ / )
675686 } )
676687 it ( 'should work with (broken) mixed-case input files' , function ( ) {
677688 const w =
678689 '{"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
679691 const wallet = Wallet . fromV3 ( w , 'testpassword' , true )
680692 assert . strictEqual ( wallet . getAddressString ( ) , '0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b' )
681693 } )
682694 it ( "shouldn't work with (broken) mixed-case input files in strict mode" , function ( ) {
683695 const w =
684696 '{"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
685698 assert . throws ( function ( ) {
686699 Wallet . fromV3 ( w , 'testpassword' )
687700 } ) // FIXME: check for assert message(s)
0 commit comments