tests: add HDNode fromSeed throwing tests
This commit is contained in:
parent
5c3d3b61e6
commit
888393fa8f
2 changed files with 24 additions and 4 deletions
|
@ -124,6 +124,10 @@ HDNode.fromBase58 = function (string, networks) {
|
||||||
return hd
|
return hd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HDNode.prototype.getAddress = function () {
|
||||||
|
return this.keyPair.getAddress()
|
||||||
|
}
|
||||||
|
|
||||||
HDNode.prototype.getIdentifier = function () {
|
HDNode.prototype.getIdentifier = function () {
|
||||||
return bcrypto.hash160(this.keyPair.getPublicKeyBuffer())
|
return bcrypto.hash160(this.keyPair.getPublicKeyBuffer())
|
||||||
}
|
}
|
||||||
|
@ -132,10 +136,6 @@ HDNode.prototype.getFingerprint = function () {
|
||||||
return this.getIdentifier().slice(0, 4)
|
return this.getIdentifier().slice(0, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
HDNode.prototype.getAddress = function () {
|
|
||||||
return this.keyPair.getAddress()
|
|
||||||
}
|
|
||||||
|
|
||||||
HDNode.prototype.neutered = function () {
|
HDNode.prototype.neutered = function () {
|
||||||
var neuteredKeyPair = new ECPair(null, this.keyPair.Q, {
|
var neuteredKeyPair = new ECPair(null, this.keyPair.Q, {
|
||||||
network: this.keyPair.network
|
network: this.keyPair.network
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
/* eslint-disable no-new */
|
/* eslint-disable no-new */
|
||||||
|
|
||||||
var assert = require('assert')
|
var assert = require('assert')
|
||||||
|
var ecdsa = require('../src/ecdsa')
|
||||||
var sinon = require('sinon')
|
var sinon = require('sinon')
|
||||||
|
|
||||||
var BigInteger = require('bigi')
|
var BigInteger = require('bigi')
|
||||||
|
@ -9,6 +10,7 @@ var ECPair = require('../src/ecpair')
|
||||||
var HDNode = require('../src/hdnode')
|
var HDNode = require('../src/hdnode')
|
||||||
|
|
||||||
var fixtures = require('./fixtures/hdnode.json')
|
var fixtures = require('./fixtures/hdnode.json')
|
||||||
|
var curve = ecdsa.__curve
|
||||||
|
|
||||||
var NETWORKS = require('../src/networks')
|
var NETWORKS = require('../src/networks')
|
||||||
var NETWORKS_LIST = [] // Object.values(NETWORKS)
|
var NETWORKS_LIST = [] // Object.values(NETWORKS)
|
||||||
|
@ -68,6 +70,24 @@ describe('HDNode', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('throws if IL is not within interval [1, n - 1] | IL === 0', sinon.test(function () {
|
||||||
|
this.mock(BigInteger).expects('fromBuffer')
|
||||||
|
.once().returns(BigInteger.ZERO)
|
||||||
|
|
||||||
|
assert.throws(function () {
|
||||||
|
HDNode.fromSeedHex('ffffffffffffffffffffffffffffffff')
|
||||||
|
}, /Private key must be greater than 0/)
|
||||||
|
}))
|
||||||
|
|
||||||
|
it('throws if IL is not within interval [1, n - 1] | IL === n', sinon.test(function () {
|
||||||
|
this.mock(BigInteger).expects('fromBuffer')
|
||||||
|
.once().returns(curve.n)
|
||||||
|
|
||||||
|
assert.throws(function () {
|
||||||
|
HDNode.fromSeedHex('ffffffffffffffffffffffffffffffff')
|
||||||
|
}, /Private key must be less than the curve order/)
|
||||||
|
}))
|
||||||
|
|
||||||
it('throws on low entropy seed', function () {
|
it('throws on low entropy seed', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
HDNode.fromSeedHex('ffffffffff')
|
HDNode.fromSeedHex('ffffffffff')
|
||||||
|
|
Loading…
Add table
Reference in a new issue