Skip to content

Commit

Permalink
Add utils.randomHex unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Oct 1, 2019
1 parent 493f664 commit b398764
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/utils.randomHex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var chai = require('chai');
var utils = require('../packages/web3-utils');

var assert = chai.assert;

// Expect 2 chars per bytes plus `0x` prefix
var tests = [
{ value: 0, expected: { prefix: '0x', type: 'string', length: 2 }},
{ value: 15, expected: { prefix: '0x', type: 'string', length: 32 }},
{ value: 16, expected: { prefix: '0x', type: 'string', length: 34 }}
];

describe('lib/utils/utils', function () {
describe('randomHex', function () {
tests.forEach(function (test) {
it('should turn ' + test.value + ' to ' + test.expected, function () {
var result = utils.randomHex(test.value);

assert.strictEqual(typeof result, test.expected.type);
assert.strictEqual(result.slice(0,2), test.expected.prefix);
assert.strictEqual(result.length, test.expected.length);
});
});
});
});

0 comments on commit b398764

Please sign in to comment.