Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 1ed1f2f

Browse files
axicholgerd77
authored andcommitted
Add comprehensive test coverage for fromV3
1 parent 5735026 commit 1ed1f2f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/test/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ describe('.fromV3()', function () {
197197
this.timeout(180000) // 3minutes
198198
assert.equal(wallet.getAddressString(), '0xa9886ac7489ecbcbd79268a79ef00d940e5fe1f2')
199199
})
200+
it('should fail with invalid password', function () {
201+
var w = '{"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}'
202+
assert.throws(function () {
203+
Wallet.fromV3(w, 'wrongtestpassword')
204+
}, /^Error: Key derivation failed - possibly wrong passphrase$/)
205+
})
200206
it('should work with (broken) mixed-case input files', function () {
201207
var w = '{"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}'
202208
var wallet = Wallet.fromV3(w, 'testpassword', true)
@@ -215,11 +221,17 @@ describe('.fromV3()', function () {
215221
}, /^Error: Not a V3 wallet$/)
216222
})
217223
it('should fail for wrong kdf', function () {
218-
var w = '{"Crypto":{"kdf":"superkey"},"version":3}'
224+
var w = '{"crypto":{"kdf":"superkey"},"version":3}'
219225
assert.throws(function () {
220-
Wallet.fromV3(w, 'testpassword', true)
226+
Wallet.fromV3(w, 'testpassword')
221227
}, /^Error: Unsupported key derivation scheme$/)
222228
})
229+
it('should fail for wrong prf in pbkdf2', function () {
230+
var w = '{"crypto":{"kdf":"pbkdf2","kdfparams":{"prf":"invalid"}},"version":3}'
231+
assert.throws(function () {
232+
Wallet.fromV3(w, 'testpassword')
233+
}, /^Error: Unsupported parameters to PBKDF2$/)
234+
})
223235
})
224236

225237
describe('.fromEthSale()', function () {

0 commit comments

Comments
 (0)