integration: use an rng for the example over mocking

This commit is contained in:
Daniel Cousens 2015-03-19 11:15:51 +11:00
parent 689f444bdf
commit b55874718a

View file

@ -3,21 +3,18 @@
var assert = require('assert') var assert = require('assert')
var bigi = require('bigi') var bigi = require('bigi')
var bitcoin = require('../../') var bitcoin = require('../../')
var crypto = require('crypto')
var sinon = require('sinon')
describe('bitcoinjs-lib (basic)', function () { describe('bitcoinjs-lib (basic)', function () {
it('can generate a random bitcoin address', sinon.test(function () { it('can generate a random bitcoin address', function () {
// for testing only // for testing only
this.mock(crypto).expects('randomBytes') function rng () { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz') }
.onCall(0).returns(new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'))
// generate random key // generate random key (custom rng for testing only)
var key = bitcoin.ECKey.makeRandom() var key = bitcoin.ECKey.makeRandom(undefined, rng)
var address = key.pub.getAddress().toString() var address = key.pub.getAddress().toString()
assert.equal(address, '1F5VhMHukdnUES9kfXqzPzMeF1GPHKiF64') assert.equal(address, '1F5VhMHukdnUES9kfXqzPzMeF1GPHKiF64')
})) })
it('can generate an address from a SHA256 hash', function () { it('can generate an address from a SHA256 hash', function () {
var hash = bitcoin.crypto.sha256('correct horse battery staple') var hash = bitcoin.crypto.sha256('correct horse battery staple')