mirror of https://github.com/ethereum/go-ethereum
parent
9d9c23e315
commit
03faec9d41
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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); |
||||
|
||||
}); |
||||
}); |
||||
}); |
||||
|
@ -1,124 +0,0 @@ |
||||
var assert = require('assert'); |
||||
var event = require('../lib/event.js'); |
||||
var f = require('../lib/formatters.js'); |
||||
|
||||
describe('event', 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, 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(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); |
||||
|
||||
}); |
||||
|
||||
}); |
||||
|
@ -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); |
||||
|
||||
}); |
||||
}); |
||||
}); |
||||
|
Loading…
Reference in new issue