Browse Source

tests: add verification of use of crypto.randomBytes

300
Daniel Cousens 10 years ago
parent
commit
65d54896c5
  1. 3
      package.json
  2. 14
      test/index.js

3
package.json

@ -21,7 +21,8 @@
},
"license": "ISC",
"dependencies": {
"crypto-js": "^3.1.2-2"
"crypto-js": "^3.1.2-2",
"sinon": "^1.10.3"
},
"devDependencies": {
"browserify": "^5.9.1",

14
test/index.js

@ -1,5 +1,7 @@
var assert = require('assert')
var crypto = require('crypto')
var BIP39 = require('../index.js')
var sinon = require('sinon')
var wordlists = {
english: require('../wordlists/en.json'),
@ -48,7 +50,17 @@ describe('BIP39', function() {
})
describe('generateMnemonic', function() {
it('generates a mnemonic', function() {
vectors.english.forEach(function(v, i) {
it('works for tests vector ' + i, sinon.test(function() {
this.mock(crypto).expects('randomBytes')
.exactly(1)
.onCall(0).returns(new Buffer(v[0], 'hex'))
assert.equal(BIP39.generateMnemonic(), v[1])
}))
})
it('can vary generated entropy bit length', function() {
var mnemonic = BIP39.generateMnemonic(96)
var words = mnemonic.split(' ')

Loading…
Cancel
Save