diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-02-03 22:08:19 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-02-03 22:08:19 +0800 |
commit | 03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965 (patch) | |
tree | dbfe40179e9e24006d37be201bd0b7e67f75f157 /test/event.outputParser.js | |
parent | 9d9c23e315a124c9fa5fa929d00c18791cfdb4e6 (diff) | |
download | dexon-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar dexon-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.gz dexon-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.bz2 dexon-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.lz dexon-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.xz dexon-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.tar.zst dexon-03faec9d41d631f9a4cc6bbe1e91e7cd1cf7b965.zip |
event outputParser && tests
Diffstat (limited to 'test/event.outputParser.js')
-rw-r--r-- | test/event.outputParser.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/test/event.outputParser.js b/test/event.outputParser.js new file mode 100644 index 000000000..22f4ed395 --- /dev/null +++ b/test/event.outputParser.js @@ -0,0 +1,81 @@ +var assert = require('assert'); +var event = require('../lib/event.js'); + +describe('event', function () { + describe('outputParser', function () { + it('should parse basic event output object', function () { + + // given + var output = { + "address":"0x78dfc5983baecf65f73e3de3a96cee24e6b7981e", + "data":"0x000000000000000000000000000000000000000000000000000000000000004b", + "number":2, + "topic":[ + "0x6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad", + "0x0000000000000000000000000000000000000000000000000000000000000001" + ] + }; + + var e = { + name: 'Event', + inputs: [{"name":"a","type":"bool","indexed":true},{"name":"b","type":"uint256","indexed":false}] + }; + + // when + var impl = event.outputParser(e); + var result = impl(output); + + // then + assert.equal(result.event, 'Event'); + assert.equal(result.number, 2); + assert.equal(Object.keys(result.args).length, 2); + assert.equal(result.args.a, true); + assert.equal(result.args.b, 75); + }); + + it('should parse event output object arguments in correct order', function () { + + // given + var output = { + "address":"0x78dfc5983baecf65f73e3de3a96cee24e6b7981e", + "data": "0x" + + "000000000000000000000000000000000000000000000000000000000000004b" + + "000000000000000000000000000000000000000000000000000000000000004c" + + "0000000000000000000000000000000000000000000000000000000000000001", + "number":3, + "topic":[ + "0x6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad", + "0x0000000000000000000000000000000000000000000000000000000000000001", + "0x0000000000000000000000000000000000000000000000000000000000000005" + ] + }; + + var e = { + name: 'Event2', + inputs: [ + {"name":"a","type":"bool","indexed":true}, + {"name":"b","type":"int","indexed":false}, + {"name":"c","type":"int","indexed":false}, + {"name":"d","type":"int","indexed":true}, + {"name":"e","type":"bool","indexed":false} + ] + }; + + // when + var impl = event.outputParser(e); + var result = impl(output); + + // then + assert.equal(result.event, 'Event2'); + assert.equal(result.number, 3); + assert.equal(Object.keys(result.args).length, 5); + assert.equal(result.args.a, true); + assert.equal(result.args.b, 75); + assert.equal(result.args.c, 76); + assert.equal(result.args.d, 5); + assert.equal(result.args.e, true); + + }); + }); +}); + |