Compare commits

..
5 Commits
Author SHA1 Message Date
Chris Troutner e881b68ca5 Merge pull request #65 from Permissionless-Software-Foundation/ct-unstable
ix(electrumx): Fixed connect/disconnect bug that was preventing tests
2020-11-21 11:39:05 -08:00
Chris Troutner f54c69a664 Fixing test typo 2020-11-21 11:35:01 -08:00
Chris Troutner 319281c096 fix(electrumx): Fixed connect/disconnect bug that was preventing tests 2020-11-21 11:29:18 -08:00
Chris Troutner 7dee8c0604 Merge branch 'master' into ct-unstable 2020-11-21 11:15:41 -08:00
Chris Troutner efbcbc5deb linting 2020-11-21 11:15:33 -08:00
3 changed files with 12 additions and 5 deletions
+6 -3
View File
@@ -81,16 +81,16 @@ class Electrum {
// Periodically check the connection. If it's not connected, attempt to // Periodically check the connection. If it's not connected, attempt to
// reconnect. // reconnect.
setInterval(async function () { _this.reconnectIntervalHandle = setInterval(async function () {
const status = _this.electrumx.connection.status const status = _this.electrumx.connection.status
// console.log(`Electrumx status: ${status}`) // console.log(`Electrumx status: ${status}`)
// 1 = connected. If we're not connected, attemp to reconnect. // 1 = connected. If we're not connected, attemp to reconnect.
if (status !== 1) { if (status !== 1) {
wlogger.info(`Electrumx not connectes. Status: ${status}`) wlogger.info(`Electrumx not connectes. Status: ${status}`)
wlogger.info(`Attempting to reconnect...`) wlogger.info('Attempting to reconnect...')
await _this.electrumx.connect() await _this.electrumx.connect()
wlogger.info(`...reconnected.`) wlogger.info('...reconnected.')
} }
}, 30000) }, 30000)
@@ -111,6 +111,9 @@ class Electrum {
// Return immediately if the isReady flag is false. // Return immediately if the isReady flag is false.
if (!_this.isReady) return true if (!_this.isReady) return true
// Disable the reconnect timer.
clearInterval(_this.reconnectIntervalHandle)
// Disconnect from the server. // Disconnect from the server.
await _this.electrumx.disconnect() await _this.electrumx.disconnect()
+1 -1
View File
@@ -42,7 +42,7 @@ function expectRouteError (res, result, expectedError, code = 400) {
assert.equal(result.success, false) assert.equal(result.success, false)
} }
describe('#ElectrumX Router', () => { describe('#Electrumx', () => {
let req, res let req, res
let sandbox let sandbox
const electrumxRoute = new ElecrumxRoute() const electrumxRoute = new ElecrumxRoute()
+5 -1
View File
@@ -821,6 +821,7 @@ describe('#BlockchainRouter', () => {
]) ])
}) })
}) })
describe('getRawMempool()', () => { describe('getRawMempool()', () => {
it('should throw 503 when network issues', async () => { it('should throw 503 when network issues', async () => {
// Save the existing RPC URL. // Save the existing RPC URL.
@@ -842,6 +843,7 @@ describe('#BlockchainRouter', () => {
'Error message expected' 'Error message expected'
) )
}) })
it('returns proper error when downstream service stalls', async () => { it('returns proper error when downstream service stalls', async () => {
// Mock the timeout error. // Mock the timeout error.
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' }) sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' })
@@ -856,6 +858,7 @@ describe('#BlockchainRouter', () => {
'Error message expected' 'Error message expected'
) )
}) })
it('returns proper error when downstream service is down', async () => { it('returns proper error when downstream service is down', async () => {
// Mock the timeout error. // Mock the timeout error.
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNREFUSED' }) 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. // Mock the RPC call for unit tests.
if (process.env.TEST === 'unit') { if (process.env.TEST === 'unit') {
sandbox sandbox
@@ -886,6 +889,7 @@ describe('#BlockchainRouter', () => {
// Not sure what other assertions should be made here. // Not sure what other assertions should be made here.
}) })
}) })
describe('getMempoolEntrySingle()', () => { describe('getMempoolEntrySingle()', () => {
it('should throw 400 if txid is empty', async () => { it('should throw 400 if txid is empty', async () => {
const result = await uut.getMempoolEntrySingle(req, res) const result = await uut.getMempoolEntrySingle(req, res)