added eth_hashrate

This commit is contained in:
cubedro 2015-04-29 00:24:33 +03:00
parent 3b799d1284
commit bd73cccd14
2 changed files with 49 additions and 6 deletions

View File

@ -224,6 +224,11 @@ var properties = [
name: 'mining',
getter: 'eth_mining'
}),
new Property({
name: 'hashrate',
getter: 'eth_hashrate',
outputFormatter: utils.toDecimal
}),
new Property({
name: 'gasPrice',
getter: 'eth_gasPrice',

38
test/web3.eth.hashRate.js Normal file
View File

@ -0,0 +1,38 @@
var chai = require('chai');
var assert = chai.assert;
var web3 = require('../index');
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var method = 'hashrate';
var tests = [{
result: '0x788a8',
formattedResult: 493736,
call: 'eth_'+ method
}];
describe('web3.eth', function () {
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);
});
});
});
});