mirror of https://github.com/status-im/web3.js.git
generic integration tests
This commit is contained in:
parent
4d1cf0bd9f
commit
33a3fc7bcd
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue