mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 17:22:04 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e881b68ca5 | ||
|
|
f54c69a664 | ||
|
|
319281c096 | ||
|
|
7dee8c0604 | ||
|
|
efbcbc5deb |
@@ -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()
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user