From 792c3e7094a086ff679aedf22208be78d44896b0 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 10 Mar 2015 17:41:32 +0100 Subject: [PATCH] Squashed 'libjsqrc/ethereumjs/' changes from 7d6b35a..9926e27 9926e27 upgraded version to 0.1.0 7a44f76 add shh post formatting 27d5421 merged from ethereum again 3848d3a fixed logs 18e1367 gulp f831dde Merge branch 'apiOverhaul' of https://github.com/frozeman/ethereum.js into apiOverhaul 27fca17 common fixes 1c9f50f changed topic to topics 8d7d00d fixed input parser test 1269731 Merge branch 'apiOverhaul' of https://github.com/frozeman/ethereum.js into apiOverhaul 2c740b0 add filter value conversion 38f6567 fixed examples fa5d4b5 Merge branch 'apiOverhaul' of https://github.com/frozeman/ethereum.js into apiOverhaul 8a2444b add default paramter for getBlock 2850bee fixed eth_getFilterChanges b454587 Merge branch 'develop' of https://github.com/ethereum/ethereum.js into apiOverhaul ede88f8 Merge pull request #105 from jorisbontje/balance-example 51a075c add in-output until eth_getBlockByHash 9c0d3e3 fixed to/fromWei a0b5353 changed outputs up to storageAt c2ed233 update balance example for new api 1f6c195 fixed toBigNumber e5cc501 updated readme 4eb857e increased meteor package version c7f8373 separated formatters files 068bdd7 changed project structure ddb90c2 refactoring formatters a6110a5 common changes d3569e4 more coverage tests e2352b4 utils.js docs 344428b tests... 9fe105e fixed from decimal; 50fc611 test for utils.toBigNumber 60ae274 code comments b8505d1 common changes ccb3775 new api method names 2b17ad6 refactoring 0a995e1 common changes in utils, fixing code complexity 3f63109 fix all failing karma tests 1fd1a31 Merge branch 'develop' into apiOverhaul 0b9d450 fixed karma test 75e92c8 Merge branch 'master' into develop a869780 Merge branch 'master' into apiOverhaul 2cdf08b Merge pull request #101 from chevdor/master 437e273 Helping travis a bit... old boy! d88effa Add node 0.12 + virtual screen for browsers/karma. 743eb30 Including Karma to Travis f0da6ef Merge remote-tracking branch 'upstream/master' cbb1efe test(eth): Disable few tests b819391 fixed tests c1136a0 Merge branch 'master' into develop 1b475aa downgrade to unreachable-branch-transform 0.1.0 636fb4b updated outdated deps cf3fa10 Merge branch 'ch' 96f3076 karma 9c72d43 Merge pull request #100 from chevdor/master 96fede8 Merge pull request #98 from kumavis/develop 833b810 doc(readme): Information about Karma in the readme e46f6f1 test(utils): Add test for the toEth() function 1e0d76e Remove phantomjs af5fef0 test(karma): Add Karma support 20c4e28 Move envify and unreachable-branch-transform to normal dependencies for external browserify support. 333c3ff merged develop b07ddb4 add defualt block 024433f Merge branch 'master' into develop 601c8ab ignore for maxcomplexity warning d9d190e Merge branch 'master' into develop a05742f Add internal defaultBlock 6cd96c9 add net object 48c107e update meteor package 9c4080b made filter polling async 869bb66 add optional callback 4096fb8 merged develop 5c4a36b working on adding callbacks 30111f7 Merge pull request #87 from kumavis/develop f2029b4 Merge pull request #85 from ethers/abiString ee686b0 Move browserify transforms to package.json 4b9bc17 constants should be before (dynamic) string contents 1c136e3 merged develop aef0171 add shh topic auto transformation for filter options 37e6d11 add shh output formatters and test c03a949 add package-init.js a69c04d add version file 487e0ac mdae it a meteor package 8cf8b9e gulp fd85749 Merge pull request #81 from ethers/arraySupport fcab219 vary the length of the arrays f8db634 need to save/concat per iteration ce664d6 fix test descriptions 66196ee constants should be before array contents, fixes #30 2cd4f02 add build files 47412c3 add more tests for blocks 545de25 add more tests 2e9a411 Merge pull request #71 from frozeman/apiOverhaul 30518ae fixed complexities 84900e6 merged with solved conflicts eaef1a2 merged develop 9981b97 fixed ) 8128342 fixed small change request 5ea5be2 add deprecated transact 181f109 changed getCode to getData 1fa7fa6 toFromWei fix ee65b2c add input formatter for transactions fec54d8 add depreaction warnring to contractFromAbi 684c495 changed contract API 36ca47f Changed watch to filter for eth and shh 7fde77d add formatter b41d7b3 Merge branch 'master' into develop 5424406 Merge pull request #69 from frozeman/apiOverhaul 1e3edbb Merge branch 'develop' of https://github.com/ethereum/ethereum.js into apiOverhaul 60cda4e fixed tests 91c015e Made to/fromWei return strings instead of numbers 85c843e Merge pull request #67 from frozeman/apiOverhaul ed7d473 Removed enumerable from methods, fixed number property ce141d8 Removed circular dependencies 188e9e5 Add toWei/fromWei and isAddress 5c994ff changed most of the function names REVERT: 7d6b35a Merge branch 'master' into cpp REVERT: ea250e6 Merge commit 'be3bfb76bef1d1f113033cd9093e03a00066d5d1' into ethereumjs_timeout REVERT: c08cea1 Improvement to AZ - confirmation disabler. Fix network crash. git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: 9926e27a84fe21f3e7250e7e245977a7125ddf63 --- abi.inputParser.js | 18 ++++++- abi.outputParser.js | 18 ++++++- eth.contract.js | 48 +++++++++++-------- eth.methods.js | 61 ++++++++++++++++-------- event.inputParser.js | 50 +++++++++---------- event.outputParser.js | 2 +- filter.methods.js | 13 ++--- formatters.inputPostFormatter.js | 28 +++++++++++ formatters.inputTransactionFormatter.js | 26 ++++++++++ formatters.outputBlockFormatter.js | 48 +++++++++++++++++++ formatters.outputLogFormatter.js | 27 +++++++++++ formatters.outputPostFormatter.js | 26 ++++++++++ formatters.outputTransactionFormatter.js | 26 ++++++++++ jsonrpc.isValidResponse.js | 2 +- jsonrpc.toBatchPayload.js | 2 +- jsonrpc.toPayload.js | 2 +- net.methods.js | 10 ++++ shh.methods.js | 3 +- utils.extractDisplayName.js | 2 +- utils.extractTypeName.js | 2 +- utils.filters.js | 2 +- utils.fromDecimal.js | 43 +++++++++++++++++ utils.fromWei.js | 22 +++++++++ utils.isAddress.js | 23 +++++++++ utils.isBigNumber.js | 26 ++++++++++ utils.isFunction.js | 21 ++++++++ utils.isString.js | 22 +++++++++ utils.toBigNumber.js | 45 +++++++++++++++++ utils.toDecimal.js | 14 ++++++ utils.toHex.js | 42 ++++++++++++++++ utils.toWei.js | 25 ++++++++++ web3.methods.js | 5 +- 32 files changed, 620 insertions(+), 84 deletions(-) create mode 100644 formatters.inputPostFormatter.js create mode 100644 formatters.inputTransactionFormatter.js create mode 100644 formatters.outputBlockFormatter.js create mode 100644 formatters.outputLogFormatter.js create mode 100644 formatters.outputPostFormatter.js create mode 100644 formatters.outputTransactionFormatter.js create mode 100644 net.methods.js create mode 100644 utils.fromDecimal.js create mode 100644 utils.fromWei.js create mode 100644 utils.isAddress.js create mode 100644 utils.isBigNumber.js create mode 100644 utils.isFunction.js create mode 100644 utils.isString.js create mode 100644 utils.toBigNumber.js create mode 100644 utils.toDecimal.js create mode 100644 utils.toHex.js create mode 100644 utils.toWei.js diff --git a/abi.inputParser.js b/abi.inputParser.js index edfc2b58f..2ee87761f 100644 --- a/abi.inputParser.js +++ b/abi.inputParser.js @@ -1,6 +1,6 @@ var assert = require('assert'); var BigNumber = require('bignumber.js'); -var abi = require('../lib/abi.js'); +var abi = require('../lib/solidity/abi.js'); var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; var description = [{ @@ -544,5 +544,21 @@ describe('abi', function() { }); + it('should throw an incorrect type error', function () { + + // given + var d = clone(description); + d[0].inputs = [ + { type: 'uin' } + ] + + // when + var parser = abi.inputParser(d); + + // then + assert.throws(function () {parser.test('0x')}, Error); + + }); + }); }); diff --git a/abi.outputParser.js b/abi.outputParser.js index 723c408f0..1ddd9d4fd 100644 --- a/abi.outputParser.js +++ b/abi.outputParser.js @@ -1,6 +1,6 @@ var assert = require('assert'); var BigNumber = require('bignumber.js'); -var abi = require('../lib/abi.js'); +var abi = require('../lib/solidity/abi.js'); var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; var description = [{ @@ -456,6 +456,22 @@ describe('abi', function() { }); + it('should throw an incorrect type error', function () { + + // given + var d = clone(description); + d[0].outputs = [ + { type: 'uin' } + ] + + // when + var parser = abi.outputParser(d); + + // then + assert.throws(function () {parser.test('0x')}, Error); + + }); + }); }); diff --git a/eth.contract.js b/eth.contract.js index 1a92ec88f..59ad51b29 100644 --- a/eth.contract.js +++ b/eth.contract.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var contract = require('../lib/contract.js'); +var contract = require('../lib/web3/contract.js'); describe('contract', function() { it('should create simple contract with one method from abi with explicit type name', function () { @@ -22,11 +22,12 @@ describe('contract', function() { }]; // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('function', typeof con.test); - assert.equal('function', typeof con.test['uint256']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); }); it('should create simple contract with one method from abi with implicit type name', function () { @@ -49,11 +50,12 @@ describe('contract', function() { }]; // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('function', typeof con.test); - assert.equal('function', typeof con.test['uint256']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); }); it('should create contract with multiple methods', function () { @@ -90,13 +92,14 @@ describe('contract', function() { }]; // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // 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']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); + assert.equal('function', typeof myCon.test2); + assert.equal('function', typeof myCon.test2['uint256']); }); it('should create contract with overloaded methods', function () { @@ -133,12 +136,13 @@ describe('contract', function() { }]; // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('function', typeof con.test); - assert.equal('function', typeof con.test['uint256']); - assert.equal('function', typeof con.test['string']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); + assert.equal('function', typeof myCon.test['string']); }); it('should create contract with no methods', function () { @@ -161,10 +165,11 @@ describe('contract', function() { // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('undefined', typeof con.test); + assert.equal('undefined', typeof myCon.test); }); @@ -189,11 +194,12 @@ describe('contract', function() { // when - var con = contract(null, description); + var Con = contract(description); + var myCon = new Con(null); // then - assert.equal('function', typeof con.test); - assert.equal('function', typeof con.test['uint256']); + assert.equal('function', typeof myCon.test); + assert.equal('function', typeof myCon.test['uint256']); }); diff --git a/eth.methods.js b/eth.methods.js index 9ea0ad59a..e1eea1ec4 100644 --- a/eth.methods.js +++ b/eth.methods.js @@ -4,33 +4,56 @@ var u = require('./test.utils.js'); describe('web3', function() { describe('eth', function() { - u.methodExists(web3.eth, 'balanceAt'); - u.methodExists(web3.eth, 'stateAt'); - u.methodExists(web3.eth, 'storageAt'); - u.methodExists(web3.eth, 'countAt'); - u.methodExists(web3.eth, 'codeAt'); - u.methodExists(web3.eth, 'transact'); + u.methodExists(web3.eth, 'getBalance'); + u.methodExists(web3.eth, 'getStorageAt'); + u.methodExists(web3.eth, 'getStorage'); + u.methodExists(web3.eth, 'getTransactionCount'); + u.methodExists(web3.eth, 'getData'); + u.methodExists(web3.eth, 'sendTransaction'); u.methodExists(web3.eth, 'call'); - u.methodExists(web3.eth, 'block'); - u.methodExists(web3.eth, 'transaction'); - u.methodExists(web3.eth, 'uncle'); - u.methodExists(web3.eth, 'compilers'); - u.methodExists(web3.eth, 'lll'); - u.methodExists(web3.eth, 'solidity'); - u.methodExists(web3.eth, 'serpent'); - u.methodExists(web3.eth, 'logs'); - u.methodExists(web3.eth, 'transactionCount'); - u.methodExists(web3.eth, 'uncleCount'); + u.methodExists(web3.eth, 'getBlock'); + u.methodExists(web3.eth, 'getTransaction'); + u.methodExists(web3.eth, 'getUncle'); + u.methodExists(web3.eth, 'getCompilers'); + u.methodExists(web3.eth.compile, 'lll'); + u.methodExists(web3.eth.compile, 'solidity'); + u.methodExists(web3.eth.compile, 'serpent'); + u.methodExists(web3.eth, 'getBlockTransactionCount'); + u.methodExists(web3.eth, 'getBlockUncleCount'); + u.methodExists(web3.eth, 'filter'); + u.methodExists(web3.eth, 'contract'); u.propertyExists(web3.eth, 'coinbase'); - u.propertyExists(web3.eth, 'listening'); u.propertyExists(web3.eth, 'mining'); u.propertyExists(web3.eth, 'gasPrice'); u.propertyExists(web3.eth, 'accounts'); - u.propertyExists(web3.eth, 'peerCount'); u.propertyExists(web3.eth, 'defaultBlock'); - u.propertyExists(web3.eth, 'number'); + u.propertyExists(web3.eth, 'blockNumber'); }); + + // Fail at the moment + // describe('eth', function(){ + // it('should be a positive balance', function() { + // // when + // var testAddress = '0x50f4ed0e83f9da907017bcfb444e3e25407f59bb'; + // var balance = web3.eth.balanceAt(testAddress); + // // then + // assert(balance > 0, 'Balance is ' + balance); + // }); + + // it('should return a block', function() { + // // when + // var block = web3.eth.block(0); + + // // then + // assert.notEqual(block, null); + // assert.equal(block.number, 0); + // assert(web3.toDecimal(block.difficulty) > 0); + // }); + // }); }); + + + diff --git a/event.inputParser.js b/event.inputParser.js index 8f9790a2d..a2ce27112 100644 --- a/event.inputParser.js +++ b/event.inputParser.js @@ -1,6 +1,6 @@ var assert = require('assert'); -var event = require('../lib/event.js'); -var f = require('../lib/formatters.js'); +var event = require('../lib/web3/event.js'); +var f = require('../lib/solidity/formatters.js'); describe('event', function () { describe('inputParser', function () { @@ -20,8 +20,8 @@ describe('event', function () { // then assert.equal(result.address, address); - assert.equal(result.topic.length, 1); - assert.equal(result.topic[0], signature); + assert.equal(result.topics.length, 1); + assert.equal(result.topics[0], signature); }); @@ -31,10 +31,10 @@ describe('event', function () { var address = '0x012345'; var signature = '0x987654'; var options = { - earliest: 1, - latest: 2, + fromBlock: 1, + toBlock: 2, offset: 3, - max: 4 + limit: 4 }; var e = { name: 'Event', @@ -47,12 +47,12 @@ describe('event', function () { // then assert.equal(result.address, address); - assert.equal(result.topic.length, 1); - assert.equal(result.topic[0], signature); - assert.equal(result.earliest, options.earliest); - assert.equal(result.latest, options.latest); + assert.equal(result.topics.length, 1); + assert.equal(result.topics[0], signature); + assert.equal(result.fromBlock, options.fromBlock); + assert.equal(result.toBlock, options.toBlock); assert.equal(result.offset, options.offset); - assert.equal(result.max, options.max); + assert.equal(result.limit, options.limit); }); @@ -62,10 +62,10 @@ describe('event', function () { var address = '0x012345'; var signature = '0x987654'; var options = { - earliest: 1, - latest: 2, + fromBlock: 1, + toBlock: 2, offset: 3, - max: 4 + limit: 4 }; var e = { name: 'Event', @@ -78,13 +78,13 @@ describe('event', function () { // then assert.equal(result.address, address); - assert.equal(result.topic.length, 2); - assert.equal(result.topic[0], signature); - assert.equal(result.topic[1], f.formatInputInt(4)); - assert.equal(result.earliest, options.earliest); - assert.equal(result.latest, options.latest); + assert.equal(result.topics.length, 2); + assert.equal(result.topics[0], signature); + assert.equal(result.topics[1], f.formatInputInt(4)); + assert.equal(result.fromBlock, options.fromBlock); + assert.equal(result.toBlock, options.toBlock); assert.equal(result.offset, options.offset); - assert.equal(result.max, options.max); + assert.equal(result.limit, options.limit); }); @@ -110,10 +110,10 @@ describe('event', function () { // then assert.equal(result.address, address); - assert.equal(result.topic.length, 2); - assert.equal(result.topic[0], signature); - assert.equal(result.topic[1][0], f.formatInputInt(4)); - assert.equal(result.topic[1][1], f.formatInputInt(69)); + assert.equal(result.topics.length, 2); + assert.equal(result.topics[0], signature); + assert.equal(result.topics[1][0], f.formatInputInt(4)); + assert.equal(result.topics[1][1], f.formatInputInt(69)); assert.equal(result.earliest, options.earliest); assert.equal(result.latest, options.latest); assert.equal(result.offset, options.offset); diff --git a/event.outputParser.js b/event.outputParser.js index 22f4ed395..93b50ff2f 100644 --- a/event.outputParser.js +++ b/event.outputParser.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var event = require('../lib/event.js'); +var event = require('../lib/web3/event.js'); describe('event', function () { describe('outputParser', function () { diff --git a/filter.methods.js b/filter.methods.js index 9f81ec38f..d039ec9bb 100644 --- a/filter.methods.js +++ b/filter.methods.js @@ -1,11 +1,11 @@ var assert = require('assert'); -var filter = require('../lib/filter'); +var filter = require('../lib/web3/filter'); var u = require('./test.utils.js'); var empty = function () {}; var implementation = { newFilter: empty, - getMessages: empty, + getLogs: empty, uninstallFilter: empty, startPolling: empty, stopPolling: empty, @@ -16,12 +16,9 @@ describe('web3', function () { describe('filter', function () { var f = filter({}, implementation); - u.methodExists(f, 'arrived'); - u.methodExists(f, 'happened'); - u.methodExists(f, 'changed'); - u.methodExists(f, 'messages'); - u.methodExists(f, 'logs'); - u.methodExists(f, 'uninstall'); + u.methodExists(f, 'watch'); + u.methodExists(f, 'stopWatching'); + u.methodExists(f, 'get'); }); }); }); diff --git a/formatters.inputPostFormatter.js b/formatters.inputPostFormatter.js new file mode 100644 index 000000000..0995d6d79 --- /dev/null +++ b/formatters.inputPostFormatter.js @@ -0,0 +1,28 @@ +var chai = require('chai'); +var formatters = require('../lib/web3/formatters.js'); +var assert = chai.assert; + +describe('formatters', function () { + describe('inputPostFormatter', function () { + it('should return the correct value', function () { + + // input as strings and numbers + assert.deepEqual(formatters.inputPostFormatter({ + from: '0x00000', + to: '0x00000', + payload: {test: 'test'}, + ttl: 200, + priority: 1000, + topics: ['hello','mytopics'] + }), { + from: '0x00000', + to: '0x00000', + payload: '0x7b2274657374223a2274657374227d', + ttl: '0xc8', + priority: '0x3e8', + topics: ['0x68656c6c6f','0x6d79746f70696373'] + }); + + }); + }); +}); diff --git a/formatters.inputTransactionFormatter.js b/formatters.inputTransactionFormatter.js new file mode 100644 index 000000000..5ff0526e1 --- /dev/null +++ b/formatters.inputTransactionFormatter.js @@ -0,0 +1,26 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); +var BigNumber = require('bignumber.js'); + +describe('formatters', function () { + describe('inputTransactionFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.inputTransactionFormatter({ + data: '0x34234kjh23kj4234', + value: new BigNumber(100), + from: '0x00000', + to: '0x00000', + gas: 1000, + gasPrice: new BigNumber(1000), + }), { + data: '0x34234kjh23kj4234', + value: '0x64', + from: '0x00000', + to: '0x00000', + gas: '0x3e8', + gasPrice: '0x3e8', + }); + }); + }); +}); diff --git a/formatters.outputBlockFormatter.js b/formatters.outputBlockFormatter.js new file mode 100644 index 000000000..f31cced99 --- /dev/null +++ b/formatters.outputBlockFormatter.js @@ -0,0 +1,48 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); +var BigNumber = require('bignumber.js'); + +describe('formatters', function () { + describe('outputBlockFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.outputBlockFormatter({ + hash: '0x34234kjh23kj4234', + parentHash: '0x34234kjh23kj4234', + miner: '0x34234kjh23kj4234', + stateRoot: '0x34234kjh23kj4234', + sha3Uncles: '0x34234kjh23kj4234', + bloom: '0x34234kjh23kj4234', + difficulty: '0x3e8', + totalDifficulty: '0x3e8', + number: '0x3e8', + minGasPrice: '0x3e8', + gasLimit: '0x3e8', + gasUsed: '0x3e8', + timestamp: '0x3e8', + extraData: '0x34234kjh23kj4234', + nonce: '0x34234kjh23kj4234', + children: ['0x34234kjh23kj4234'], + size: '0x3e8' + }), { + hash: '0x34234kjh23kj4234', + parentHash: '0x34234kjh23kj4234', + miner: '0x34234kjh23kj4234', + stateRoot: '0x34234kjh23kj4234', + sha3Uncles: '0x34234kjh23kj4234', + bloom: '0x34234kjh23kj4234', + difficulty: new BigNumber(1000), + totalDifficulty: new BigNumber(1000), + number: 1000, + minGasPrice: new BigNumber(1000), + gasLimit: 1000, + gasUsed: 1000, + timestamp: 1000, + extraData: '0x34234kjh23kj4234', + nonce: '0x34234kjh23kj4234', + children: ['0x34234kjh23kj4234'], + size: 1000 + }); + }); + }); +}); diff --git a/formatters.outputLogFormatter.js b/formatters.outputLogFormatter.js new file mode 100644 index 000000000..495a64620 --- /dev/null +++ b/formatters.outputLogFormatter.js @@ -0,0 +1,27 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); + +describe('formatters', function () { + describe('outputLogFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.outputLogFormatter({ + transactionIndex: '0x3e8', + logIndex: '0x3e8', + blockNumber: '0x3e8', + transactionHash: '0x7b2274657374223a2274657374227d', + blockHash: '0x7b2274657374223a2274657374227d', + data: '0x7b2274657374223a2274657374227d', + topics: ['0x68656c6c6f','0x6d79746f70696373'] + }), { + transactionIndex: 1000, + logIndex: 1000, + blockNumber: 1000, + transactionHash: '0x7b2274657374223a2274657374227d', + blockHash: '0x7b2274657374223a2274657374227d', + data: '0x7b2274657374223a2274657374227d', + topics: ['0x68656c6c6f','0x6d79746f70696373'] + }); + }); + }); +}); diff --git a/formatters.outputPostFormatter.js b/formatters.outputPostFormatter.js new file mode 100644 index 000000000..850d3d801 --- /dev/null +++ b/formatters.outputPostFormatter.js @@ -0,0 +1,26 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); + +describe('formatters', function () { + describe('outputPostFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.outputPostFormatter({ + expiry: '0x3e8', + sent: '0x3e8', + ttl: '0x3e8', + workProved: '0x3e8', + payload: '0x7b2274657374223a2274657374227d', + topics: ['0x68656c6c6f','0x6d79746f70696373'] + }), { + expiry: 1000, + sent: 1000, + ttl: 1000, + workProved: 1000, + payload: {test: 'test'}, + payloadRaw: '0x7b2274657374223a2274657374227d', + topics: ['hello','mytopics'] + }); + }); + }); +}); diff --git a/formatters.outputTransactionFormatter.js b/formatters.outputTransactionFormatter.js new file mode 100644 index 000000000..f42ed8495 --- /dev/null +++ b/formatters.outputTransactionFormatter.js @@ -0,0 +1,26 @@ +var assert = require('assert'); +var formatters = require('../lib/web3/formatters.js'); +var BigNumber = require('bignumber.js'); + +describe('formatters', function () { + describe('outputTransactionFormatter', function () { + it('should return the correct value', function () { + + assert.deepEqual(formatters.outputTransactionFormatter({ + input: '0x34234kjh23kj4234', + from: '0x00000', + to: '0x00000', + value: '0x3e8', + gas: '0x3e8', + gasPrice: '0x3e8' + }), { + input: '0x34234kjh23kj4234', + from: '0x00000', + to: '0x00000', + value: new BigNumber(1000), + gas: 1000, + gasPrice: new BigNumber(1000), + }); + }); + }); +}); diff --git a/jsonrpc.isValidResponse.js b/jsonrpc.isValidResponse.js index 920b5f3a9..78388a443 100644 --- a/jsonrpc.isValidResponse.js +++ b/jsonrpc.isValidResponse.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var jsonrpc = require('../lib/jsonrpc'); +var jsonrpc = require('../lib/web3/jsonrpc'); describe('jsonrpc', function () { describe('isValidResponse', function () { diff --git a/jsonrpc.toBatchPayload.js b/jsonrpc.toBatchPayload.js index 1c1aafebb..c9a1e51e0 100644 --- a/jsonrpc.toBatchPayload.js +++ b/jsonrpc.toBatchPayload.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var jsonrpc = require('../lib/jsonrpc'); +var jsonrpc = require('../lib/web3/jsonrpc'); describe('jsonrpc', function () { describe('toBatchPayload', function () { diff --git a/jsonrpc.toPayload.js b/jsonrpc.toPayload.js index 6d6f003bb..a79501d73 100644 --- a/jsonrpc.toPayload.js +++ b/jsonrpc.toPayload.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var jsonrpc = require('../lib/jsonrpc'); +var jsonrpc = require('../lib/web3/jsonrpc'); describe('jsonrpc', function () { describe('toPayload', function () { diff --git a/net.methods.js b/net.methods.js new file mode 100644 index 000000000..26d9c224d --- /dev/null +++ b/net.methods.js @@ -0,0 +1,10 @@ +var assert = require('assert'); +var web3 = require('../index.js'); +var u = require('./test.utils.js'); + +describe('web3', function() { + describe('net', function() { + u.propertyExists(web3.net, 'listening'); + u.propertyExists(web3.net, 'peerCount'); + }); +}); \ No newline at end of file diff --git a/shh.methods.js b/shh.methods.js index 91ca3caba..f8501d527 100644 --- a/shh.methods.js +++ b/shh.methods.js @@ -6,9 +6,10 @@ describe('web3', function() { describe('shh', function() { u.methodExists(web3.shh, 'post'); u.methodExists(web3.shh, 'newIdentity'); - u.methodExists(web3.shh, 'haveIdentity'); + u.methodExists(web3.shh, 'hasIdentity'); u.methodExists(web3.shh, 'newGroup'); u.methodExists(web3.shh, 'addToGroup'); + u.methodExists(web3.shh, 'filter'); }); }); diff --git a/utils.extractDisplayName.js b/utils.extractDisplayName.js index 148653ab2..c401b7e60 100644 --- a/utils.extractDisplayName.js +++ b/utils.extractDisplayName.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var utils = require('../lib/utils.js'); +var utils = require('../lib/utils/utils.js'); describe('utils', function () { describe('extractDisplayName', function () { diff --git a/utils.extractTypeName.js b/utils.extractTypeName.js index 2b4bbe767..7211ff613 100644 --- a/utils.extractTypeName.js +++ b/utils.extractTypeName.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var utils = require('../lib/utils.js'); +var utils = require('../lib/utils/utils.js'); describe('utils', function () { describe('extractTypeName', function () { diff --git a/utils.filters.js b/utils.filters.js index f2d2788b0..4629e4fe8 100644 --- a/utils.filters.js +++ b/utils.filters.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var utils = require('../lib/utils.js'); +var utils = require('../lib/utils/utils.js'); describe('utils', function() { it('should filter functions and events from input array properly', function () { diff --git a/utils.fromDecimal.js b/utils.fromDecimal.js new file mode 100644 index 000000000..4dc774c74 --- /dev/null +++ b/utils.fromDecimal.js @@ -0,0 +1,43 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var assert = chai.assert; + +var tests = [ + { value: 1, expected: '0x1' }, + { value: '1', expected: '0x1' }, + { value: '0x1', expected: '0x1'}, + { value: '0x01', expected: '0x1'}, + { value: 15, expected: '0xf'}, + { value: '15', expected: '0xf'}, + { value: '0xf', expected: '0xf'}, + { value: '0x0f', expected: '0xf'}, + { value: -1, expected: '-0x1'}, + { value: '-1', expected: '-0x1'}, + { value: '-0x1', expected: '-0x1'}, + { value: '-0x01', expected: '-0x1'}, + { value: -15, expected: '-0xf'}, + { value: '-15', expected: '-0xf'}, + { value: '-0xf', expected: '-0xf'}, + { value: '-0x0f', expected: '-0xf'}, + { value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, + { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, + { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, + { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, + { value: 0, expected: '0x0'}, + { value: '0', expected: '0x0'}, + { value: '0x0', expected: '0x0'}, + { value: -0, expected: '0x0'}, + { value: '-0', expected: '0x0'}, + { value: '-0x0', expected: '0x0'} +]; + +describe('utils', function () { + describe('fromDecimal', function () { + tests.forEach(function (test) { + it('should turn ' + test.value + ' to ' + test.expected, function () { + assert.equal(utils.fromDecimal(test.value), test.expected); + }); + }); + }); +}); + diff --git a/utils.fromWei.js b/utils.fromWei.js new file mode 100644 index 000000000..735575c68 --- /dev/null +++ b/utils.fromWei.js @@ -0,0 +1,22 @@ +var assert = require('assert'); +var utils = require('../lib/utils/utils.js'); + +describe('utils', function () { + describe('fromWei', function () { + it('should return the correct value', function () { + + assert.equal(utils.fromWei(1000000000000000000, 'wei'), '1000000000000000000'); + assert.equal(utils.fromWei(1000000000000000000, 'kwei'), '1000000000000000'); + assert.equal(utils.fromWei(1000000000000000000, 'mwei'), '1000000000000'); + assert.equal(utils.fromWei(1000000000000000000, 'gwei'), '1000000000'); + assert.equal(utils.fromWei(1000000000000000000, 'szabo'), '1000000'); + assert.equal(utils.fromWei(1000000000000000000, 'finney'), '1000'); + assert.equal(utils.fromWei(1000000000000000000, 'ether'), '1'); + assert.equal(utils.fromWei(1000000000000000000, 'kether'), '0.001'); + assert.equal(utils.fromWei(1000000000000000000, 'grand'), '0.001'); + assert.equal(utils.fromWei(1000000000000000000, 'mether'), '0.000001'); + assert.equal(utils.fromWei(1000000000000000000, 'gether'), '0.000000001'); + assert.equal(utils.fromWei(1000000000000000000, 'tether'), '0.000000000001'); + }); + }); +}); diff --git a/utils.isAddress.js b/utils.isAddress.js new file mode 100644 index 000000000..d2d087ffd --- /dev/null +++ b/utils.isAddress.js @@ -0,0 +1,23 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var assert = chai.assert; + +var tests = [ + { value: function () {}, is: false}, + { value: new Function(), is: false}, + { value: 'function', is: false}, + { value: {}, is: false}, + { value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true }, + { value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: true } +]; + +describe('utils', function () { + describe('isAddress', function () { + tests.forEach(function (test) { + it('shoud test if value ' + test.value + ' is address: ' + test.is, function () { + assert.equal(utils.isAddress(test.value), test.is); + }); + }); + }); +}); + diff --git a/utils.isBigNumber.js b/utils.isBigNumber.js new file mode 100644 index 000000000..a3de36916 --- /dev/null +++ b/utils.isBigNumber.js @@ -0,0 +1,26 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var BigNumber = require('bignumber.js'); +var assert = chai.assert; + +var tests = [ + { value: function () {}, is: false}, + { value: new Function(), is: false}, + { value: 'function', is: false}, + { value: {}, is: false}, + { value: new String('hello'), is: false}, + { value: new BigNumber(0), is: true}, + { value: 132, is: false}, + { value: '0x12', is: false}, + +]; + +describe('utils', function () { + describe('isBigNumber', function () { + tests.forEach(function (test) { + it('shoud test if value ' + test.func + ' is BigNumber: ' + test.is, function () { + assert.equal(utils.isBigNumber(test.value), test.is); + }); + }); + }); +}); diff --git a/utils.isFunction.js b/utils.isFunction.js new file mode 100644 index 000000000..c113bc334 --- /dev/null +++ b/utils.isFunction.js @@ -0,0 +1,21 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var assert = chai.assert; + +var tests = [ + { func: function () {}, is: true}, + { func: new Function(), is: true}, + { func: 'function', is: false}, + { func: {}, is: false} +]; + +describe('utils', function () { + describe('isFunction', function () { + tests.forEach(function (test) { + it('shoud test if value ' + test.func + ' is function: ' + test.is, function () { + assert.equal(utils.isFunction(test.func), test.is); + }); + }); + }); +}); + diff --git a/utils.isString.js b/utils.isString.js new file mode 100644 index 000000000..bb36ccd67 --- /dev/null +++ b/utils.isString.js @@ -0,0 +1,22 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var assert = chai.assert; + +var tests = [ + { value: function () {}, is: false}, + { value: new Function(), is: false}, + { value: 'function', is: true}, + { value: {}, is: false}, + { value: new String('hello'), is: true} +]; + +describe('utils', function () { + describe('isString', function () { + tests.forEach(function (test) { + it('shoud test if value ' + test.func + ' is string: ' + test.is, function () { + assert.equal(utils.isString(test.value), test.is); + }); + }); + }); +}); + diff --git a/utils.toBigNumber.js b/utils.toBigNumber.js new file mode 100644 index 000000000..2d293c12a --- /dev/null +++ b/utils.toBigNumber.js @@ -0,0 +1,45 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils.js'); +var BigNumber = require('bignumber.js'); +var assert = chai.assert; + +var tests = [ + { value: 1, expected: '1' }, + { value: '1', expected: '1' }, + { value: '0x1', expected: '1'}, + { value: '0x01', expected: '1'}, + { value: 15, expected: '15'}, + { value: '15', expected: '15'}, + { value: '0xf', expected: '15'}, + { value: '0x0f', expected: '15'}, + { value: new BigNumber('f', 16), expected: '15'}, + { value: -1, expected: '-1'}, + { value: '-1', expected: '-1'}, + { value: '-0x1', expected: '-1'}, + { value: '-0x01', expected: '-1'}, + { value: -15, expected: '-15'}, + { value: '-15', expected: '-15'}, + { value: '-0xf', expected: '-15'}, + { value: '-0x0f', expected: '-15'}, + { value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639935'}, + { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639933'}, + { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639935'}, + { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639933'}, + { value: 0, expected: '0'}, + { value: '0', expected: '0'}, + { value: '0x0', expected: '0'}, + { value: -0, expected: '0'}, + { value: '-0', expected: '0'}, + { value: '-0x0', expected: '0'}, + { value: new BigNumber(0), expected: '0'} +]; + +describe('utils', function () { + describe('toBigNumber', function () { + tests.forEach(function (test) { + it('should turn ' + test.value + ' to ' + test.expected, function () { + assert.equal(utils.toBigNumber(test.value).toString(10), test.expected); + }); + }); + }); +}); diff --git a/utils.toDecimal.js b/utils.toDecimal.js new file mode 100644 index 000000000..d785b0444 --- /dev/null +++ b/utils.toDecimal.js @@ -0,0 +1,14 @@ +var assert = require('assert'); +var utils = require('../lib/utils/utils.js'); + +describe('utils', function () { + describe('toDecimal', function () { + it('should return the correct value', function () { + + assert.equal(utils.toDecimal("0x3e8"), '1000'); + // allow compatiblity + assert.equal(utils.toDecimal(100000), '100000'); + assert.equal(utils.toDecimal('100000'), '100000'); + }); + }); +}); diff --git a/utils.toHex.js b/utils.toHex.js new file mode 100644 index 000000000..2e9c59cb5 --- /dev/null +++ b/utils.toHex.js @@ -0,0 +1,42 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils'); +var BigNumber = require('bignumber.js'); +var assert = chai.assert; + +var tests = [ + { value: 1, expected: '0x1' }, + { value: '1', expected: '0x1' }, + { value: '0x1', expected: '0x1'}, + { value: '15', expected: '0xf'}, + { value: '0xf', expected: '0xf'}, + { value: -1, expected: '-0x1'}, + { value: '-1', expected: '-0x1'}, + { value: '-0x1', expected: '-0x1'}, + { value: '-15', expected: '-0xf'}, + { value: '-0xf', expected: '-0xf'}, + { value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, + { value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}, + { value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'}, + { value: 0, expected: '0x0'}, + { value: '0', expected: '0x0'}, + { value: '0x0', expected: '0x0'}, + { value: -0, expected: '0x0'}, + { value: '-0', expected: '0x0'}, + { value: '-0x0', expected: '0x0'}, + { value: [1,2,3,{test: 'data'}], expected: '0x5b312c322c332c7b2274657374223a2264617461227d5d'}, + { value: {test: 'test'}, expected: '0x7b2274657374223a2274657374227d'}, + { value: '{"test": "test"}', expected: '0x7b2274657374223a202274657374227d'}, + { value: 'myString', expected: '0x6d79537472696e67'}, + { value: new BigNumber(15), expected: '0xf'} +]; + +describe('utils', function () { + describe('toHex', function () { + tests.forEach(function (test) { + it('should turn ' + test.value + ' to ' + test.expected, function () { + assert.equal(utils.toHex(test.value), test.expected); + }); + }); + }); +}); + diff --git a/utils.toWei.js b/utils.toWei.js new file mode 100644 index 000000000..33e03ffc3 --- /dev/null +++ b/utils.toWei.js @@ -0,0 +1,25 @@ +var chai = require('chai'); +var utils = require('../lib/utils/utils'); +var assert = chai.assert; + +describe('utils', function () { + describe('toWei', function () { + it('should return the correct value', function () { + + assert.equal(utils.toWei(1, 'wei'), '1'); + assert.equal(utils.toWei(1, 'kwei'), '1000'); + assert.equal(utils.toWei(1, 'mwei'), '1000000'); + assert.equal(utils.toWei(1, 'gwei'), '1000000000'); + assert.equal(utils.toWei(1, 'szabo'), '1000000000000'); + assert.equal(utils.toWei(1, 'finney'), '1000000000000000'); + assert.equal(utils.toWei(1, 'ether'), '1000000000000000000'); + assert.equal(utils.toWei(1, 'kether'), '1000000000000000000000'); + assert.equal(utils.toWei(1, 'grand'), '1000000000000000000000'); + assert.equal(utils.toWei(1, 'mether'), '1000000000000000000000000'); + assert.equal(utils.toWei(1, 'gether'), '1000000000000000000000000000'); + assert.equal(utils.toWei(1, 'tether'), '1000000000000000000000000000000'); + + assert.throws(function () {utils.toWei(1, 'wei1');}, Error); + }); + }); +}); diff --git a/web3.methods.js b/web3.methods.js index 8dcc61101..92d4e1604 100644 --- a/web3.methods.js +++ b/web3.methods.js @@ -8,7 +8,10 @@ describe('web3', function() { u.methodExists(web3, 'fromAscii'); u.methodExists(web3, 'toDecimal'); u.methodExists(web3, 'fromDecimal'); - u.methodExists(web3, 'toEth'); + u.methodExists(web3, 'fromWei'); + u.methodExists(web3, 'toWei'); + u.methodExists(web3, 'toBigNumber'); + u.methodExists(web3, 'isAddress'); u.methodExists(web3, 'setProvider'); u.methodExists(web3, 'reset');