2015-03-23 17:50:33 +00:00
|
|
|
var chai = require('chai');
|
|
|
|
var assert = chai.assert;
|
|
|
|
var web3 = require('../index');
|
|
|
|
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
|
|
|
|
|
|
|
var method = 'blockNumber';
|
|
|
|
|
|
|
|
var tests = [{
|
|
|
|
result: '0xb',
|
|
|
|
formattedResult: 11,
|
|
|
|
call: 'eth_'+ method
|
|
|
|
}];
|
|
|
|
|
2015-03-25 22:50:39 +00:00
|
|
|
describe('web3.eth', function () {
|
2015-03-23 17:50:33 +00:00
|
|
|
describe(method, function () {
|
|
|
|
tests.forEach(function (test, index) {
|
|
|
|
it('property test: ' + index, function () {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var provider = new FakeHttpProvider();
|
|
|
|
web3.setProvider(provider);
|
|
|
|
provider.injectResult(test.result);
|
|
|
|
provider.injectValidation(function (payload) {
|
|
|
|
assert.equal(payload.jsonrpc, '2.0');
|
|
|
|
assert.equal(payload.method, test.call);
|
|
|
|
assert.deepEqual(payload.params, []);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
var result = web3.eth[method];
|
|
|
|
|
|
|
|
// then
|
|
|
|
assert.strictEqual(test.formattedResult, result);
|
|
|
|
});
|
2015-05-12 06:26:27 +00:00
|
|
|
|
|
|
|
it('async get property test: ' + index, function (done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var provider = new FakeHttpProvider();
|
|
|
|
web3.setProvider(provider);
|
|
|
|
provider.injectResult(test.result);
|
|
|
|
provider.injectValidation(function (payload) {
|
|
|
|
assert.equal(payload.jsonrpc, '2.0');
|
|
|
|
assert.equal(payload.method, test.call);
|
|
|
|
assert.deepEqual(payload.params, []);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
web3.eth.getBlockNumber(function (err, result) {
|
|
|
|
assert.strictEqual(test.formattedResult, result);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2015-03-23 17:50:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|