ECPair/tests: always use WIF for error throwing

This commit is contained in:
Daniel Cousens 2016-02-25 13:26:05 +11:00
parent 54c071c131
commit 9e32c892ef
3 changed files with 9 additions and 3 deletions

View file

@ -58,7 +58,6 @@ ECPair.fromPublicKeyBuffer = function (buffer, network) {
}
ECPair.fromWIF = function (string, network) {
network = network || NETWORKS.bitcoin
var buffer = bs58check.decode(string)
if (types.Array(network)) {
@ -67,9 +66,9 @@ ECPair.fromWIF = function (string, network) {
network = network.filter(function (network) {
return version === network.wif
}).pop()
if (!network) throw new Error('Invalid network version')
}
network = network || NETWORKS.bitcoin
var decoded = wif.decodeRaw(buffer, network.wif)
var d = BigInteger.fromBuffer(decoded.privateKey)

View file

@ -107,7 +107,9 @@ describe('ECPair', function () {
fixtures.invalid.fromWIF.forEach(function (f) {
it('throws on ' + f.WIF, function () {
assert.throws(function () {
ECPair.fromWIF(f.WIF)
var networks = f.network ? NETWORKS[f.network] : NETWORKS_LIST
ECPair.fromWIF(f.WIF, networks)
}, new RegExp(f.exception))
})
})

View file

@ -107,8 +107,13 @@
"fromWIF": [
{
"exception": "Invalid network version",
"network": "bitcoin",
"WIF": "92Qba5hnyWSn5Ffcka56yMQauaWY6ZLd91Vzxbi4a9CCetaHtYj"
},
{
"exception": "Invalid network version",
"WIF": "brQnSed3Fia1w9VcbbS6ZGDgJ6ENkgwuQY2LS7pEC5bKHD1fMF"
},
{
"exception": "Invalid compression flag",
"WIF": "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sfZr2ym"