aboutsummaryrefslogtreecommitdiffstats
path: root/coder.decodeParam.js
diff options
context:
space:
mode:
Diffstat (limited to 'coder.decodeParam.js')
-rw-r--r--coder.decodeParam.js69
1 files changed, 57 insertions, 12 deletions
diff --git a/coder.decodeParam.js b/coder.decodeParam.js
index 0a67bda0..3eea9dd6 100644
--- a/coder.decodeParam.js
+++ b/coder.decodeParam.js
@@ -1,23 +1,68 @@
var chai = require('chai');
var assert = chai.assert;
var coder = require('../lib/solidity/coder');
+var BigNumber = require('bignumber.js');
+var bn = BigNumber;
-var tests = [
- { type: 'int', value: '0000000000000000000000000000000000000000000000000000000000000001', expected: 1},
- { type: 'int', value: '0000000000000000000000000000000000000000000000000000000000000010', expected: 16},
- { type: 'int', value: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: -1},
- { type: 'bytes32', value: '6761766f66796f726b0000000000000000000000000000000000000000000000', expected: 'gavofyork'},
- { type: 'bytes', value: '0000000000000000000000000000000000000000000000000000000000000009' +
- '6761766f66796f726b0000000000000000000000000000000000000000000000', expected: 'gavofyork'}
-];
describe('lib/solidity/coder', function () {
describe('decodeParam', function () {
- tests.forEach(function (test) {
- it('should turn ' + test.value + ' to ' + test.expected, function () {
- assert.equal(coder.decodeParam(test.type, test.value), test.expected);
+ var test = function (t) {
+ it('should turn ' + t.value + ' to ' + t.expected, function () {
+ assert.deepEqual(coder.decodeParam(t.type, t.value), t.expected);
});
- });
+ };
+
+
+ test({ type: 'int', expected: new bn(1), value: '0000000000000000000000000000000000000000000000000000000000000001'});
+ test({ type: 'int', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
+ test({ type: 'int', expected: new bn(-1), value: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
+ test({ type: 'int256', expected: new bn(1), value: '0000000000000000000000000000000000000000000000000000000000000001'});
+ test({ type: 'int256', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
+ test({ type: 'int256', expected: new bn(-1), value: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
+ test({ type: 'bytes32', expected: 'gavofyork', value: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ type: 'bytes', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000009' +
+ '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ type: 'int[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000003'});
+ test({ type: 'int256[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000003'});
+ test({ type: 'int[]', expected: [new bn(1), new bn(2), new bn(3)],
+ value: '0000000000000000000000000000000000000000000000000000000000000003' +
+ '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000002' +
+ '0000000000000000000000000000000000000000000000000000000000000003'});
+ });
+});
+
+describe('lib/solidity/coder', function () {
+ describe('decodeParams', function () {
+ var test = function (t) {
+ it('should turn ' + t.values + ' to ' + t.expected, function () {
+ assert.deepEqual(coder.decodeParams(t.types, t.values), t.expected);
+ });
+ };
+
+
+ test({ types: ['int'], expected: [new bn(1)], values: '0000000000000000000000000000000000000000000000000000000000000001'});
+ test({ types: ['bytes32', 'int'], expected: ['gavofyork', new bn(5)],
+ values: '6761766f66796f726b0000000000000000000000000000000000000000000000' +
+ '0000000000000000000000000000000000000000000000000000000000000005'});
+ test({ types: ['int', 'bytes32'], expected: [new bn(5), 'gavofyork'],
+ values: '0000000000000000000000000000000000000000000000000000000000000005' +
+ '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ types: ['int', 'bytes', 'int', 'int', 'int', 'int[]'], expected: [new bn(1), 'gavofyork', new bn(2), new bn(3), new bn(4),
+ [new bn(5), new bn(6), new bn(7)]],
+ values: '0000000000000000000000000000000000000000000000000000000000000009' +
+ '0000000000000000000000000000000000000000000000000000000000000003' +
+ '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000002' +
+ '0000000000000000000000000000000000000000000000000000000000000003' +
+ '0000000000000000000000000000000000000000000000000000000000000004' +
+ '6761766f66796f726b0000000000000000000000000000000000000000000000' +
+ '0000000000000000000000000000000000000000000000000000000000000005' +
+ '0000000000000000000000000000000000000000000000000000000000000006' +
+ '0000000000000000000000000000000000000000000000000000000000000007'});
});
});