Files
web3.js/test/eth.abi.encodeFunctionCall.js

53 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2017-03-27 14:04:05 +02:00
var chai = require('chai');
var assert = chai.assert;
2018-08-07 14:52:05 +02:00
var Abi = require('../packages/web3-eth-abi');
2017-03-27 14:04:05 +02:00
var tests = [{
params: [{
name: 'myMethod',
type: 'function',
inputs: [{
type: 'uint256',
name: 'myNumber'
},{
type: 'string',
name: 'myString'
}]
}, ['2345675643', 'Hello!%']],
result: '0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000'
},{
params: [{
name: 'myOtherMethod',
type: 'function',
inputs: [{
2018-08-07 14:52:05 +02:00
type: 'uint16',
2017-03-27 14:04:05 +02:00
name: 'myNumberdd'
},{
type: 'bytes32',
name: 'myBytes'
}]
}, [2323, '0x234567432145678543213456']],
2018-08-07 14:52:05 +02:00
result: '0xed6d6f8500000000000000000000000000000000000000000000000000000000000009132345674321456785432134560000000000000000000000000000000000000000'
2017-03-27 14:04:05 +02:00
},{
params: [{
name: 'myMethod',
type: 'function',
inputs: [{
2018-08-07 14:52:05 +02:00
type: 'uint256',
2017-03-27 14:04:05 +02:00
name: 'myNumber'
},{
type: 'bytes',
name: 'myBytes'
}]
}, ['2345675643', '0x23456743214567854321ffffdddddd']],
2018-08-07 14:52:05 +02:00
result: '0x4c6a9980000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000f23456743214567854321ffffdddddd0000000000000000000000000000000000'
2017-03-27 14:04:05 +02:00
}];
describe('encodeFunctionCall', function () {
tests.forEach(function (test) {
it('should convert correctly', function () {
2018-08-07 14:52:05 +02:00
assert.equal(Abi.encodeFunctionCall.apply(Abi, test.params), test.result);
2017-03-27 14:04:05 +02:00
});
});
});