From 0567ba182654460eb9f6a8918c547488c8d27d8b Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 16 Apr 2015 22:11:15 +0200 Subject: [PATCH] outputParser do not require 0x prefix before hash --- lib/solidity/abi.js | 2 +- lib/solidity/formatters.js | 1 - lib/web3/event.js | 4 +- test/abi.outputParser.js | 96 +++++++++++++++++++------------------- 4 files changed, 51 insertions(+), 52 deletions(-) diff --git a/lib/solidity/abi.js b/lib/solidity/abi.js index 0ae1a62..b81718d 100644 --- a/lib/solidity/abi.js +++ b/lib/solidity/abi.js @@ -51,7 +51,7 @@ var formatInput = function (inputs, params) { * @returns {Array} output params */ var formatOutput = function (outs, bytes) { - var bytes = bytes.slice(2); + //var bytes = bytes.slice(2); var o = outs.map(function (out) { return out.type; diff --git a/lib/solidity/formatters.js b/lib/solidity/formatters.js index a0b7a6a..cdeadbd 100644 --- a/lib/solidity/formatters.js +++ b/lib/solidity/formatters.js @@ -133,7 +133,6 @@ var signedIsNegative = function (value) { * @returns {BigNumber} right-aligned output bytes formatted to big number */ var formatOutputInt = function (param) { - var value = param.value || "0"; // check if it's negative number diff --git a/lib/web3/event.js b/lib/web3/event.js index 9af10ce..5d4fe96 100644 --- a/lib/web3/event.js +++ b/lib/web3/event.js @@ -107,11 +107,11 @@ var outputParser = function (event) { output.data = output.data || ''; var indexedOutputs = filterInputs(event.inputs, true); - var indexedData = "0x" + output.topics.slice(1, output.topics.length).map(function (topics) { return topics.slice(2); }).join(""); + var indexedData = output.topics.slice(1).map(function (topics) { return topics.slice(2); }).join(""); var indexedRes = abi.formatOutput(indexedOutputs, indexedData); var notIndexedOutputs = filterInputs(event.inputs, false); - var notIndexedRes = abi.formatOutput(notIndexedOutputs, output.data); + var notIndexedRes = abi.formatOutput(notIndexedOutputs, output.data.slice(2)); result.args = getArgumentsObject(event.inputs, indexedRes, notIndexedRes); diff --git a/test/abi.outputParser.js b/test/abi.outputParser.js index a57b84a..5fe23e2 100644 --- a/test/abi.outputParser.js +++ b/test/abi.outputParser.js @@ -35,13 +35,13 @@ describe('lib/solidity/abi', function() { // then assert.equal( - parser.test("0x" + + parser.test( "0000000000000000000000000000000000000000000000000000000000000005" + "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], 'hello' ); assert.equal( - parser.test("0x" + + parser.test( "0000000000000000000000000000000000000000000000000000000000000005" + "776f726c64000000000000000000000000000000000000000000000000000000")[0], 'world' @@ -62,14 +62,14 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), + parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) ); assert.equal( - parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), + parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) ); }); @@ -87,14 +87,14 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), + parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) ); assert.equal( - parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), + parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) ); }); @@ -112,14 +112,14 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), + parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) ); assert.equal( - parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), + parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) ); }); @@ -137,10 +137,10 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); + assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); }); it('should parse output int256', function() { @@ -156,10 +156,10 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); + assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); }); it('should parse output int128', function() { @@ -175,10 +175,10 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); + assert.equal(parser.test("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); }); it('should parse output address', function() { @@ -195,7 +195,7 @@ describe('lib/solidity/abi', function() { // then assert.equal( - parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], + parser.test("000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], "0x407d73d8a49eeb85d32cf465507dd71d507100c1" ); }); @@ -213,8 +213,8 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], true); - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000000")[0], false); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], true); + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000000")[0], false); }); @@ -232,10 +232,10 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000100000000000000000000000000000000")[0], 1); - assert.equal(parser.test("0x0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); - assert.equal(parser.test("0x0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffff00000000000000000000000000000000")[0], -1); + assert.equal(parser.test("0000000000000000000000000000000100000000000000000000000000000000")[0], 1); + assert.equal(parser.test("0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); + assert.equal(parser.test("0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); + assert.equal(parser.test("ffffffffffffffffffffffffffffffff00000000000000000000000000000000")[0], -1); }); @@ -252,9 +252,9 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x0000000000000000000000000000000100000000000000000000000000000000")[0], 1); - assert.equal(parser.test("0x0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); - assert.equal(parser.test("0x0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); + assert.equal(parser.test("0000000000000000000000000000000100000000000000000000000000000000")[0], 1); + assert.equal(parser.test("0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); + assert.equal(parser.test("0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); }); @@ -274,7 +274,7 @@ describe('lib/solidity/abi', function() { // then assert.equal( - parser.test("0x" + + parser.test( "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000005" + "68656c6c6f000000000000000000000000000000000000000000000000000000" + @@ -282,7 +282,7 @@ describe('lib/solidity/abi', function() { 'hello' ); assert.equal( - parser.test("0x" + + parser.test( "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000005" + "68656c6c6f000000000000000000000000000000000000000000000000000000" + @@ -305,8 +305,8 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.helloworld("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.helloworld['int']("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.helloworld("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.helloworld['int']("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); }); @@ -330,8 +330,8 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); //then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test2("0x" + + assert.equal(parser.test("00000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test2( "0000000000000000000000000000000000000000000000000000000000000005" + "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], "hello" @@ -351,13 +351,13 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x" + + assert.equal(parser.test( "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000006")[0][0], 5 ); - assert.equal(parser.test("0x" + + assert.equal(parser.test( "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000006")[0][1], @@ -366,7 +366,7 @@ describe('lib/solidity/abi', function() { }); - it('should parse 0x value', function () { + it('should parse 0x0 value', function () { // given var d = clone(description); @@ -378,11 +378,11 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x")[0], 0); + assert.equal(parser.test("0x0")[0], 0); }); - it('should parse 0x value', function () { + it('should parse 0x0 value', function () { // given var d = clone(description); @@ -394,7 +394,7 @@ describe('lib/solidity/abi', function() { var parser = abi.outputParser(d); // then - assert.equal(parser.test("0x")[0], 0); + assert.equal(parser.test("0x0")[0], 0); });