ECPair/tests: always use WIF for error throwing
This commit is contained in:
parent
54c071c131
commit
9e32c892ef
3 changed files with 9 additions and 3 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
})
|
||||
|
|
5
test/fixtures/ecpair.json
vendored
5
test/fixtures/ecpair.json
vendored
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue