Skip to content

Commit

Permalink
Remove unnecessary nock calls from TokenRatesController tests (#1500)
Browse files Browse the repository at this point in the history
Unnecessary `nock` calls have been removed from the
`TokenRatesController` tests. Additionally, real network requests have
been disabled for this test suite as a precaution.
  • Loading branch information
Gudahtt authored Jul 14, 2023
1 parent e40b313 commit 0f43dcf
Showing 1 changed file with 16 additions and 55 deletions.
71 changes: 16 additions & 55 deletions packages/assets-controllers/src/TokenRatesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,23 @@ import {

const COINGECKO_API = 'https://api.coingecko.com/api/v3';
const COINGECKO_ETH_PATH = '/simple/token_price/ethereum';
const COINGECKO_BSC_PATH = '/simple/token_price/binance-smart-chain';
const COINGECKO_MATIC_PATH = '/simple/token_price/polygon-pos-network';
const COINGECKO_ASSETS_PATH = '/asset_platforms';
const COINGECKO_SUPPORTED_CURRENCIES = '/simple/supported_vs_currencies';
const ADDRESS = '0x01';

describe('TokenRatesController', () => {
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.enableNetConnect();
});

let messenger: NetworkControllerMessenger;
beforeEach(() => {
nock(COINGECKO_API)
.get(COINGECKO_ASSETS_PATH)
.reply(200, [
{
id: 'binance-smart-chain',
chain_identifier: 56,
name: 'Binance Smart Chain',
shortname: 'BSC',
},
{
id: 'ethereum',
chain_identifier: 1,
name: 'Ethereum',
shortname: '',
},
{
id: 'polygon-pos-network',
chain_identifier: 137,
name: 'Polygon',
shortname: 'MATIC',
},
])
.get(
`${COINGECKO_ETH_PATH}?contract_addresses=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359,${ADDRESS}&vs_currencies=eth`,
)
.reply(200, {
'0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359': { eth: 0.00561045 },
})
.get(
`${COINGECKO_ETH_PATH}?contract_addresses=${ADDRESS}&vs_currencies=eth`,
)
.reply(200, {})
.get(`${COINGECKO_ETH_PATH}?contract_addresses=bar&vs_currencies=eth`)
.reply(200, {})
.get(
`${COINGECKO_ETH_PATH}?contract_addresses=${ADDRESS}&vs_currencies=gno`,
)
.reply(200, {})
.get(
`${COINGECKO_BSC_PATH}?contract_addresses=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359,${ADDRESS}&vs_currencies=eth`,
)
.reply(200, {
'0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359': { eth: 0.00561045 },
})
.get(`${COINGECKO_BSC_PATH}?contract_addresses=0xfoO&vs_currencies=eth`)
.reply(200, {})
.get(`${COINGECKO_BSC_PATH}?contract_addresses=bar&vs_currencies=eth`)
.reply(200, {})
.get(`${COINGECKO_BSC_PATH}?contract_addresses=0xfoO&vs_currencies=gno`)
.reply(200, {})
.get(COINGECKO_SUPPORTED_CURRENCIES)
.reply(200, ['eth', 'usd'])
.get(COINGECKO_ASSETS_PATH)
Expand All @@ -99,11 +57,6 @@ describe('TokenRatesController', () => {
])
.persist();

nock('https://min-api.cryptocompare.com')
.get('/data/price?fsym=ETH&tsyms=USD')
.reply(200, { USD: 179.63 })
.persist();

messenger = new ControllerMessenger().getRestricted({
name: 'NetworkController',
allowedEvents: ['NetworkController:stateChange'],
Expand Down Expand Up @@ -223,6 +176,14 @@ describe('TokenRatesController', () => {
});

it('should update all rates', async () => {
nock(COINGECKO_API)
.get(
`${COINGECKO_ETH_PATH}?contract_addresses=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359,${ADDRESS}&vs_currencies=eth`,
)
.reply(200, {
'0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359': { eth: 0.00561045 },
})
.persist();
new NetworkController({
infuraProjectId: 'infura-project-id',
messenger,
Expand Down

0 comments on commit 0f43dcf

Please sign in to comment.