aboutsummaryrefslogtreecommitdiffstats
path: root/coder.decodeParam.js
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-04-26 23:40:35 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-04-26 23:40:35 +0800
commit572d268f2860773562ce83719432c05af47c7528 (patch)
tree96592d36bb234352867b35e5edb5d025cb7f9dc9 /coder.decodeParam.js
parent1a137629e31ac63d44fcdd72ddf454b1ce692354 (diff)
downloaddexon-solidity-572d268f2860773562ce83719432c05af47c7528.tar
dexon-solidity-572d268f2860773562ce83719432c05af47c7528.tar.gz
dexon-solidity-572d268f2860773562ce83719432c05af47c7528.tar.bz2
dexon-solidity-572d268f2860773562ce83719432c05af47c7528.tar.lz
dexon-solidity-572d268f2860773562ce83719432c05af47c7528.tar.xz
dexon-solidity-572d268f2860773562ce83719432c05af47c7528.tar.zst
dexon-solidity-572d268f2860773562ce83719432c05af47c7528.zip
Squashed 'libjsqrc/ethereumjs/' changes from c74c854..3b799d1
3b799d1 fixed typos c5f6379 version 0.3.3 d795d36 fixed trimming call output prefix a2f561f fixed calling contract only with array param 4912ec6 tests for decoding solidity params 2b4fd21 solidity param encoding tests git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: 3b799d128452639463424c657956ee90a28daec6
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'});
});
});