aboutsummaryrefslogtreecommitdiffstats
path: root/coder.encodeParam.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.encodeParam.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.encodeParam.js')
-rw-r--r--coder.encodeParam.js92
1 files changed, 80 insertions, 12 deletions
diff --git a/coder.encodeParam.js b/coder.encodeParam.js
index 1a4df06b..a9e11ab9 100644
--- a/coder.encodeParam.js
+++ b/coder.encodeParam.js
@@ -2,22 +2,90 @@ var chai = require('chai');
var assert = chai.assert;
var coder = require('../lib/solidity/coder');
-var tests = [
- { type: 'int', value: 1, expected: '0000000000000000000000000000000000000000000000000000000000000001'},
- { type: 'int', value: 16, expected: '0000000000000000000000000000000000000000000000000000000000000010'},
- { type: 'int', value: -1, expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'},
- { type: 'bytes32', value: 'gavofyork', expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'},
- { type: 'bytes', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000009' +
- '6761766f66796f726b0000000000000000000000000000000000000000000000'}
-];
describe('lib/solidity/coder', function () {
describe('encodeParam', function () {
- tests.forEach(function (test) {
- it('should turn ' + test.value + ' to ' + test.expected, function () {
- assert.equal(coder.encodeParam(test.type, test.value), test.expected);
+ var test = function (t) {
+ it('should turn ' + t.value + ' to ' + t.expected, function () {
+ assert.equal(coder.encodeParam(t.type, t.value), t.expected);
});
- });
+ };
+
+
+ test({ type: 'int', value: 1, expected: '0000000000000000000000000000000000000000000000000000000000000001'});
+ test({ type: 'int', value: 16, expected: '0000000000000000000000000000000000000000000000000000000000000010'});
+ test({ type: 'int', value: -1, expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
+ test({ type: 'int256', value: 1, expected: '0000000000000000000000000000000000000000000000000000000000000001'});
+ test({ type: 'int256', value: 16, expected: '0000000000000000000000000000000000000000000000000000000000000010'});
+ test({ type: 'int256', value: -1, expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
+ test({ type: 'bytes32', value: 'gavofyork', expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ type: 'bytes', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000009' +
+ '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ type: 'int[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000003'});
+ test({ type: 'int256[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000003'});
+ test({ type: 'int[]', value: [1,2,3], expected: '0000000000000000000000000000000000000000000000000000000000000003' +
+ '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000002' +
+ '0000000000000000000000000000000000000000000000000000000000000003'});
+ });
+});
+
+
+describe('lib/solidity/coder', function () {
+ describe('encodeParams', function () {
+ var test = function (t) {
+ it('should turn ' + t.values + ' to ' + t.expected, function () {
+ assert.equal(coder.encodeParams(t.types, t.values), t.expected);
+ });
+ };
+
+
+ test({ types: ['int'], values: [1], expected: '0000000000000000000000000000000000000000000000000000000000000001'});
+ test({ types: ['int'], values: [16], expected: '0000000000000000000000000000000000000000000000000000000000000010'});
+ test({ types: ['int'], values: [-1], expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
+ test({ types: ['int256'], values: [1], expected: '0000000000000000000000000000000000000000000000000000000000000001'});
+ test({ types: ['int256'], values: [16], expected: '0000000000000000000000000000000000000000000000000000000000000010'});
+ test({ types: ['int256'], values: [-1], expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
+ test({ types: ['bytes32'], values: ['gavofyork'], expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ types: ['bytes'], values: ['gavofyork'], expected: '0000000000000000000000000000000000000000000000000000000000000009' +
+ '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ types: ['int[]'], values: [[3]], expected: '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000003'});
+ test({ types: ['int256[]'], values: [[3]], expected: '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000003'});
+ test({ types: ['int256[]'], values: [[1,2,3]], expected: '0000000000000000000000000000000000000000000000000000000000000003' +
+ '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000002' +
+ '0000000000000000000000000000000000000000000000000000000000000003'});
+ test({ types: ['bytes32', 'int'], values: ['gavofyork', 5],
+ expected: '6761766f66796f726b0000000000000000000000000000000000000000000000' +
+ '0000000000000000000000000000000000000000000000000000000000000005'});
+ test({ types: ['int', 'bytes32'], values: [5, 'gavofyork'],
+ expected: '0000000000000000000000000000000000000000000000000000000000000005' +
+ '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ types: ['bytes', 'int'], values: ['gavofyork', 5],
+ expected: '0000000000000000000000000000000000000000000000000000000000000009' +
+ '0000000000000000000000000000000000000000000000000000000000000005' +
+ '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ types: ['int', 'bytes'], values: [5, 'gavofyork'],
+ expected: '0000000000000000000000000000000000000000000000000000000000000009' +
+ '0000000000000000000000000000000000000000000000000000000000000005' +
+ '6761766f66796f726b0000000000000000000000000000000000000000000000'});
+ test({ types: ['int', 'bytes', 'int', 'int', 'int', 'int[]'], values: [1, 'gavofyork', 2, 3, 4, [5, 6, 7]],
+ expected: '0000000000000000000000000000000000000000000000000000000000000009' +
+ '0000000000000000000000000000000000000000000000000000000000000003' +
+ '0000000000000000000000000000000000000000000000000000000000000001' +
+ '0000000000000000000000000000000000000000000000000000000000000002' +
+ '0000000000000000000000000000000000000000000000000000000000000003' +
+ '0000000000000000000000000000000000000000000000000000000000000004' +
+ '6761766f66796f726b0000000000000000000000000000000000000000000000' +
+ '0000000000000000000000000000000000000000000000000000000000000005' +
+ '0000000000000000000000000000000000000000000000000000000000000006' +
+ '0000000000000000000000000000000000000000000000000000000000000007'});
+
});
});
+