aboutsummaryrefslogtreecommitdiffstats
path: root/test/event.inputParser.js
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-02-03 22:08:19 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-02-03 22:08:19 +0800
commit03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965 (patch)
treedbfe40179e9e24006d37be201bd0b7e67f75f157 /test/event.inputParser.js
parent9d9c23e315a124c9fa5fa929d00c18791cfdb4e6 (diff)
downloadgo-tangerine-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar
go-tangerine-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.gz
go-tangerine-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.bz2
go-tangerine-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.lz
go-tangerine-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.xz
go-tangerine-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.zst
go-tangerine-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.zip
event outputParser && tests
Diffstat (limited to 'test/event.inputParser.js')
-rw-r--r--test/event.inputParser.js125
1 files changed, 125 insertions, 0 deletions
diff --git a/test/event.inputParser.js b/test/event.inputParser.js
new file mode 100644
index 000000000..8f9790a2d
--- /dev/null
+++ b/test/event.inputParser.js
@@ -0,0 +1,125 @@
+var assert = require('assert');
+var event = require('../lib/event.js');
+var f = require('../lib/formatters.js');
+
+describe('event', function () {
+ describe('inputParser', 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.inputParser(address, signature, e);
+ var result = impl();
+
+ // then
+ assert.equal(result.address, address);
+ 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.inputParser(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.inputParser(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.inputParser(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);
+
+ });
+ });
+});
+