add eth_protocolVersion (#491)

This commit is contained in:
bas-vk 2016-09-12 15:20:20 +02:00 committed by Fabian Vogelsteller
parent 260ac6e78a
commit c2426ad880
3 changed files with 42 additions and 0 deletions

View File

@ -314,6 +314,10 @@ var properties = function () {
name: 'blockNumber', name: 'blockNumber',
getter: 'eth_blockNumber', getter: 'eth_blockNumber',
outputFormatter: utils.toDecimal outputFormatter: utils.toDecimal
}),
new Property({
name: 'protocolVersion',
getter: 'eth_protocolVersion'
}) })
]; ];
}; };

View File

@ -30,6 +30,7 @@ describe('web3.eth', function() {
u.propertyExists(web3.eth, 'accounts'); u.propertyExists(web3.eth, 'accounts');
u.propertyExists(web3.eth, 'defaultBlock'); u.propertyExists(web3.eth, 'defaultBlock');
u.propertyExists(web3.eth, 'blockNumber'); u.propertyExists(web3.eth, 'blockNumber');
u.propertyExists(web3.eth, 'protocolVersion');
}); });
}); });

View File

@ -0,0 +1,37 @@
var chai = require('chai');
var assert = chai.assert;
var Web3 = require('../index');
var web3 = new Web3();
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var method = 'protocolVersion';
var tests = [{
result: ['1234'],
call: 'eth_'+ method
}];
describe('eth.protocolVersion', 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.deepEqual(test.result, result);
});
});
});
});