From 9475733a2d58a3cff250f84ff3f97e519a30417b Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 31 Jan 2015 04:11:09 +0100 Subject: [PATCH 1/2] Squashed 'libjsqrc/ethereumjs/' changes from 600c9dd..0b82a05 0b82a05 events 80c97ca events 2491c99 abi.js cleanup && new types.js, utils.js cf534d4 gulp 5689086 formatters separated 995861d event options git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: 0b82a05a75a0a7592e4fe391120f90d7cee495ac --- event.js | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 4 deletions(-) diff --git a/event.js b/event.js index 781f42e5e..9edd93ae7 100644 --- a/event.js +++ b/event.js @@ -1,22 +1,124 @@ var assert = require('assert'); var event = require('../lib/event.js'); +var f = require('../lib/formatters.js'); describe('event', function () { - it('should create filter input object from given', function () { + it('should create basic filter input object', function () { // given var address = '0x012345'; var signature = '0x987654'; + var e = { + name: 'Event', + inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] + }; // when - var impl = event(address, signature); + var impl = event(address, signature, e); var result = impl(); // then assert.equal(result.address, address); - assert.equal(result.topics.length, 1); - assert.equal(result.topics[0], signature); + assert.equal(result.topic.length, 1); + assert.equal(result.topic[0], signature); }); + + it('should create filter input object with options', function () { + + // given + var address = '0x012345'; + var signature = '0x987654'; + var options = { + earliest: 1, + latest: 2, + offset: 3, + max: 4 + }; + var e = { + name: 'Event', + inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] + }; + + // when + var impl = event(address, signature, e); + var result = impl({}, options); + + // then + assert.equal(result.address, address); + assert.equal(result.topic.length, 1); + assert.equal(result.topic[0], signature); + assert.equal(result.earliest, options.earliest); + assert.equal(result.latest, options.latest); + assert.equal(result.offset, options.offset); + assert.equal(result.max, options.max); + + }); + + it('should create filter input object with indexed params', function () { + + // given + var address = '0x012345'; + var signature = '0x987654'; + var options = { + earliest: 1, + latest: 2, + offset: 3, + max: 4 + }; + var e = { + name: 'Event', + inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] + }; + + // when + var impl = event(address, signature, e); + var result = impl({a: 4}, options); + + // then + assert.equal(result.address, address); + assert.equal(result.topic.length, 2); + assert.equal(result.topic[0], signature); + assert.equal(result.topic[1], f.formatInputInt(4)); + assert.equal(result.earliest, options.earliest); + assert.equal(result.latest, options.latest); + assert.equal(result.offset, options.offset); + assert.equal(result.max, options.max); + + }); + + it('should create filter input object with an array of indexed params', function () { + + // given + var address = '0x012345'; + var signature = '0x987654'; + var options = { + earliest: 1, + latest: 2, + offset: 3, + max: 4 + }; + var e = { + name: 'Event', + inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] + }; + + // when + var impl = event(address, signature, e); + var result = impl({a: [4, 69]}, options); + + // then + assert.equal(result.address, address); + assert.equal(result.topic.length, 2); + assert.equal(result.topic[0], signature); + assert.equal(result.topic[1][0], f.formatInputInt(4)); + assert.equal(result.topic[1][1], f.formatInputInt(69)); + assert.equal(result.earliest, options.earliest); + assert.equal(result.latest, options.latest); + assert.equal(result.offset, options.offset); + assert.equal(result.max, options.max); + + }); + }); From 8cbaec5ce6379a4bfbc550d3b8f5aa4de044eef6 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 31 Jan 2015 15:53:50 +0100 Subject: [PATCH 2/2] Squashed 'libjsqrc/ethereumjs/' changes from a8a2e32..589c4fb 589c4fb formatInput && formatOutput simplified b20e972 few methods moved to utils git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: 589c4fb30f2e68972b898c5ce084cda5b0831266 --- abi.filters.js => utils.filters.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename abi.filters.js => utils.filters.js (84%) diff --git a/abi.filters.js b/utils.filters.js similarity index 84% rename from abi.filters.js rename to utils.filters.js index 42385fd2a..f2d2788b0 100644 --- a/abi.filters.js +++ b/utils.filters.js @@ -1,7 +1,7 @@ var assert = require('assert'); -var abi = require('../lib/abi.js'); +var utils = require('../lib/utils.js'); -describe('abi', function() { +describe('utils', function() { it('should filter functions and events from input array properly', function () { // given @@ -36,8 +36,8 @@ describe('abi', function() { }]; // when - var events = abi.filterEvents(description); - var functions = abi.filterFunctions(description); + var events = utils.filterEvents(description); + var functions = utils.filterFunctions(description); // then assert.equal(events.length, 1);