2015-03-08 07:48:45 +00:00
|
|
|
var chai = require('chai');
|
2015-03-08 17:18:52 +00:00
|
|
|
var utils = require('../lib/utils/utils');
|
2015-03-09 14:09:21 +00:00
|
|
|
var BigNumber = require('bignumber.js');
|
2015-03-08 07:48:45 +00:00
|
|
|
var assert = chai.assert;
|
|
|
|
|
|
|
|
var tests = [
|
|
|
|
{ value: 1, expected: '0x1' },
|
|
|
|
{ value: '1', expected: '0x1' },
|
|
|
|
{ value: '0x1', expected: '0x1'},
|
|
|
|
{ value: '15', expected: '0xf'},
|
|
|
|
{ value: '0xf', expected: '0xf'},
|
|
|
|
{ value: -1, expected: '-0x1'},
|
|
|
|
{ value: '-1', expected: '-0x1'},
|
|
|
|
{ value: '-0x1', expected: '-0x1'},
|
|
|
|
{ value: '-15', expected: '-0xf'},
|
|
|
|
{ value: '-0xf', expected: '-0xf'},
|
|
|
|
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},
|
|
|
|
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'},
|
|
|
|
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},
|
|
|
|
{ value: 0, expected: '0x0'},
|
|
|
|
{ value: '0', expected: '0x0'},
|
|
|
|
{ value: '0x0', expected: '0x0'},
|
|
|
|
{ value: -0, expected: '0x0'},
|
|
|
|
{ value: '-0', expected: '0x0'},
|
2015-03-09 14:09:21 +00:00
|
|
|
{ value: '-0x0', expected: '0x0'},
|
|
|
|
{ value: [1,2,3,{test: 'data'}], expected: '0x5b312c322c332c7b2274657374223a2264617461227d5d'},
|
|
|
|
{ value: {test: 'test'}, expected: '0x7b2274657374223a2274657374227d'},
|
|
|
|
{ value: '{"test": "test"}', expected: '0x7b2274657374223a202274657374227d'},
|
|
|
|
{ value: 'myString', expected: '0x6d79537472696e67'},
|
2015-03-23 14:19:42 +00:00
|
|
|
{ value: new BigNumber(15), expected: '0xf'},
|
|
|
|
{ value: true, expected: '0x1'},
|
|
|
|
{ value: false, expected: '0x0'}
|
2015-03-08 07:48:45 +00:00
|
|
|
];
|
2015-02-27 11:41:07 +00:00
|
|
|
|
2015-03-25 21:17:35 +00:00
|
|
|
describe('lib/utils/utils', function () {
|
2015-02-27 11:41:07 +00:00
|
|
|
describe('toHex', function () {
|
2015-03-08 07:48:45 +00:00
|
|
|
tests.forEach(function (test) {
|
|
|
|
it('should turn ' + test.value + ' to ' + test.expected, function () {
|
2015-03-23 14:19:42 +00:00
|
|
|
assert.strictEqual(utils.toHex(test.value), test.expected);
|
2015-03-08 07:48:45 +00:00
|
|
|
});
|
2015-02-27 11:41:07 +00:00
|
|
|
});
|
|
|
|
});
|
2015-03-07 18:18:22 +00:00
|
|
|
});
|
2015-03-08 07:48:45 +00:00
|
|
|
|