From 65d54896c512fcb0350ee84857b3041840b2c5d1 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 22 Sep 2014 16:48:40 +1000 Subject: [PATCH] tests: add verification of use of crypto.randomBytes --- package.json | 3 ++- test/index.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 94e2685..38c9ebd 100644 --- a/package.json +++ b/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", diff --git a/test/index.js b/test/index.js index 62e8105..aacce2b 100644 --- a/test/index.js +++ b/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(' ')