Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) remove non-Ethereum network tests #311

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 2 additions & 209 deletions test/network/network.routes.test.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,18 @@
import request from 'supertest';
import { gatewayApp } from '../../src/app';
import { Avalanche } from '../../src/chains/avalanche/avalanche';
import { Cronos } from '../../src/chains/cronos/cronos';
import { Ethereum } from '../../src/chains/ethereum/ethereum';
import { Harmony } from '../../src/chains/harmony/harmony';
import { Polygon } from '../../src/chains/polygon/polygon';
import { patchEVMNonceManager } from '../evm.nonce.mock';
import { patch, unpatch } from '../services/patch';
let eth: Ethereum;
let goerli: Ethereum;
let avalanche: Avalanche;
let harmony: Harmony;
let polygon: Polygon;
let cronos: Cronos;

beforeAll(async () => {
eth = Ethereum.getInstance('goerli');
patchEVMNonceManager(eth.nonceManager);
await eth.init();

goerli = Ethereum.getInstance('goerli');
patchEVMNonceManager(goerli.nonceManager);
await goerli.init();

avalanche = Avalanche.getInstance('fuji');
patchEVMNonceManager(avalanche.nonceManager);
await avalanche.init();

harmony = Harmony.getInstance('testnet');
await harmony.init();

polygon = Polygon.getInstance('mumbai');
await polygon.init();

cronos = Cronos.getInstance('testnet');
await cronos.init();
});

beforeEach(() => {
patchEVMNonceManager(eth.nonceManager);
patchEVMNonceManager(goerli.nonceManager);
patchEVMNonceManager(avalanche.nonceManager);
patchEVMNonceManager(harmony.nonceManager);
patchEVMNonceManager(polygon.nonceManager);
patchEVMNonceManager(cronos.nonceManager);
});

afterEach(async () => {
Expand All @@ -52,44 +21,16 @@ afterEach(async () => {

afterAll(async () => {
await eth.close();
await goerli.close();
await avalanche.close();
await harmony.close();
await polygon.close();
await cronos.close();
});

describe('GET /chain/status', () => {
it('should return 200 when asking for harmony network status', async () => {
patch(harmony, 'chain', () => {
return 'testnet';
});
patch(harmony, 'rpcUrl', 'http://...');
patch(harmony, 'chainId', 88);
patch(harmony, 'getCurrentBlockNumber', () => {
return 3;
});

await request(gatewayApp)
.get(`/chain/status`)
.query({
chain: 'harmony',
network: 'testnet',
})
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => expect(res.body.chain).toBe('testnet'))
.expect((res) => expect(res.body.chainId).toBeDefined())
.expect((res) => expect(res.body.rpcUrl).toBeDefined())
.expect((res) => expect(res.body.currentBlockNumber).toBeDefined());
});

it('should return 200 when asking for ethereum network status', async () => {
it('should return 200 when asking for goerli network status', async () => {
patch(eth, 'chain', () => {
return 'goerli';
});
patch(eth, 'rpcUrl', 'http://...');
patch(eth, 'chainId', 34);
patch(eth, 'chainId', 5);
patch(eth, 'getCurrentBlockNumber', () => {
return 1;
});
Expand All @@ -108,114 +49,11 @@ describe('GET /chain/status', () => {
.expect((res) => expect(res.body.currentBlockNumber).toBeDefined());
});

it('should return 200 when asking for goerli network status', async () => {
patch(goerli, 'chain', () => {
return 'goerli';
});
patch(goerli, 'rpcUrl', 'http://...');
patch(goerli, 'chainId', 5);
patch(goerli, 'getCurrentBlockNumber', () => {
return 1;
});

await request(gatewayApp)
.get(`/chain/status`)
.query({
chain: 'ethereum',
network: 'goerli',
})
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => expect(res.body.chain).toBe('goerli'))
.expect((res) => expect(res.body.chainId).toBeDefined())
.expect((res) => expect(res.body.rpcUrl).toBeDefined())
.expect((res) => expect(res.body.currentBlockNumber).toBeDefined());
});

it('should return 200 when asking for avalance network status', async () => {
patch(avalanche, 'chain', () => {
return 'fuji';
});
patch(avalanche, 'rpcUrl', 'http://...');
patch(avalanche, 'chainId', 20);
patch(avalanche, 'getCurrentBlockNumber', () => {
return 2;
});

await request(gatewayApp)
.get(`/chain/status`)
.query({
chain: 'avalanche',
network: 'fuji',
})
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => expect(res.body.chain).toBe('fuji'))
.expect((res) => expect(res.body.chainId).toBeDefined())
.expect((res) => expect(res.body.rpcUrl).toBeDefined())
.expect((res) => expect(res.body.currentBlockNumber).toBeDefined());
});

it('should return 200 when asking for polygon network status', async () => {
patch(polygon, 'chain', () => {
return 'mumbai';
});
patch(polygon, 'rpcUrl', 'http://...');
patch(polygon, 'chainId', 80001);
patch(polygon, 'getCurrentBlockNumber', () => {
return 2;
});

await request(gatewayApp)
.get(`/chain/status`)
.query({
chain: 'polygon',
network: 'mumbai',
})
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => expect(res.body.chain).toBe('mumbai'))
.expect((res) => expect(res.body.chainId).toBeDefined())
.expect((res) => expect(res.body.rpcUrl).toBeDefined())
.expect((res) => expect(res.body.currentBlockNumber).toBeDefined());
});

it('should return 200 when asking for cronos network status', async () => {
patch(cronos, 'chain', () => {
return 'testnet';
});
patch(cronos, 'rpcUrl', 'http://...');
patch(cronos, 'chainId', 338);
patch(cronos, 'getCurrentBlockNumber', () => {
return 2;
});

await request(gatewayApp)
.get(`/chain/status`)
.query({
chain: 'cronos',
network: 'testnet',
})
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => expect(res.body.chain).toBe('testnet'))
.expect((res) => expect(res.body.chainId).toBeDefined())
.expect((res) => expect(res.body.rpcUrl).toBeDefined())
.expect((res) => expect(res.body.currentBlockNumber).toBeDefined());
});

it('should return 200 when requesting network status without specifying', async () => {
patch(eth, 'getCurrentBlockNumber', () => {
return 212;
});

patch(avalanche, 'getCurrentBlockNumber', () => {
return 204;
});
patch(harmony, 'getCurrentBlockNumber', () => {
return 100;
});

await request(gatewayApp)
.get(`/chain/status`)
.expect('Content-Type', /json/)
Expand Down Expand Up @@ -289,51 +127,6 @@ describe('GET /chain/tokens', () => {
.expect(200);
});

it('should return 200 when retrieving polygon-mumbai tokens, tokenSymbols parameter not provided', async () => {
await request(gatewayApp)
.get(`/chain/tokens`)
.query({
chain: 'polygon',
network: 'mumbai',
})
.expect('Content-Type', /json/)
.expect(200);
});

it('should return 200 when retrieving polygon-mumbai tokens, tokenSymbols parameter provided', async () => {
await request(gatewayApp)
.get(`/chain/tokens`)
.query({
chain: 'polygon',
network: 'mumbai',
tokenSymbols: ['WMATIC', 'WETH'],
})
.expect('Content-Type', /json/)
.expect(200);
});

it('should return 200 when retrieving cronos-testnet tokens, tokenSymbols parameter not provided', async () => {
await request(gatewayApp)
.get(`/chain/tokens`)
.query({
chain: 'cronos',
network: 'testnet',
})
.expect('Content-Type', /json/)
.expect(200);
});

it('should return 200 when retrieving cronos-testnet tokens, tokenSymbols parameter provided', async () => {
await request(gatewayApp)
.get(`/chain/tokens`)
.query({
chain: 'cronos',
network: 'testnet',
tokenSymbols: ['WCRO', 'WETH'],
})
.expect('Content-Type', /json/)
.expect(200);
});

it('should return 503 when retrieving tokens for invalid chain', async () => {
await request(gatewayApp)
Expand Down
Loading
Loading