Added tests covering toV3() function branches
This commit is contained in:
parent
93445039f9
commit
0032880429
|
@ -145,19 +145,23 @@ describe('.toV3()', function () {
|
||||||
var uuid = Buffer.from('7e59dc028d42d09db29aa8a0f862cc81', 'hex')
|
var uuid = Buffer.from('7e59dc028d42d09db29aa8a0f862cc81', 'hex')
|
||||||
|
|
||||||
it('should work with PBKDF2', function () {
|
it('should work with PBKDF2', function () {
|
||||||
var key = Buffer.from(fixturePrivateKey, 'hex')
|
|
||||||
var wallet = Wallet.fromPrivateKey(key)
|
|
||||||
var w = '{"version":3,"id":"7e59dc02-8d42-409d-b29a-a8a0f862cc81","address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"ciphertext":"01ee7f1a3c8d187ea244c92eea9e332ab0bb2b4c902d89bdd71f80dc384da1be","cipherparams":{"iv":"cecacd85e9cb89788b5aab2f93361233"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6","c":262144,"prf":"hmac-sha256"},"mac":"0c02cd0badfebd5e783e0cf41448f84086a96365fc3456716c33641a86ebc7cc"}}'
|
var w = '{"version":3,"id":"7e59dc02-8d42-409d-b29a-a8a0f862cc81","address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"ciphertext":"01ee7f1a3c8d187ea244c92eea9e332ab0bb2b4c902d89bdd71f80dc384da1be","cipherparams":{"iv":"cecacd85e9cb89788b5aab2f93361233"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6","c":262144,"prf":"hmac-sha256"},"mac":"0c02cd0badfebd5e783e0cf41448f84086a96365fc3456716c33641a86ebc7cc"}}'
|
||||||
// FIXME: just test for ciphertext and mac?
|
// FIXME: just test for ciphertext and mac?
|
||||||
assert.equal(wallet.toV3String('testtest', { kdf: 'pbkdf2', uuid: uuid, salt: salt, iv: iv }), w)
|
assert.equal(fixtureWallet.toV3String('testtest', { kdf: 'pbkdf2', uuid: uuid, salt: salt, iv: iv }), w)
|
||||||
})
|
})
|
||||||
it('should work with Scrypt', function () {
|
it('should work with Scrypt', function () {
|
||||||
var key = Buffer.from(fixturePrivateKey, 'hex')
|
|
||||||
var wallet = Wallet.fromPrivateKey(key)
|
|
||||||
var w = '{"version":3,"id":"7e59dc02-8d42-409d-b29a-a8a0f862cc81","address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"ciphertext":"c52682025b1e5d5c06b816791921dbf439afe7a053abb9fac19f38a57499652c","cipherparams":{"iv":"cecacd85e9cb89788b5aab2f93361233"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6","n":262144,"r":8,"p":1},"mac":"27b98c8676dc6619d077453b38db645a4c7c17a3e686ee5adaf53c11ac1b890e"}}'
|
var w = '{"version":3,"id":"7e59dc02-8d42-409d-b29a-a8a0f862cc81","address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"ciphertext":"c52682025b1e5d5c06b816791921dbf439afe7a053abb9fac19f38a57499652c","cipherparams":{"iv":"cecacd85e9cb89788b5aab2f93361233"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6","n":262144,"r":8,"p":1},"mac":"27b98c8676dc6619d077453b38db645a4c7c17a3e686ee5adaf53c11ac1b890e"}}'
|
||||||
this.timeout(180000) // 3minutes
|
this.timeout(180000) // 3minutes
|
||||||
// FIXME: just test for ciphertext and mac?
|
// FIXME: just test for ciphertext and mac?
|
||||||
assert.equal(wallet.toV3String('testtest', { kdf: 'scrypt', uuid: uuid, salt: salt, iv: iv }), w)
|
assert.equal(fixtureWallet.toV3String('testtest', { kdf: 'scrypt', uuid: uuid, salt: salt, iv: iv }), w)
|
||||||
|
})
|
||||||
|
it('should work without providing options', function() {
|
||||||
|
assert.equal(fixtureWallet.toV3('testtest')['version'], 3)
|
||||||
|
})
|
||||||
|
it('should fail for unsupported kdf', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
fixtureWallet.toV3('testtest', { kdf: 'superkey' })
|
||||||
|
}, /^Error: Unsupported kdf$/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue