diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-31 23:02:16 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-31 23:02:16 +0800 |
commit | 3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca (patch) | |
tree | 11fc98b4f70b0f5b549cc463bb97f3a15764dae2 /test | |
parent | 2eedc330bfcb976b8eef2b6aee69e19430de1713 (diff) | |
parent | 688030ecb615cbf97c428cf1dd2e337380079168 (diff) | |
download | dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.gz dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.bz2 dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.lz dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.xz dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.tar.zst dexon-3cdf108057a6f0ce83bb3eb9d9b2804ae07956ca.zip |
Merge branch 'develop'
Diffstat (limited to 'test')
-rw-r--r-- | test/event.js | 110 | ||||
-rw-r--r-- | test/utils.filters.js (renamed from test/abi.filters.js) | 8 |
2 files changed, 110 insertions, 8 deletions
diff --git a/test/event.js b/test/event.js index 781f42e5e..9edd93ae7 100644 --- a/test/event.js +++ b/test/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); + + }); + }); diff --git a/test/abi.filters.js b/test/utils.filters.js index 42385fd2a..f2d2788b0 100644 --- a/test/abi.filters.js +++ b/test/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); |