diff --git a/src/routes/v3/electrumx.js b/src/routes/v3/electrumx.js index 59a5687..8e5cc67 100644 --- a/src/routes/v3/electrumx.js +++ b/src/routes/v3/electrumx.js @@ -81,16 +81,16 @@ class Electrum { // Periodically check the connection. If it's not connected, attempt to // reconnect. - setInterval(async function () { + _this.reconnectIntervalHandle = setInterval(async function () { const status = _this.electrumx.connection.status // console.log(`Electrumx status: ${status}`) // 1 = connected. If we're not connected, attemp to reconnect. if (status !== 1) { wlogger.info(`Electrumx not connectes. Status: ${status}`) - wlogger.info(`Attempting to reconnect...`) + wlogger.info('Attempting to reconnect...') await _this.electrumx.connect() - wlogger.info(`...reconnected.`) + wlogger.info('...reconnected.') } }, 30000) @@ -111,6 +111,9 @@ class Electrum { // Return immediately if the isReady flag is false. if (!_this.isReady) return true + // Disable the reconnect timer. + clearInterval(_this.reconnectIntervalHandle) + // Disconnect from the server. await _this.electrumx.disconnect() diff --git a/test/v3/a01-electrumx.js b/test/v3/a01-electrumx.js index 0b45b88..c1f003a 100644 --- a/test/v3/a01-electrumx.js +++ b/test/v3/a01-electrumx.js @@ -42,7 +42,7 @@ function expectRouteError (res, result, expectedError, code = 400) { assert.equal(result.success, false) } -describe('#ElectrumX Router', () => { +describe('#Electrumx', () => { let req, res let sandbox const electrumxRoute = new ElecrumxRoute() diff --git a/test/v3/blockchain.js b/test/v3/blockchain.js index cba83ad..548381e 100644 --- a/test/v3/blockchain.js +++ b/test/v3/blockchain.js @@ -821,6 +821,7 @@ describe('#BlockchainRouter', () => { ]) }) }) + describe('getRawMempool()', () => { it('should throw 503 when network issues', async () => { // Save the existing RPC URL. @@ -842,6 +843,7 @@ describe('#BlockchainRouter', () => { 'Error message expected' ) }) + it('returns proper error when downstream service stalls', async () => { // Mock the timeout error. sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' }) @@ -856,6 +858,7 @@ describe('#BlockchainRouter', () => { 'Error message expected' ) }) + it('returns proper error when downstream service is down', async () => { // Mock the timeout error. sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNREFUSED' }) @@ -871,7 +874,7 @@ describe('#BlockchainRouter', () => { ) }) - it('should GET /getMempoolInfo', async () => { + it('should GET /getRawMempool', async () => { // Mock the RPC call for unit tests. if (process.env.TEST === 'unit') { sandbox @@ -886,6 +889,7 @@ describe('#BlockchainRouter', () => { // Not sure what other assertions should be made here. }) }) + describe('getMempoolEntrySingle()', () => { it('should throw 400 if txid is empty', async () => { const result = await uut.getMempoolEntrySingle(req, res)