diff --git a/test/eth.getBalance.js b/test/eth.getBalance.js new file mode 100644 index 0000000..bd3510f --- /dev/null +++ b/test/eth.getBalance.js @@ -0,0 +1,65 @@ +var chai = require('chai'); +var assert = chai.assert; +var web3 = require('../index'); +var FakeHttpProvider = require('./FakeHttpProvider'); + +var method = 'getBalance'; + +var tests = [{ + args: ['0x12d', '0x1'], + formattedArgs: ['0x12d', '0x1'], + result: '0x31981', + formattedResult: '0x31981', + call: 'eth_getBalance' +}]; + +describe('eth', function () { + describe(method, function () { + tests.forEach(function (test, index) { + it('sync test:' + index, function () { + + // given + var provider = new FakeHttpProvider(); + web3.setProvider(provider); + provider.injectResult(test.result); + var validation = function (payload) { + assert.equal(payload.jsonrpc, '2.0'); + assert.equal(payload.method, test.call); + assert.deepEqual(payload.params, test.formattedArgs); + }; + provider.injectValidation(validation); + + // when + var result = web3.eth[method].apply(null, test.args.slice(0)); + + // then + assert.equal(test.formattedResult, result); + }); + + it('async test: ' + index, function (done) { + + // given + var provider = new FakeHttpProvider(); + web3.setProvider(provider); + provider.injectResult(test.result); + var validation = function (payload) { + assert.equal(payload.jsonrpc, '2.0'); + assert.equal(payload.method, test.call); + assert.deepEqual(payload.params, test.formattedArgs); + }; + provider.injectValidation(validation); + var callback = function (err, result) { + assert.equal(test.formattedResult, result); + done(); + }; + + var args = test.args.slice(0); + args.push(callback); + + // when + web3.eth[method].apply(null, args); + }); + }); + }); +}); + diff --git a/test/eth.integration.js b/test/eth.integration.js deleted file mode 100644 index e05b5ee..0000000 --- a/test/eth.integration.js +++ /dev/null @@ -1,56 +0,0 @@ -var chai = require('chai'); -var assert = chai.assert; -var web3 = require('../index'); -var FakeHttpProvider = require('./FakeHttpProvider'); - -describe('eth', function () { - describe('getBalance', function () { - it('should get balance synchronously', function () { - - // given - var provider = new FakeHttpProvider(); - web3.setProvider(provider); - var address = '0x12d'; - var blockNumber = '0x1'; - var expected = '0x31981'; - provider.injectResult(expected); - var validation = function (payload) { - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'eth_getBalance'); - assert.deepEqual(payload.params, [address, blockNumber]); - }; - provider.injectValidation(validation); - - // when - var result = web3.eth.getBalance(address, blockNumber); - - // then - assert.equal(expected, result); - }); - - it('should get balance asynchronously', function (done) { - - // given - var provider = new FakeHttpProvider(); - web3.setProvider(provider); - var address = '0x12d'; - var blockNumber = '0x1'; - var expected = '0x31981'; - provider.injectResult(expected); - var validation = function (payload) { - assert.equal(payload.jsonrpc, '2.0'); - assert.equal(payload.method, 'eth_getBalance'); - assert.deepEqual(payload.params, [address, blockNumber]); - }; - provider.injectValidation(validation); - var callback = function (err, result) { - assert.equal(expected, result); - done(); - }; - - // when - web3.eth.getBalance(address, blockNumber, callback); - }); - }); -}); -