crypto: fix test randomBytes stub
This commit is contained in:
parent
b5c42303ff
commit
64e206ca7a
2 changed files with 14 additions and 20 deletions
|
@ -61,6 +61,7 @@
|
||||||
"coveralls": "^2.11.2",
|
"coveralls": "^2.11.2",
|
||||||
"istanbul": "^0.3.5",
|
"istanbul": "^0.3.5",
|
||||||
"mocha": "^2.2.0",
|
"mocha": "^2.2.0",
|
||||||
|
"proxyquire": "^1.4.0",
|
||||||
"sinon": "^1.12.2",
|
"sinon": "^1.12.2",
|
||||||
"standard": "^2.11.0"
|
"standard": "^2.11.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
/* eslint-disable no-new */
|
/* eslint-disable no-new */
|
||||||
|
|
||||||
var assert = require('assert')
|
var assert = require('assert')
|
||||||
var crypto = require('crypto')
|
|
||||||
var ecurve = require('ecurve')
|
var ecurve = require('ecurve')
|
||||||
var networks = require('../src/networks')
|
var networks = require('../src/networks')
|
||||||
var sinon = require('sinon')
|
var proxyquire = require('proxyquire')
|
||||||
|
var randomBytes = require('randombytes')
|
||||||
|
|
||||||
var BigInteger = require('bigi')
|
var BigInteger = require('bigi')
|
||||||
var ECKey = require('../src/eckey')
|
var ECKey = require('../src/eckey')
|
||||||
|
@ -101,25 +101,13 @@ describe('ECKey', function () {
|
||||||
var exPrivKey = ECKey.fromWIF(exWIF)
|
var exPrivKey = ECKey.fromWIF(exWIF)
|
||||||
var exBuffer = exPrivKey.d.toBuffer(32)
|
var exBuffer = exPrivKey.d.toBuffer(32)
|
||||||
|
|
||||||
describe('uses default crypto RNG', function () {
|
it("uses the RNG provided by the 'randombytes' module by default", function () {
|
||||||
beforeEach(function () {
|
var stub = { randombytes: function() { return exBuffer } }
|
||||||
sinon.stub(crypto, 'randomBytes').returns(exBuffer)
|
var ProxiedECKey = proxyquire('../src/eckey', stub)
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function () {
|
var privKey = ProxiedECKey.makeRandom()
|
||||||
crypto.randomBytes.restore()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('generates a ECKey', function () {
|
assert.equal(privKey.toWIF(), exWIF)
|
||||||
var privKey = ECKey.makeRandom()
|
|
||||||
|
|
||||||
assert.equal(privKey.toWIF(), exWIF)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('supports compression', function () {
|
|
||||||
assert.equal(ECKey.makeRandom(true).pub.compressed, true)
|
|
||||||
assert.equal(ECKey.makeRandom(false).pub.compressed, false)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('allows a custom RNG to be used', function () {
|
it('allows a custom RNG to be used', function () {
|
||||||
|
@ -130,10 +118,15 @@ describe('ECKey', function () {
|
||||||
var privKey = ECKey.makeRandom(undefined, rng)
|
var privKey = ECKey.makeRandom(undefined, rng)
|
||||||
assert.equal(privKey.toWIF(), exWIF)
|
assert.equal(privKey.toWIF(), exWIF)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('supports compression', function () {
|
||||||
|
assert.equal(ECKey.makeRandom(true).pub.compressed, true)
|
||||||
|
assert.equal(ECKey.makeRandom(false).pub.compressed, false)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('signing', function () {
|
describe('signing', function () {
|
||||||
var hash = crypto.randomBytes(32)
|
var hash = randomBytes(32)
|
||||||
var priv = ECKey.makeRandom()
|
var priv = ECKey.makeRandom()
|
||||||
var signature = priv.sign(hash)
|
var signature = priv.sign(hash)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue