aboutsummaryrefslogtreecommitdiffstats
path: root/coder.encodeParam.js
blob: 1a4df06bf0480af71c578255844d14b04dc8eed9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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);
            });
        });
    });
});