From c2426ad880e5ab57cd6e16419f17a2287a34c356 Mon Sep 17 00:00:00 2001 From: bas-vk Date: Mon, 12 Sep 2016 15:20:20 +0200 Subject: [PATCH] add eth_protocolVersion (#491) --- lib/web3/methods/eth.js | 4 ++++ test/web3.eth.methods.js | 1 + test/web3.eth.protocolVersion.js | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 test/web3.eth.protocolVersion.js diff --git a/lib/web3/methods/eth.js b/lib/web3/methods/eth.js index 5b44528..553d07d 100644 --- a/lib/web3/methods/eth.js +++ b/lib/web3/methods/eth.js @@ -314,6 +314,10 @@ var properties = function () { name: 'blockNumber', getter: 'eth_blockNumber', outputFormatter: utils.toDecimal + }), + new Property({ + name: 'protocolVersion', + getter: 'eth_protocolVersion' }) ]; }; diff --git a/test/web3.eth.methods.js b/test/web3.eth.methods.js index 1e6bf72..6a8dd2a 100644 --- a/test/web3.eth.methods.js +++ b/test/web3.eth.methods.js @@ -30,6 +30,7 @@ describe('web3.eth', function() { u.propertyExists(web3.eth, 'accounts'); u.propertyExists(web3.eth, 'defaultBlock'); u.propertyExists(web3.eth, 'blockNumber'); + u.propertyExists(web3.eth, 'protocolVersion'); }); }); diff --git a/test/web3.eth.protocolVersion.js b/test/web3.eth.protocolVersion.js new file mode 100644 index 0000000..bdb91fc --- /dev/null +++ b/test/web3.eth.protocolVersion.js @@ -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); + }); + }); + }); +});