tests: add loop test at 1, and n-1
This commit is contained in:
parent
c81f561f3e
commit
0ae7977574
1 changed files with 12 additions and 3 deletions
|
@ -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 })
|
||||
}))
|
||||
|
|
Loading…
Reference in a new issue