Skip to content

Commit ea5ade0

Browse files
committed
Migrated from nodeunit to mocha.
1 parent 0eb7087 commit ea5ade0

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

test/test-scrypt.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
var nodeunit = require('nodeunit');
1+
"use strict";
22

3-
var scrypt = require('../scrypt.js');
3+
const assert = require("assert");
44

5-
var testVectors = require('./test-vectors.json');
5+
const scrypt = require('../scrypt.js');
66

7-
function makeTest(options) {
8-
var password = new Buffer(options.password, 'hex');
9-
var salt = new Buffer(options.salt, 'hex');
10-
var N = options.N;
11-
var p = options.p;
12-
var r = options.r;
13-
var dkLen = options.dkLen;
7+
const testVectors = require('./test-vectors.json');
148

15-
var derivedKeyHex = options.derivedKey;
9+
for (let i = 0; i < testVectors.length; i++) {
10+
const test = testVectors[i];
1611

17-
return function (test) {
12+
const password = new Buffer(test.password, 'hex');
13+
const salt = new Buffer(test.salt, 'hex');
14+
const N = test.N;
15+
const p = test.p;
16+
const r = test.r;
17+
const dkLen = test.dkLen;
18+
19+
const derivedKeyHex = test.derivedKey;
20+
21+
it("Test async " + String(i), function() {
22+
this.timeout(60000);
23+
24+
return new Promise(function(resolve, reject) {
1825
scrypt(password, salt, N, r, p, dkLen, function(error, progress, key) {
1926
if (error) {
2027
console.log(error);
28+
assert.ok(false);
29+
reject(error);
2130

2231
} else if (key) {
23-
key = new Buffer(key);
24-
test.equal(derivedKeyHex, key.toString('hex'), 'failed to generate correct derived key');
25-
test.done();
32+
assert.equal(derivedKeyHex, Buffer.from(key).toString('hex'), 'failed to match derived key');
33+
resolve();
2634
} else {
2735
}
2836
});
29-
}
37+
});
38+
});
3039
}
3140

32-
var Tests = {scrypt: {}};
33-
for (var i = 0; i < testVectors.length; i++) {
34-
var test = testVectors[i];
35-
Tests.scrypt['test-' + Object.keys(Tests.scrypt).length] = makeTest(test);
36-
}
37-
38-
39-
nodeunit.reporters.default.run(Tests);

0 commit comments

Comments
 (0)