Browse Source

integration: use an rng for the example over mocking

hk-custom-address
Daniel Cousens 10 years ago
parent
commit
b55874718a
  1. 13
      test/integration/basic.js

13
test/integration/basic.js

@ -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')

Loading…
Cancel
Save