diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-28 21:20:36 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-28 21:20:36 +0800 |
commit | ea7c2fc673db31f96583e4712aa0fb78f5d709eb (patch) | |
tree | 120cf378eec0bc7549fe8128d62766964cb0cf6b /test/eth.contract.js | |
parent | 63d9c070ef7637a3d570a5a45ea931c1680ebc02 (diff) | |
download | go-tangerine-ea7c2fc673db31f96583e4712aa0fb78f5d709eb.tar go-tangerine-ea7c2fc673db31f96583e4712aa0fb78f5d709eb.tar.gz go-tangerine-ea7c2fc673db31f96583e4712aa0fb78f5d709eb.tar.bz2 go-tangerine-ea7c2fc673db31f96583e4712aa0fb78f5d709eb.tar.lz go-tangerine-ea7c2fc673db31f96583e4712aa0fb78f5d709eb.tar.xz go-tangerine-ea7c2fc673db31f96583e4712aa0fb78f5d709eb.tar.zst go-tangerine-ea7c2fc673db31f96583e4712aa0fb78f5d709eb.zip |
abi function type
Diffstat (limited to 'test/eth.contract.js')
-rw-r--r-- | test/eth.contract.js | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/test/eth.contract.js b/test/eth.contract.js new file mode 100644 index 000000000..945700cf9 --- /dev/null +++ b/test/eth.contract.js @@ -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); + + }); +}); + |