From 4b9bc177f716bdd208438b0833a9eec7b7b7e4dd Mon Sep 17 00:00:00 2001 From: ethers Date: Fri, 27 Feb 2015 14:41:52 -0800 Subject: [PATCH] constants should be before (dynamic) string contents --- lib/abi.js | 2 ++ test/abi.inputParser.js | 47 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/abi.js b/lib/abi.js index e645351..917e94e 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -75,6 +75,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 26e61c2..edfc2b5 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