From 09f633596da91818201781cc009e1e1ab6f8d059 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 27 Jan 2015 15:20:22 +0100 Subject: fixed #23 --- test/abi.parsers.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test') diff --git a/test/abi.parsers.js b/test/abi.parsers.js index 19fa1d4cf..b7a05cea3 100644 --- a/test/abi.parsers.js +++ b/test/abi.parsers.js @@ -823,6 +823,38 @@ describe('abi', function() { }); + it('should parse 0x value', function () { + + // given + var d = clone(description); + d[0].outputs = [ + { type: 'int' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x")[0], 0); + + }); + + it('should parse 0x value', function () { + + // given + var d = clone(description); + d[0].outputs = [ + { type: 'uint' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x")[0], 0); + + }); + }); }); -- cgit v1.2.3 From c2cb2bef96e591d68b04cf5f1a6ec29696abb481 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 27 Jan 2015 16:02:42 +0100 Subject: removed web3.eth.account, fixed #37 --- test/eth.methods.js | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/eth.methods.js b/test/eth.methods.js index 002268565..7a031c4c8 100644 --- a/test/eth.methods.js +++ b/test/eth.methods.js @@ -24,7 +24,6 @@ describe('web3', function() { u.propertyExists(web3.eth, 'listening'); u.propertyExists(web3.eth, 'mining'); u.propertyExists(web3.eth, 'gasPrice'); - u.propertyExists(web3.eth, 'account'); u.propertyExists(web3.eth, 'accounts'); u.propertyExists(web3.eth, 'peerCount'); u.propertyExists(web3.eth, 'defaultBlock'); -- cgit v1.2.3 From 83fad0fb594ca120eb979d4d643be96c26553a6f Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 27 Jan 2015 23:03:57 +0100 Subject: removed fromFixed, toFixed && offset from tests --- test/web3.methods.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'test') diff --git a/test/web3.methods.js b/test/web3.methods.js index 1b5792110..d08495dd9 100644 --- a/test/web3.methods.js +++ b/test/web3.methods.js @@ -6,8 +6,5 @@ describe('web3', function() { u.methodExists(web3, 'sha3'); u.methodExists(web3, 'toAscii'); u.methodExists(web3, 'fromAscii'); - u.methodExists(web3, 'toFixed'); - u.methodExists(web3, 'fromFixed'); - u.methodExists(web3, 'offset'); }); -- cgit v1.2.3 From ea7c2fc673db31f96583e4712aa0fb78f5d709eb Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 28 Jan 2015 14:20:36 +0100 Subject: abi function type --- test/abi.parsers.js | 5 ++ test/eth.contract.js | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/eth.event.js | 0 3 files changed, 177 insertions(+) create mode 100644 test/eth.contract.js create mode 100644 test/eth.event.js (limited to 'test') diff --git a/test/abi.parsers.js b/test/abi.parsers.js index b7a05cea3..12bccf5a5 100644 --- a/test/abi.parsers.js +++ b/test/abi.parsers.js @@ -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" }] }]; 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); + + }); +}); + diff --git a/test/eth.event.js b/test/eth.event.js new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From 2544d2c952dc003d62bdb99a554b3fa576b202c5 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 28 Jan 2015 14:39:10 +0100 Subject: tests for abi.filters --- test/abi.filters.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/abi.filters.js (limited to 'test') diff --git a/test/abi.filters.js b/test/abi.filters.js new file mode 100644 index 000000000..42385fd2a --- /dev/null +++ b/test/abi.filters.js @@ -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'); + + }); +}); -- cgit v1.2.3 From 842b8cf323a3b39d9e29ddd831bc41ddb98279ad Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 29 Jan 2015 12:35:21 +0100 Subject: event.js --- test/eth.contract.js | 31 ++++++++++++++++++++++++++++++- test/eth.event.js | 0 test/event.js | 25 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) delete mode 100644 test/eth.event.js create mode 100644 test/event.js (limited to 'test') diff --git a/test/eth.contract.js b/test/eth.contract.js index 945700cf9..1a92ec88f 100644 --- a/test/eth.contract.js +++ b/test/eth.contract.js @@ -146,7 +146,6 @@ describe('contract', function() { // given var description = [{ "name": "test(uint256)", - "type": "event", "inputs": [{ "name": "a", "type": "uint256" @@ -168,5 +167,35 @@ describe('contract', function() { assert.equal('undefined', typeof con.test); }); + + it('should create contract with one event', function () { + + // given + var description = [{ + "name": "test", + "type": "event", + "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']); + + }); + }); diff --git a/test/eth.event.js b/test/eth.event.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/event.js b/test/event.js new file mode 100644 index 000000000..0cc9c0c65 --- /dev/null +++ b/test/event.js @@ -0,0 +1,25 @@ +var assert = require('assert'); +var event = require('../lib/event.js'); + +describe('event', function () { + it('should create filter input object from given', function () { + + // given + var address = '0x012345'; + var signature = '0x987654'; + var e = { + name: 'test', + type: 'event', + }; + + // when + var impl = event(e, address, signature); + var result = impl(); + + // then + assert.equal(result.address, address); + assert.equal(result.topics.length, 1); + assert.equal(result.topics[0], signature); + + }); +}); -- cgit v1.2.3 From c8ee08c24bee9ab994822066f9abe94448c4ae89 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 29 Jan 2015 13:32:32 +0100 Subject: contract.js simplified --- test/event.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/event.js b/test/event.js index 0cc9c0c65..781f42e5e 100644 --- a/test/event.js +++ b/test/event.js @@ -7,13 +7,9 @@ describe('event', function () { // given var address = '0x012345'; var signature = '0x987654'; - var e = { - name: 'test', - type: 'event', - }; // when - var impl = event(e, address, signature); + var impl = event(address, signature); var result = impl(); // then @@ -23,3 +19,4 @@ describe('event', function () { }); }); + -- cgit v1.2.3