Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for isHex and isHexStrict. #3622

Merged
merged 4 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/utils.isHex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var chai = require('chai');
var utils = require('../packages/web3-utils');

var BigNumber = require('bignumber.js');
var BN = require('bn.js');

var assert = chai.assert;

var tests = [
{ value: 1, expected: true },
{ value: '1', expected: true },
{ value: '0xH', expected: false},
{ value: 'H', expected: false},
{ value: [1,2,3,{test: 'data'}], expected: false},
{ value: {test: 'test'}, expected: false},
{ value: '{"test": "test"}', expected: false},
{ value: 'myString', expected: false},
{ value: 'myString 34534!', expected: false},
{ value: new BN(15), expected: false},
{ value: new BigNumber(15), expected: false},
{ value: 'Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/', expected: false},
{ value: true, expected: false},
{ value: false, expected: false}
];

describe('lib/utils/utils', function () {
describe('isHex', function () {
tests.forEach(function (test) {
it('should return ' + test.expected + ' for input ' + test.value, function () {
assert.strictEqual(utils.isHex(test.value), test.expected);
});
});
});
});
34 changes: 34 additions & 0 deletions test/utils.isHexStrict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var chai = require('chai');
var utils = require('../packages/web3-utils');

var BigNumber = require('bignumber.js');
var BN = require('bn.js');

var assert = chai.assert;

var tests = [
{ value: 0x1, expected: false }, //0x1 would be tested as 1
{ value: '0x1', expected: true },
{ value: '0xH', expected: false},
{ value: 'H', expected: false},
{ value: [1,2,3,{test: 'data'}], expected: false},
{ value: {test: 'test'}, expected: false},
{ value: '{"test": "test"}', expected: false},
{ value: 'myString', expected: false},
{ value: 'myString 34534!', expected: false},
{ value: new BN(15), expected: false},
{ value: new BigNumber(15), expected: false},
{ value: 'Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/', expected: false},
{ value: true, expected: false},
{ value: false, expected: false}
];

describe('lib/utils/utils', function () {
describe('isHexStrict', function () {
tests.forEach(function (test) {
it('should return ' + test.expected + ' for input ' + test.value, function () {
assert.strictEqual(utils.isHexStrict(test.value), test.expected);
});
});
});
});