diff --git a/js/src/api/api.spec.js b/js/src/api/api.spec.js index bbd140d4d..16831ea66 100644 --- a/js/src/api/api.spec.js +++ b/js/src/api/api.spec.js @@ -34,7 +34,7 @@ describe('api/Api', () => { }); describe('interface', () => { - const api = new Api(new Api.Transport.Http(TEST_HTTP_URL)); + const api = new Api(new Api.Transport.Http(TEST_HTTP_URL, -1)); Object.keys(ethereumRpc).sort().forEach((endpoint) => { describe(endpoint, () => { diff --git a/js/src/api/contract/contract.spec.js b/js/src/api/contract/contract.spec.js index 96929cc11..3d57c2afa 100644 --- a/js/src/api/contract/contract.spec.js +++ b/js/src/api/contract/contract.spec.js @@ -25,7 +25,7 @@ import Api from '../api'; import Contract from './contract'; import { isInstanceOf, isFunction } from '../util/types'; -const transport = new Api.Transport.Http(TEST_HTTP_URL); +const transport = new Api.Transport.Http(TEST_HTTP_URL, -1); const eth = new Api(transport); describe('api/contract/Contract', () => { diff --git a/js/src/api/rpc/db/db.spec.js b/js/src/api/rpc/db/db.spec.js index 4379b51c4..4a11fc416 100644 --- a/js/src/api/rpc/db/db.spec.js +++ b/js/src/api/rpc/db/db.spec.js @@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import Http from '../../transport/http'; import Db from './db'; -const instance = new Db(new Http(TEST_HTTP_URL)); +const instance = new Db(new Http(TEST_HTTP_URL, -1)); describe('api/rpc/Db', () => { let scope; diff --git a/js/src/api/rpc/eth/eth.spec.js b/js/src/api/rpc/eth/eth.spec.js index 65377db50..85d22f4bd 100644 --- a/js/src/api/rpc/eth/eth.spec.js +++ b/js/src/api/rpc/eth/eth.spec.js @@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types'; import Http from '../../transport/http'; import Eth from './eth'; -const instance = new Eth(new Http(TEST_HTTP_URL)); +const instance = new Eth(new Http(TEST_HTTP_URL, -1)); describe('rpc/Eth', () => { const address = '0x63Cf90D3f0410092FC0fca41846f596223979195'; diff --git a/js/src/api/rpc/net/net.spec.js b/js/src/api/rpc/net/net.spec.js index 55029a29e..4903a0cde 100644 --- a/js/src/api/rpc/net/net.spec.js +++ b/js/src/api/rpc/net/net.spec.js @@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types'; import Http from '../../transport/http'; import Net from './net'; -const instance = new Net(new Http(TEST_HTTP_URL)); +const instance = new Net(new Http(TEST_HTTP_URL, -1)); describe('api/rpc/Net', () => { describe('peerCount', () => { diff --git a/js/src/api/rpc/parity/parity.spec.js b/js/src/api/rpc/parity/parity.spec.js index ea0dd8d8c..557314e5c 100644 --- a/js/src/api/rpc/parity/parity.spec.js +++ b/js/src/api/rpc/parity/parity.spec.js @@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types'; import Http from '../../transport/http'; import Parity from './parity'; -const instance = new Parity(new Http(TEST_HTTP_URL)); +const instance = new Parity(new Http(TEST_HTTP_URL, -1)); describe('api/rpc/parity', () => { describe('accountsInfo', () => { diff --git a/js/src/api/rpc/personal/personal.spec.js b/js/src/api/rpc/personal/personal.spec.js index a9bf4f644..70c8cf4c2 100644 --- a/js/src/api/rpc/personal/personal.spec.js +++ b/js/src/api/rpc/personal/personal.spec.js @@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import Http from '../../transport/http'; import Personal from './personal'; -const instance = new Personal(new Http(TEST_HTTP_URL)); +const instance = new Personal(new Http(TEST_HTTP_URL, -1)); describe('rpc/Personal', () => { const account = '0x63cf90d3f0410092fc0fca41846f596223979195'; diff --git a/js/src/api/rpc/trace/trace.spec.js b/js/src/api/rpc/trace/trace.spec.js index 4a38f7a3f..f36e5537c 100644 --- a/js/src/api/rpc/trace/trace.spec.js +++ b/js/src/api/rpc/trace/trace.spec.js @@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import Http from '../../transport/http'; import Trace from './trace'; -const instance = new Trace(new Http(TEST_HTTP_URL)); +const instance = new Trace(new Http(TEST_HTTP_URL, -1)); describe('api/rpc/Trace', () => { let scope; diff --git a/js/src/api/rpc/web3/web3.spec.js b/js/src/api/rpc/web3/web3.spec.js index eb4a59cd1..b933e805b 100644 --- a/js/src/api/rpc/web3/web3.spec.js +++ b/js/src/api/rpc/web3/web3.spec.js @@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import Http from '../../transport/http'; import Web3 from './web3'; -const instance = new Web3(new Http(TEST_HTTP_URL)); +const instance = new Web3(new Http(TEST_HTTP_URL, -1)); describe('api/rpc/Web3', () => { let scope; diff --git a/js/src/api/transport/http/http.js b/js/src/api/transport/http/http.js index 08d9422f8..8ea59f0fb 100644 --- a/js/src/api/transport/http/http.js +++ b/js/src/api/transport/http/http.js @@ -19,11 +19,14 @@ import JsonRpcBase from '../jsonRpcBase'; /* global fetch */ export default class Http extends JsonRpcBase { - constructor (url) { + constructor (url, connectTimeout = 1000) { super(); this._connected = true; this._url = url; + this._connectTimeout = connectTimeout; + + this._pollConnection(); } _encodeOptions (method, params) { @@ -77,4 +80,17 @@ export default class Http extends JsonRpcBase { return response.result; }); } + + _pollConnection = () => { + if (this._connectTimeout <= 0) { + return; + } + + const nextTimeout = () => setTimeout(this._pollConnection, this._connectTimeout); + + this + .execute('net_listening') + .then(nextTimeout) + .catch(nextTimeout); + } } diff --git a/js/src/api/transport/http/http.spec.js b/js/src/api/transport/http/http.spec.js index 94441bc51..718a7e66b 100644 --- a/js/src/api/transport/http/http.spec.js +++ b/js/src/api/transport/http/http.spec.js @@ -17,7 +17,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import Http from './http'; -const transport = new Http(TEST_HTTP_URL); +const transport = new Http(TEST_HTTP_URL, -1); describe('api/transport/Http', () => { describe('instance', () => {