Skip to content

Commit

Permalink
Merge pull request #85 from ethers/abiString
Browse files Browse the repository at this point in the history
constants should be before (dynamic) string contents, fix #84
  • Loading branch information
debris committed Mar 3, 2015
1 parent 0dd6cc4 commit a59f3a4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
Expand Down
47 changes: 46 additions & 1 deletion test/abi.inputParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,59 @@ describe('abi', function() {
// then
assert.equal(
parser.test('hello'),
"000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000005" +
"68656c6c6f000000000000000000000000000000000000000000000000000000"
);
assert.equal(
parser.test('world'),
"0000000000000000000000000000000000000000000000000000000000000005776f726c64000000000000000000000000000000000000000000000000000000"
);
});

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
Expand Down

0 comments on commit a59f3a4

Please sign in to comment.