From 0ae7977574582ab5fff8e4297bfceaf7d9208824 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 14 Dec 2016 09:42:21 +1100 Subject: [PATCH] tests: add loop test at 1, and n-1 --- test/ecpair.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/ecpair.js b/test/ecpair.js index 0e9a3a1..127aa02 100644 --- a/test/ecpair.js +++ b/test/ecpair.js @@ -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 }) }))