2015-01-29 14:26:42 +00:00
|
|
|
var assert = require('assert');
|
2015-01-31 14:53:50 +00:00
|
|
|
var utils = require('../lib/utils.js');
|
2015-01-29 14:26:42 +00:00
|
|
|
|
2015-01-31 14:53:50 +00:00
|
|
|
describe('utils', function() {
|
2015-01-29 14:26:42 +00:00
|
|
|
it('should filter functions and events from input array properly', function () {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var description = [{
|
|
|
|
"name": "test",
|
|
|
|
"type": "function",
|
|
|
|
"inputs": [{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "d",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}, {
|
|
|
|
"name": "test2",
|
|
|
|
"type": "event",
|
|
|
|
"inputs": [{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "d",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}];
|
|
|
|
|
|
|
|
// when
|
2015-01-31 14:53:50 +00:00
|
|
|
var events = utils.filterEvents(description);
|
|
|
|
var functions = utils.filterFunctions(description);
|
2015-01-29 14:26:42 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
assert.equal(events.length, 1);
|
|
|
|
assert.equal(events[0].name, 'test2');
|
|
|
|
assert.equal(functions.length, 1);
|
|
|
|
assert.equal(functions[0].name, 'test');
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|