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",
|
||||
"istanbul": "^0.3.5",
|
||||
"mocha": "^2.2.0",
|
||||
"proxyquire": "^1.4.0",
|
||||
"sinon": "^1.12.2",
|
||||
"standard": "^2.11.0"
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
/* eslint-disable no-new */
|
||||
|
||||
var assert = require('assert')
|
||||
var crypto = require('crypto')
|
||||
var ecurve = require('ecurve')
|
||||
var networks = require('../src/networks')
|
||||
var sinon = require('sinon')
|
||||
var proxyquire = require('proxyquire')
|
||||
var randomBytes = require('randombytes')
|
||||
|
||||
var BigInteger = require('bigi')
|
||||
var ECKey = require('../src/eckey')
|
||||
|
@ -101,25 +101,13 @@ describe('ECKey', function () {
|
|||
var exPrivKey = ECKey.fromWIF(exWIF)
|
||||
var exBuffer = exPrivKey.d.toBuffer(32)
|
||||
|
||||
describe('uses default crypto RNG', function () {
|
||||
beforeEach(function () {
|
||||
sinon.stub(crypto, 'randomBytes').returns(exBuffer)
|
||||
})
|
||||
it("uses the RNG provided by the 'randombytes' module by default", function () {
|
||||
var stub = { randombytes: function() { return exBuffer } }
|
||||
var ProxiedECKey = proxyquire('../src/eckey', stub)
|
||||
|
||||
afterEach(function () {
|
||||
crypto.randomBytes.restore()
|
||||
})
|
||||
var privKey = ProxiedECKey.makeRandom()
|
||||
|
||||
it('generates a ECKey', function () {
|
||||
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)
|
||||
})
|
||||
assert.equal(privKey.toWIF(), exWIF)
|
||||
})
|
||||
|
||||
it('allows a custom RNG to be used', function () {
|
||||
|
@ -130,10 +118,15 @@ describe('ECKey', function () {
|
|||
var privKey = ECKey.makeRandom(undefined, rng)
|
||||
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 () {
|
||||
var hash = crypto.randomBytes(32)
|
||||
var hash = randomBytes(32)
|
||||
var priv = ECKey.makeRandom()
|
||||
var signature = priv.sign(hash)
|
||||
|
||||
|
|
Loading…
Reference in a new issue