From f4e90a0518d56fb6d12a9f7d1d17dbb828dd7536 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 14 Apr 2020 09:55:36 -0700 Subject: [PATCH] fix(electrumx integration): Fixed the integration tests by renaming file --- src/routes/v3/electrumx.js | 6 ++++++ test/v3/{electrumx.js => a01-electrumx.js} | 25 +++++++++------------- test/v3/blockbook.js | 4 +++- test/v3/blockchain.js | 1 + 4 files changed, 20 insertions(+), 16 deletions(-) rename test/v3/{electrumx.js => a01-electrumx.js} (93%) diff --git a/src/routes/v3/electrumx.js b/src/routes/v3/electrumx.js index bc2b2be..a04d782 100644 --- a/src/routes/v3/electrumx.js +++ b/src/routes/v3/electrumx.js @@ -9,7 +9,9 @@ const router = express.Router() const axios = require('axios') const util = require('util') const bitcore = require('bitcore-lib-cash') + const ElectrumCash = require('electrum-cash').Client +// const ElectrumCash = require('/home/trout/work/personal/electrum-cash/electrum.js').Client // eslint-disable-line const wlogger = require('../../util/winston-logging') const config = require('../../../config') @@ -37,6 +39,8 @@ class Electrum { '1.4.1', process.env.FULCRUM_URL, process.env.FULCRUM_PORT + // '192.168.0.6', + // '50002' ) _this.isReady = false @@ -52,6 +56,8 @@ class Electrum { try { console.log('Attempting to connect to ElectrumX server...') + // console.log('_this.electrumx: ', _this.electrumx) + // Return immediately if a connection has already been established. if (_this.isReady) return true diff --git a/test/v3/electrumx.js b/test/v3/a01-electrumx.js similarity index 93% rename from test/v3/electrumx.js rename to test/v3/a01-electrumx.js index bb174dd..875a239 100644 --- a/test/v3/electrumx.js +++ b/test/v3/a01-electrumx.js @@ -1,6 +1,11 @@ /* TESTS FOR THE ELECTRUMX.JS LIBRARY + Named with a01 prefix so that these tests are run first. Something about running + the Blcokbook and Blockchain tests screws up these tests. Spend a couple hours + debugging and couldn't isolate the source of the issue, but renaming the file + was an easy fix. + This test file uses the environment variable TEST to switch between unit and integration tests. By default, TEST is set to 'unit'. Set this variable to 'integration' to run the tests against BCH mainnet. @@ -15,15 +20,6 @@ const assert = chai.assert const sinon = require('sinon') -let originalUrl // Used during transition from integration to unit tests. - -// Set default environment variables for unit tests. -if (!process.env.TEST) process.env.TEST = 'unit' -if (process.env.TEST === 'unit') { - process.env.BLOCKBOOK_URL = 'http://fakeurl/api/' -} - -// Only load blockbook library after setting BLOCKBOOK_URL env var. const ElecrumxRoute = require('../../src/routes/v3/electrumx') const electrumxRoute = new ElecrumxRoute() @@ -52,6 +48,8 @@ describe('#ElectrumX Router', () => { }) after(async () => { + // console.log(`electrumxRoute.electrumx: `, electrumxRoute.electrumx) + // Disconnect from the electrumx server if this is an integration test. if (process.env.TEST === 'integration') { await electrumxRoute.disconnect() @@ -78,7 +76,7 @@ describe('#ElectrumX Router', () => { }) after(() => { - process.env.BLOCKBOOK_URL = originalUrl + // }) describe('#root', () => { @@ -236,16 +234,13 @@ describe('#ElectrumX Router', () => { it('should return empty array for address with no utxos', async () => { // Address has invalid checksum. - const address = - 'bchtest:qqtmlpspjakqlvywae226esrcdrj9auynuwadh55uf' + const address = 'bchtest:qqtmlpspjakqlvywae226esrcdrj9auynuwadh55uf' // Mock unit tests to prevent live network calls. if (process.env.TEST === 'unit') { electrumxRoute.isReady = true // Force flag. - sandbox - .stub(electrumxRoute.electrumx, 'request') - .resolves([]) + sandbox.stub(electrumxRoute.electrumx, 'request').resolves([]) } // Call the details API. diff --git a/test/v3/blockbook.js b/test/v3/blockbook.js index 7b4ac71..eab7e70 100644 --- a/test/v3/blockbook.js +++ b/test/v3/blockbook.js @@ -15,7 +15,9 @@ const assert = chai.assert const sinon = require('sinon') -let originalUrl // Used during transition from integration to unit tests. +// Used during transition from integration to unit tests. +// let originalUrl +const originalUrl = process.env.BLOCKBOOK_URL // Set default environment variables for unit tests. if (!process.env.TEST) process.env.TEST = 'unit' diff --git a/test/v3/blockchain.js b/test/v3/blockchain.js index 0675499..fcebf9e 100644 --- a/test/v3/blockchain.js +++ b/test/v3/blockchain.js @@ -499,6 +499,7 @@ describe('#BlockchainRouter', () => { process.env.BITCOINCOM_BASEURL = savedUrl } }) + it('returns proper error when downstream service stalls', async () => { // Mock the timeout error. sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' })