forked from cerc-io/plugeth
tests for abi.filters
This commit is contained in:
parent
ea7c2fc673
commit
2544d2c952
11
lib/abi.js
11
lib/abi.js
@ -73,6 +73,14 @@ var filterFunctions = function (json) {
|
||||
});
|
||||
};
|
||||
|
||||
/// Filters all events form input abi
|
||||
/// @returns abi array with filtered objects of type 'event'
|
||||
var filterEvents = function (json) {
|
||||
return json.filter(function (current) {
|
||||
return current.type === 'event';
|
||||
});
|
||||
};
|
||||
|
||||
/// @param string string to be padded
|
||||
/// @param number of characters that result string should have
|
||||
/// @param sign, by default 0
|
||||
@ -414,6 +422,7 @@ module.exports = {
|
||||
methodDisplayName: methodDisplayName,
|
||||
methodTypeName: methodTypeName,
|
||||
getMethodWithName: getMethodWithName,
|
||||
filterFunctions: filterFunctions
|
||||
filterFunctions: filterFunctions,
|
||||
filterEvents: filterEvents
|
||||
};
|
||||
|
||||
|
49
test/abi.filters.js
Normal file
49
test/abi.filters.js
Normal file
@ -0,0 +1,49 @@
|
||||
var assert = require('assert');
|
||||
var abi = require('../lib/abi.js');
|
||||
|
||||
describe('abi', function() {
|
||||
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
|
||||
var events = abi.filterEvents(description);
|
||||
var functions = abi.filterFunctions(description);
|
||||
|
||||
// then
|
||||
assert.equal(events.length, 1);
|
||||
assert.equal(events[0].name, 'test2');
|
||||
assert.equal(functions.length, 1);
|
||||
assert.equal(functions[0].name, 'test');
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user