ECPair: move throwing constructor tests to fixtures
This commit is contained in:
parent
a71ec21405
commit
945276fbef
2 changed files with 24 additions and 28 deletions
|
@ -44,31 +44,6 @@ describe('ECPair', function () {
|
|||
assert.strictEqual(keyPair.network, NETWORKS.testnet)
|
||||
})
|
||||
|
||||
it('throws if compressed option is not a bool', function () {
|
||||
assert.throws(function () {
|
||||
new ECPair(null, null, {
|
||||
compressed: 2
|
||||
}, /Expected Boolean, got 2/)
|
||||
})
|
||||
})
|
||||
|
||||
it('throws if public and private key given', function () {
|
||||
var qBuffer = new Buffer('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', 'hex')
|
||||
var Q = ecurve.Point.decodeFrom(curve, qBuffer)
|
||||
|
||||
assert.throws(function () {
|
||||
new ECPair(BigInteger.ONE, Q)
|
||||
}, /Unexpected publicKey parameter/)
|
||||
})
|
||||
|
||||
it('throws if network is missing pubKeyHash constants', function () {
|
||||
assert.throws(function () {
|
||||
new ECPair(null, null, {
|
||||
network: {}
|
||||
}, /Unknown pubKeyHash constants for network/)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('calculates the public point for ' + f.WIF, function () {
|
||||
var d = new BigInteger(f.d)
|
||||
|
@ -81,11 +56,12 @@ describe('ECPair', function () {
|
|||
})
|
||||
|
||||
fixtures.invalid.constructor.forEach(function (f) {
|
||||
it('throws on ' + f.d, function () {
|
||||
var d = new BigInteger(f.d)
|
||||
it('throws ' + f.exception, function () {
|
||||
var d = f.d && new BigInteger(f.d)
|
||||
var Q = f.Q && ecurve.Point.decodeFrom(curve, new Buffer(f.Q, 'hex'))
|
||||
|
||||
assert.throws(function () {
|
||||
new ECPair(d)
|
||||
new ECPair(d, Q, f.options)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
|
|
20
test/fixtures/ecpair.json
vendored
20
test/fixtures/ecpair.json
vendored
|
@ -82,7 +82,27 @@
|
|||
{
|
||||
"exception": "Private key must be less than the curve order",
|
||||
"d": "115792089237316195423570985008687907853269984665640564039457584007913129639935"
|
||||
},
|
||||
{
|
||||
"exception": "Expected property \"compressed\" of type \\?Boolean, got Number 2",
|
||||
"d": "1",
|
||||
"options": {
|
||||
"compressed": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Unexpected publicKey parameter",
|
||||
"d": "1",
|
||||
"Q": "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
|
||||
},
|
||||
{
|
||||
"exception": "Expected property \"network.messagePrefix\" of type Buffer|String, got undefined",
|
||||
"d": "1",
|
||||
"options": {
|
||||
"network": {}
|
||||
}
|
||||
}
|
||||
|
||||
],
|
||||
"fromWIF": [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue