tests: add loop test at 1, and n-1

This commit is contained in:
Daniel Cousens 2016-12-14 09:42:21 +11:00 committed by Daniel Cousens
parent c81f561f3e
commit 0ae7977574

View file

@ -165,12 +165,21 @@ describe('ECPair', function () {
assert.strictEqual(keyPair.network, NETWORKS.testnet)
})
it('loops until d is within interval [1, n - 1]', sinon.test(function () {
it('loops until d is within interval [1, n - 1] : 1', sinon.test(function () {
var rng = this.mock()
rng.exactly(2)
rng.onCall(0).returns(BigInteger.ZERO.toBuffer(32)) // invalid length
rng.onCall(1).returns(BigInteger.ONE.toBuffer(32)) // === 1
ECPair.makeRandom({ rng: rng })
}))
it('loops until d is within interval [1, n - 1] : n - 1', sinon.test(function () {
var rng = this.mock()
rng.exactly(3)
rng.onCall(0).returns(new BigInteger('0').toBuffer(32)) // < 1
rng.onCall(0).returns(BigInteger.ZERO.toBuffer(32)) // < 1
rng.onCall(1).returns(curve.n.toBuffer(32)) // > n-1
rng.onCall(2).returns(new BigInteger('42').toBuffer(32)) // valid
rng.onCall(2).returns(curve.n.subtract(BigInteger.ONE).toBuffer(32)) // === n-1
ECPair.makeRandom({ rng: rng })
}))