diff --git a/lib/web3/filter.js b/lib/web3/filter.js index d6d9c77..d8f2c9c 100644 --- a/lib/web3/filter.js +++ b/lib/web3/filter.js @@ -134,8 +134,8 @@ var Filter = function (web3, options, methods, formatter, callback) { var self = this; var implementation = {}; methods.forEach(function (method) { - method.attachToObject(implementation); method.setRequestManager(web3._requestManager); + method.attachToObject(implementation); }); this.requestManager = web3._requestManager; this.options = getOptions(options); diff --git a/lib/web3/requestmanager.js b/lib/web3/requestmanager.js index 4d1c95e..f33fee2 100644 --- a/lib/web3/requestmanager.js +++ b/lib/web3/requestmanager.js @@ -40,6 +40,8 @@ var RequestManager = function (provider) { this.polls = {}; this.timeout = null; this.isPolling = false; + + this.poll(); }; /** diff --git a/lib/web3/syncing.js b/lib/web3/syncing.js index ccd7acb..a4296ce 100644 --- a/lib/web3/syncing.js +++ b/lib/web3/syncing.js @@ -20,7 +20,6 @@ * @date 2015 */ -var Method = require('./method'); var formatters = require('./formatters'); var utils = require('../utils/utils'); @@ -41,7 +40,7 @@ var pollSyncing = function(self) { } if(utils.isObject(sync)) - sync = self.implementation.outputFormatter(sync); + sync = formatters.outputSyncingFormatter(sync); self.callbacks.forEach(function (callback) { if (lastSyncState !== sync) { @@ -60,8 +59,8 @@ var pollSyncing = function(self) { }); }; - self._web3._requestManager.startPolling({ - method: self.implementation.call, + self.requestManager.startPolling({ + method: 'eth_syncing', params: [], }, self.pollId, onMessage, self.stopWatching.bind(self)); @@ -69,15 +68,9 @@ var pollSyncing = function(self) { var IsSyncing = function (web3, callback) { this._web3 = web3; + this.requestManager = web3._requestManager; this.pollId = 'syncPoll_'+ Math.floor(Math.random() * 1000); this.callbacks = []; - this.implementation = new Method({ - name: 'isSyncing', - call: 'eth_syncing', - params: 0, - outputFormatter: formatters.outputSyncingFormatter - }); - this.addCallback(callback); pollSyncing(this); diff --git a/test/web3.eth.isSyncing.js b/test/web3.eth.isSyncing.js index ba00949..005afc0 100644 --- a/test/web3.eth.isSyncing.js +++ b/test/web3.eth.isSyncing.js @@ -22,40 +22,40 @@ var tests = [{ call: 'eth_syncing' }]; -//describe('eth', function () { - //describe(method, function () { - //tests.forEach(function (test, index) { - //it('property test: ' + index, function (done) { +describe('eth', function () { + describe(method, function () { + tests.forEach(function (test, index) { + it('property test: ' + index, function (done) { + + // given + var provider = new FakeHttpProvider(); + web3.setProvider(provider); + web3.reset(); + provider.injectBatchResults(test.result); + provider.injectValidation(function(payload) { + assert.equal(payload[0].jsonrpc, '2.0', 'failed'); + assert.equal(payload[0].method, test.call); + assert.deepEqual(payload[0].params, test.formattedArgs); + }); + + var count = 1; + + // TODO results seem to be overwritten + + // call + var syncing = web3.eth[method](function(e, res){ + if(count === 1) { + assert.isTrue(res); + count++; + } else { + assert.deepEqual(res, test.formattedResult); + syncing.stopWatching(); + done(); + } + }); - //// given - //var provider = new FakeHttpProvider(); - //web3.setProvider(provider); - //web3.reset(); - //provider.injectBatchResults(test.result); - //provider.injectValidation(function (payload) { - //assert.equal(payload[0].jsonrpc, '2.0'); - //assert.equal(payload[0].method, test.call); - //assert.deepEqual(payload[0].params, test.formattedArgs); - //}); - - //var count = 1; - - //// TODO results seem to be overwritten - - //// call - //var syncing = web3.eth[method](function(e, res){ - //if(count === 1) { - //assert.isTrue(res); - //count++; - //} else { - //assert.deepEqual(res, test.formattedResult); - //syncing.stopWatching(); - //done(); - //} - //}); - - //}); - //}); - //}); -//}); + }); + }); + }); +});