diff --git a/lib/abi.js b/lib/abi.js index 93c859a8e95..1ef36ceef5f 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -74,6 +74,8 @@ var formatInput = function (inputs, params) { toAppendArrayContent += params[i].reduce(function (acc, curr) { return acc + formatter(curr); }, ""); + else if (inputs[i].type === 'string') + toAppendArrayContent += formatter(params[i]); else toAppendConstant += formatter(params[i]); }); diff --git a/test/abi.inputParser.js b/test/abi.inputParser.js index 26e61c221b9..edfc2b58f31 100644 --- a/test/abi.inputParser.js +++ b/test/abi.inputParser.js @@ -309,7 +309,8 @@ describe('abi', function() { // then assert.equal( parser.test('hello'), - "000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000005" + + "68656c6c6f000000000000000000000000000000000000000000000000000000" ); assert.equal( parser.test('world'), @@ -317,6 +318,50 @@ describe('abi', function() { ); }); + it('should parse input int followed by a string', function () { + + // given + var d = clone(description); + + d[0].inputs = [ + { type: "int" }, + { type: "string" } + ]; + + // when + var parser = abi.inputParser(d); + + // then + assert.equal( + parser.test(9, 'hello'), + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000009" + + "68656c6c6f000000000000000000000000000000000000000000000000000000" + ); + }); + + it('should parse input string followed by an int', function () { + + // given + var d = clone(description); + + d[0].inputs = [ + { type: "string" }, + { type: "int" } + ]; + + // when + var parser = abi.inputParser(d); + + // then + assert.equal( + parser.test('hello', 9), + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000009" + + "68656c6c6f000000000000000000000000000000000000000000000000000000" + ); + }); + it('should use proper method name', function () { // given