Skip to content

Commit 0ae7977

Browse files
committed
tests: add loop test at 1, and n-1
1 parent c81f561 commit 0ae7977

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

test/ecpair.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,21 @@ describe('ECPair', function () {
165165
assert.strictEqual(keyPair.network, NETWORKS.testnet)
166166
})
167167

168-
it('loops until d is within interval [1, n - 1]', sinon.test(function () {
168+
it('loops until d is within interval [1, n - 1] : 1', sinon.test(function () {
169+
var rng = this.mock()
170+
rng.exactly(2)
171+
rng.onCall(0).returns(BigInteger.ZERO.toBuffer(32)) // invalid length
172+
rng.onCall(1).returns(BigInteger.ONE.toBuffer(32)) // === 1
173+
174+
ECPair.makeRandom({ rng: rng })
175+
}))
176+
177+
it('loops until d is within interval [1, n - 1] : n - 1', sinon.test(function () {
169178
var rng = this.mock()
170179
rng.exactly(3)
171-
rng.onCall(0).returns(new BigInteger('0').toBuffer(32)) // < 1
180+
rng.onCall(0).returns(BigInteger.ZERO.toBuffer(32)) // < 1
172181
rng.onCall(1).returns(curve.n.toBuffer(32)) // > n-1
173-
rng.onCall(2).returns(new BigInteger('42').toBuffer(32)) // valid
182+
rng.onCall(2).returns(curve.n.subtract(BigInteger.ONE).toBuffer(32)) // === n-1
174183

175184
ECPair.makeRandom({ rng: rng })
176185
}))

0 commit comments

Comments
 (0)