commit
ec0dc44fe2
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web3
|
* Web3
|
||||||
*
|
*
|
||||||
* @module web3
|
* @module web3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -77,16 +77,16 @@ var uncleCountCall = function (args) {
|
||||||
/// @returns an array of objects describing web3.eth api methods
|
/// @returns an array of objects describing web3.eth api methods
|
||||||
|
|
||||||
var getBalance = new Method({
|
var getBalance = new Method({
|
||||||
name: 'getBalance',
|
name: 'getBalance',
|
||||||
call: 'eth_getBalance',
|
call: 'eth_getBalance',
|
||||||
params: 2,
|
params: 2,
|
||||||
inputFormatter: [utils.toAddress, formatters.inputDefaultBlockNumberFormatter],
|
inputFormatter: [utils.toAddress, formatters.inputDefaultBlockNumberFormatter],
|
||||||
outputFormatter: formatters.outputBigNumberFormatter
|
outputFormatter: formatters.outputBigNumberFormatter
|
||||||
});
|
});
|
||||||
|
|
||||||
var getStorageAt = new Method({
|
var getStorageAt = new Method({
|
||||||
name: 'getStorageAt',
|
name: 'getStorageAt',
|
||||||
call: 'eth_getStorageAt',
|
call: 'eth_getStorageAt',
|
||||||
params: 3,
|
params: 3,
|
||||||
inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter]
|
inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter]
|
||||||
});
|
});
|
||||||
|
@ -99,7 +99,7 @@ var getCode = new Method({
|
||||||
});
|
});
|
||||||
|
|
||||||
var getBlock = new Method({
|
var getBlock = new Method({
|
||||||
name: 'getBlock',
|
name: 'getBlock',
|
||||||
call: blockCall,
|
call: blockCall,
|
||||||
params: 2,
|
params: 2,
|
||||||
inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }],
|
inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }],
|
||||||
|
@ -224,6 +224,11 @@ var properties = [
|
||||||
name: 'mining',
|
name: 'mining',
|
||||||
getter: 'eth_mining'
|
getter: 'eth_mining'
|
||||||
}),
|
}),
|
||||||
|
new Property({
|
||||||
|
name: 'hashrate',
|
||||||
|
getter: 'eth_hashrate',
|
||||||
|
outputFormatter: utils.toDecimal
|
||||||
|
}),
|
||||||
new Property({
|
new Property({
|
||||||
name: 'gasPrice',
|
name: 'gasPrice',
|
||||||
getter: 'eth_gasPrice',
|
getter: 'eth_gasPrice',
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue