Skip to content

Commit

Permalink
Merge pull request #92 from blockchain-certificates/feat/deprecate-ex…
Browse files Browse the repository at this point in the history
…plorers

feat(Explorers): deprecate services that don't respond anymore
  • Loading branch information
lemoustachiste authored Apr 28, 2021
2 parents 5954a13 + 6110bfb commit 77d6d90
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 17,236 deletions.
16,958 changes: 49 additions & 16,909 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/constants/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export enum TRANSACTION_APIS {
bitpay = 'bitpay',
blockcypher = 'blockcypher',
blockexplorer = 'blockexplorer',
blockstream = 'blockstream',
etherscan = 'etherscan'
}
Expand Down
41 changes: 0 additions & 41 deletions src/explorers/bitcoin/bitpay.ts

This file was deleted.

40 changes: 0 additions & 40 deletions src/explorers/bitcoin/blockexplorer.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/explorers/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { TransactionData } from '../models/transactionData';
import { ExplorerAPI, TExplorerFunctionsArray } from '../models/explorers';
import { explorerApi as EtherscanApi } from './ethereum/etherscan';
import { explorerApi as BlockCypherETHApi } from './ethereum/blockcypher';
import { explorerApi as BlockExplorerApi } from './bitcoin/blockexplorer';
import { explorerApi as BlockstreamApi } from './bitcoin/blockstream';
import { explorerApi as BlockCypherBTCApi } from './bitcoin/blockcypher';
import { explorerApi as BitPayApi } from './bitcoin/bitpay';
import { SupportedChains } from '../constants/supported-chains';

export function explorerFactory (TransactionAPIArray: ExplorerAPI[]): TExplorerFunctionsArray {
Expand Down Expand Up @@ -46,8 +44,6 @@ export async function getTransactionFromApi (

const BitcoinTransactionAPIArray = [
BlockCypherBTCApi,
BitPayApi,
BlockExplorerApi,
BlockstreamApi
];

Expand Down
36 changes: 0 additions & 36 deletions tests/explorers/bitcoin/bitpay.test.ts

This file was deleted.

36 changes: 0 additions & 36 deletions tests/explorers/bitcoin/blockexplorer.test.ts

This file was deleted.

40 changes: 20 additions & 20 deletions tests/explorers/explorer.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sinon from 'sinon';
import * as RequestService from '../../src/services/request';
import { explorerApi as BitpayAPI } from '../../src/explorers/bitcoin/bitpay';
import { explorerApi as BlockstreamAPI } from '../../src/explorers/bitcoin/blockstream';
import { explorerApi as BlockcypherAPI } from '../../src/explorers/bitcoin/blockcypher';
import * as mockBitpayResponse from './mocks/mockBitpayResponse.json';
import * as mockBlockstreamResponse from './mocks/mockBlockstreamResponse.json';
import { explorerFactory, getTransactionFromApi } from '../../src/explorers/explorer';
import { BLOCKCHAINS } from '../../src/constants/blockchains';
import { ExplorerAPI } from '../../src/models/explorers';
Expand All @@ -20,7 +20,7 @@ import { TRANSACTION_APIS } from '../../src/constants/api';

describe('Blockchain Explorers test suite', function () {
const fixtureTransactionId = '2378076e8e140012814e98a2b2cb1af07ec760b239c1d6d93ba54d658a010ecd';
const assertionRequestUrl = `https://insight.bitpay.com/api/tx/${fixtureTransactionId}`;
const assertionRequestUrl = `https://blockstream.info/api/tx/${fixtureTransactionId}`;
let stubRequest;
const assertionResponse = {
issuingAddress: '1AwdUWQzJgfDDjeKtpPzMfYMHejFBrxZfo',
Expand All @@ -30,7 +30,7 @@ describe('Blockchain Explorers test suite', function () {
};

beforeEach(function () {
stubRequest = sinon.stub(RequestService, 'request').resolves(JSON.stringify(mockBitpayResponse));
stubRequest = sinon.stub(RequestService, 'request').resolves(JSON.stringify(mockBlockstreamResponse));
});

afterEach(function () {
Expand All @@ -39,23 +39,23 @@ describe('Blockchain Explorers test suite', function () {

describe('getTransactionFromApi method', function () {
it('should call the right request API', async function () {
await getTransactionFromApi(BitpayAPI, fixtureTransactionId, BLOCKCHAINS.bitcoin.code);
await getTransactionFromApi(BlockstreamAPI, fixtureTransactionId, BLOCKCHAINS.bitcoin.code);
expect(stubRequest.getCall(0).args).toEqual([{ url: assertionRequestUrl }]);
});

describe('given the API request failed', function () {
it('should throw the right error', async function () {
const fixtureError = new Error('Unable to get remote hash');
stubRequest.rejects(fixtureError);
await expect(getTransactionFromApi(BitpayAPI, fixtureTransactionId, BLOCKCHAINS.bitcoin.code))
await expect(getTransactionFromApi(BlockstreamAPI, fixtureTransactionId, BLOCKCHAINS.bitcoin.code))
.rejects.toThrow('Unable to get remote hash');
});
});

describe('given the request is successful', function () {
describe('and the transaction data is generated from the response', function () {
it('should return a correct transaction data', async function () {
const res = await getTransactionFromApi(BitpayAPI, fixtureTransactionId, BLOCKCHAINS.bitcoin.code);
const res = await getTransactionFromApi(BlockstreamAPI, fixtureTransactionId, BLOCKCHAINS.bitcoin.code);
expect(res).toEqual(assertionResponse);
});
});
Expand All @@ -66,12 +66,12 @@ describe('Blockchain Explorers test suite', function () {
describe('given it was passed a default explorer match', function () {
it('should overwrite the data of that default explorer', function () {
const fixtureExplorer: ExplorerAPI = {
serviceName: TRANSACTION_APIS.bitpay,
serviceName: TRANSACTION_APIS.blockstream,
key: 'a-custom-key',
keyPropertyName: 'apiKey'
};

const mockDefaultExplorer: ExplorerAPI = Object.assign({}, BitpayAPI);
const mockDefaultExplorer: ExplorerAPI = Object.assign({}, BlockstreamAPI);

const output = overwriteDefaultExplorers([fixtureExplorer], [mockDefaultExplorer, BlockcypherAPI]);
expect(output.find(explorerAPI => explorerAPI.serviceName === fixtureExplorer.serviceName).key)
Expand All @@ -80,12 +80,12 @@ describe('Blockchain Explorers test suite', function () {

it('should return the list of default explorers with the one modified', function () {
const fixtureExplorer: ExplorerAPI = {
serviceName: TRANSACTION_APIS.bitpay,
serviceName: TRANSACTION_APIS.blockstream,
key: 'a-custom-key',
keyPropertyName: 'apiKey'
};

const mockDefaultExplorer: ExplorerAPI = Object.assign({}, BitpayAPI);
const mockDefaultExplorer: ExplorerAPI = Object.assign({}, BlockstreamAPI);

const output = overwriteDefaultExplorers([fixtureExplorer], [mockDefaultExplorer, BlockcypherAPI]);
const expectedOutput = [Object.assign(mockDefaultExplorer, fixtureExplorer), BlockcypherAPI];
Expand All @@ -96,13 +96,13 @@ describe('Blockchain Explorers test suite', function () {
describe('when a key is set but no keyPropertyName', function () {
it('should throw an error', function () {
const fixtureExplorer: ExplorerAPI = {
serviceName: TRANSACTION_APIS.bitpay,
serviceName: TRANSACTION_APIS.blockstream,
key: 'a-custom-key'
};

expect(() => {
overwriteDefaultExplorers([fixtureExplorer], [BitpayAPI, BlockcypherAPI]);
}).toThrow('Property keyPropertyName is not set for bitpay. Cannot pass the key property to the service.');
overwriteDefaultExplorers([fixtureExplorer], [BlockstreamAPI, BlockcypherAPI]);
}).toThrow('Property keyPropertyName is not set for blockstream. Cannot pass the key property to the service.');
});
});
});
Expand All @@ -116,8 +116,8 @@ describe('Blockchain Explorers test suite', function () {
keyPropertyName: 'apiKey'
};

const output = overwriteDefaultExplorers([fixtureExplorer], [BitpayAPI, BlockcypherAPI]);
const expectedOutput = [BitpayAPI, BlockcypherAPI];
const output = overwriteDefaultExplorers([fixtureExplorer], [BlockstreamAPI, BlockcypherAPI]);
const expectedOutput = [BlockstreamAPI, BlockcypherAPI];
expect(output).toEqual(expectedOutput);
});
});
Expand All @@ -132,7 +132,7 @@ describe('Blockchain Explorers test suite', function () {

it('should return the default explorers for bitcoin', function () {
const output = getDefaultExplorers();
expect(output.bitcoin.length).toBe(4);
expect(output.bitcoin.length).toBe(2);
});

it('should return the default explorers for ethereum', function () {
Expand All @@ -144,12 +144,12 @@ describe('Blockchain Explorers test suite', function () {
describe('and one of the custom explorers matches one of the default explorers', function () {
it('should return the same expected amount of default explorers', function () {
const fixtureExplorer: ExplorerAPI = {
serviceName: TRANSACTION_APIS.bitpay,
serviceName: TRANSACTION_APIS.blockstream,
key: 'a-custom-key',
keyPropertyName: 'apiKey'
};
const output = getDefaultExplorers([fixtureExplorer]);
expect(output.bitcoin.length).toBe(4);
expect(output.bitcoin.length).toBe(2);
expect(output.ethereum.length).toBe(2);
});
});
Expand All @@ -162,7 +162,7 @@ describe('Blockchain Explorers test suite', function () {
keyPropertyName: 'apiKey'
};
const output = getDefaultExplorers([fixtureExplorer]);
expect(output.bitcoin.length).toBe(4);
expect(output.bitcoin.length).toBe(2);
expect(output.ethereum.length).toBe(2);
});
});
Expand Down
Loading

0 comments on commit 77d6d90

Please sign in to comment.