forked from cerc-io/plugeth
abi function type
This commit is contained in:
@@ -5,6 +5,7 @@ var clone = function (object) { return JSON.parse(JSON.stringify(object)); };
|
||||
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
@@ -339,10 +340,12 @@ describe('abi', function() {
|
||||
// given
|
||||
var d = [{
|
||||
name: "test",
|
||||
type: "function",
|
||||
inputs: [{ type: "int" }],
|
||||
outputs: [{ type: "int" }]
|
||||
},{
|
||||
name: "test2",
|
||||
type: "function",
|
||||
inputs: [{ type: "string" }],
|
||||
outputs: [{ type: "string" }]
|
||||
}];
|
||||
@@ -775,10 +778,12 @@ describe('abi', function() {
|
||||
// given
|
||||
var d = [{
|
||||
name: "test",
|
||||
type: "function",
|
||||
inputs: [{ type: "int" }],
|
||||
outputs: [{ type: "int" }]
|
||||
},{
|
||||
name: "test2",
|
||||
type: "function",
|
||||
inputs: [{ type: "string" }],
|
||||
outputs: [{ type: "string" }]
|
||||
}];
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
var assert = require('assert');
|
||||
var contract = require('../lib/contract.js');
|
||||
|
||||
describe('contract', function() {
|
||||
it('should create simple contract with one method from abi with explicit type name', function () {
|
||||
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test(uint256)",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
// when
|
||||
var con = contract(null, description);
|
||||
|
||||
// then
|
||||
assert.equal('function', typeof con.test);
|
||||
assert.equal('function', typeof con.test['uint256']);
|
||||
});
|
||||
|
||||
it('should create simple contract with one method from abi with implicit type name', function () {
|
||||
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
// when
|
||||
var con = contract(null, description);
|
||||
|
||||
// then
|
||||
assert.equal('function', typeof con.test);
|
||||
assert.equal('function', typeof con.test['uint256']);
|
||||
});
|
||||
|
||||
it('should create contract with multiple methods', function () {
|
||||
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
}, {
|
||||
"name": "test2",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
// when
|
||||
var con = contract(null, description);
|
||||
|
||||
// then
|
||||
assert.equal('function', typeof con.test);
|
||||
assert.equal('function', typeof con.test['uint256']);
|
||||
assert.equal('function', typeof con.test2);
|
||||
assert.equal('function', typeof con.test2['uint256']);
|
||||
});
|
||||
|
||||
it('should create contract with overloaded methods', function () {
|
||||
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
}, {
|
||||
"name": "test",
|
||||
"type": "function",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
// when
|
||||
var con = contract(null, description);
|
||||
|
||||
// then
|
||||
assert.equal('function', typeof con.test);
|
||||
assert.equal('function', typeof con.test['uint256']);
|
||||
assert.equal('function', typeof con.test['string']);
|
||||
});
|
||||
|
||||
it('should create contract with no methods', function () {
|
||||
|
||||
// given
|
||||
var description = [{
|
||||
"name": "test(uint256)",
|
||||
"type": "event",
|
||||
"inputs": [{
|
||||
"name": "a",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "d",
|
||||
"type": "uint256"
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
||||
|
||||
// when
|
||||
var con = contract(null, description);
|
||||
|
||||
// then
|
||||
assert.equal('undefined', typeof con.test);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user