From 1ba268a456b47d2d89bbbdd2a9e3affd72b43809 Mon Sep 17 00:00:00 2001 From: Michael Feng Date: Thu, 25 Jul 2024 13:13:31 -0700 Subject: [PATCH] (fix) fix tests --- .../uniswap/bsc.uniswap.lp.routes.test.ts | 442 ------------ .../uniswap/bsc.uniswap.routes.test.ts | 678 ------------------ .../connectors/uniswap/uniswap.routes.test.ts | 2 +- 3 files changed, 1 insertion(+), 1121 deletions(-) delete mode 100644 test/connectors/uniswap/bsc.uniswap.lp.routes.test.ts delete mode 100644 test/connectors/uniswap/bsc.uniswap.routes.test.ts diff --git a/test/connectors/uniswap/bsc.uniswap.lp.routes.test.ts b/test/connectors/uniswap/bsc.uniswap.lp.routes.test.ts deleted file mode 100644 index 94892f403d..0000000000 --- a/test/connectors/uniswap/bsc.uniswap.lp.routes.test.ts +++ /dev/null @@ -1,442 +0,0 @@ -import express from 'express'; -import { Express } from 'express-serve-static-core'; -import request from 'supertest'; -import { UniswapLP } from '../../../src/connectors/uniswap/uniswap.lp'; -import { AmmLiquidityRoutes } from '../../../src/amm/amm.routes'; -import { patch, unpatch } from '../../../test/services/patch'; -import { patchEVMNonceManager } from '../../evm.nonce.mock'; -import {BinanceSmartChain} from "../../../src/chains/binance-smart-chain/binance-smart-chain"; - -let app: Express; -let binanceSmartChain: BinanceSmartChain; -let uniswap: UniswapLP; - -beforeAll(async () => { - app = express(); - app.use(express.json()); - binanceSmartChain = BinanceSmartChain.getInstance('mainnet'); - patchEVMNonceManager(binanceSmartChain.nonceManager); - await binanceSmartChain.init(); - - uniswap = UniswapLP.getInstance('binance-smart-chain', 'mainnet'); - await uniswap.init(); - app.use('/amm/liquidity', AmmLiquidityRoutes.router); -}); - -beforeEach(() => { - patchEVMNonceManager(binanceSmartChain.nonceManager); -}); - -afterEach(() => { - unpatch(); -}); - -afterAll(async () => { - await binanceSmartChain.close(); -}); - -const address: string = '0x242532ebDfcc760f2Ddfe8378eB51f5F847CE5bD'; - -const patchGetWallet = () => { - patch(binanceSmartChain, 'getWallet', () => { - return { - address: address, - }; - }); -}; - -const patchInit = () => { - patch(uniswap, 'init', async () => { - return; - }); -}; - -const patchStoredTokenList = () => { - patch(binanceSmartChain, 'tokenList', () => { - return [ - { - chainId: 56, - name: 'WBNB', - symbol: 'WBNB', - address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', - decimals: 18, - }, - { - chainId: 56, - name: 'DAI', - symbol: 'DAI', - address: '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', - decimals: 18, - }, - ]; - }); -}; - -const patchGetTokenBySymbol = () => { - patch(binanceSmartChain, 'getTokenBySymbol', (symbol: string) => { - if (symbol === 'WBNB') { - return { - chainId: 56, - name: 'WBNB', - symbol: 'WBNB', - address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', - decimals: 18, - }; - } else { - return { - chainId: 56, - name: 'DAI', - symbol: 'DAI', - address: '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', - decimals: 18, - }; - } - }); -}; - -const patchGetTokenByAddress = () => { - patch(uniswap, 'getTokenByAddress', () => { - return { - chainId: 56, - name: 'WBNB', - symbol: 'WBNB', - address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', - decimals: 18, - }; - }); -}; - -const patchGasPrice = () => { - patch(binanceSmartChain, 'gasPrice', () => 100); -}; - -const patchGetNonce = () => { - patch(binanceSmartChain.nonceManager, 'getNonce', () => 21); -}; - -const patchAddPosition = () => { - patch(uniswap, 'addPosition', () => { - return { nonce: 21, hash: '000000000000000' }; - }); -}; - -const patchRemovePosition = () => { - patch(uniswap, 'reducePosition', () => { - return { nonce: 21, hash: '000000000000000' }; - }); -}; - -const patchCollectFees = () => { - patch(uniswap, 'collectFees', () => { - return { nonce: 21, hash: '000000000000000' }; - }); -}; - -const patchPosition = () => { - patch(uniswap, 'getPosition', () => { - return { - token0: 'DAI', - token1: 'WBNB', - fee: 300, - lowerPrice: '1', - upperPrice: '5', - amount0: '1', - amount1: '1', - unclaimedToken0: '1', - unclaimedToken1: '1', - }; - }); -}; - -describe('POST /liquidity/add', () => { - it('should return 200 when all parameter are OK', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patchGasPrice(); - patchAddPosition(); - patchGetNonce(); - - await request(app) - .post(`/amm/liquidity/add`) - .send({ - address: address, - token0: 'DAI', - token1: 'WBNB', - amount0: '1', - amount1: '1', - fee: 'LOW', - lowerPrice: '1', - upperPrice: '5', - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - it('should return 500 for unrecognized token0 symbol', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - - await request(app) - .post(`/amm/liquidity/add`) - .send({ - address: address, - token0: 'DOGE', - token1: 'WBNB', - amount0: '1', - amount1: '1', - fee: 'LOW', - lowerPrice: '1', - upperPrice: '5', - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(500); - }); - - it('should return 404 for invalid fee tier', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - - await request(app) - .post(`/amm/liquidity/add`) - .send({ - address: address, - token0: 'DAI', - token1: 'WBNB', - amount0: '1', - amount1: '1', - fee: 300, - lowerPrice: '1', - upperPrice: '5', - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(404); - }); - - it('should return 500 when the helper operation fails', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patch(uniswap, 'addPositionHelper', () => { - return 'error'; - }); - - await request(app) - .post(`/amm/liquidity/add`) - .send({ - address: address, - token0: 'DAI', - token1: 'WBNB', - amount0: '1', - amount1: '1', - fee: 'LOW', - lowerPrice: '1', - upperPrice: '5', - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(500); - }); -}); - -describe('POST /liquidity/remove', () => { - const patchForBuy = () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patchGasPrice(); - patchRemovePosition(); - patchGetNonce(); - }; - it('should return 200 when all parameter are OK', async () => { - patchForBuy(); - await request(app) - .post(`/amm/liquidity/remove`) - .send({ - address: address, - tokenId: 2732, - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - it('should return 404 when the tokenId is invalid', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - - await request(app) - .post(`/amm/liquidity/remove`) - .send({ - address: address, - tokenId: 'Invalid', - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(404); - }); -}); - -describe('POST /liquidity/collect_fees', () => { - const patchForBuy = () => { - patchGetWallet(); - patchInit(); - patchGasPrice(); - patchCollectFees(); - patchGetNonce(); - }; - it('should return 200 when all parameter are OK', async () => { - patchForBuy(); - await request(app) - .post(`/amm/liquidity/collect_fees`) - .send({ - address: address, - tokenId: 2732, - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - it('should return 404 when the tokenId is invalid', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - - await request(app) - .post(`/amm/liquidity/collect_fees`) - .send({ - address: address, - tokenId: 'Invalid', - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(404); - }); -}); - -describe('POST /liquidity/position', () => { - it('should return 200 when all parameter are OK', async () => { - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patchPosition(); - - await request(app) - .post(`/amm/liquidity/position`) - .send({ - tokenId: 2732, - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - it('should return 404 when the tokenId is invalid', async () => { - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - - await request(app) - .post(`/amm/liquidity/position`) - .send({ - tokenId: 'Invalid', - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(404); - }); -}); - -describe('POST /liquidity/price', () => { - const patchForBuy = () => { - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patch(uniswap, 'poolPrice', () => { - return ['100', '105']; - }); - }; - it('should return 200 when all parameter are OK', async () => { - patchForBuy(); - await request(app) - .post(`/amm/liquidity/price`) - .send({ - token0: 'DAI', - token1: 'WBNB', - fee: 'LOW', - period: 120, - interval: 60, - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - it('should return 404 when the fee is invalid', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - - await request(app) - .post(`/amm/liquidity/price`) - .send({ - token0: 'DAI', - token1: 'WBNB', - fee: 11, - period: 120, - interval: 60, - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswapLP', - }) - .set('Accept', 'application/json') - .expect(404); - }); -}); diff --git a/test/connectors/uniswap/bsc.uniswap.routes.test.ts b/test/connectors/uniswap/bsc.uniswap.routes.test.ts deleted file mode 100644 index 66a733cd63..0000000000 --- a/test/connectors/uniswap/bsc.uniswap.routes.test.ts +++ /dev/null @@ -1,678 +0,0 @@ -import express from 'express'; -import { Express } from 'express-serve-static-core'; -import request from 'supertest'; -import { Uniswap } from '../../../src/connectors/uniswap/uniswap'; -import { AmmRoutes } from '../../../src/amm/amm.routes'; -import { patch, unpatch } from '../../../test/services/patch'; -import { gasCostInEthString } from '../../../src/services/base'; -import { patchEVMNonceManager } from '../../evm.nonce.mock'; -import {BinanceSmartChain} from "../../../src/chains/binance-smart-chain/binance-smart-chain"; -let app: Express; -let binanceSmartChain: BinanceSmartChain; -let uniswap: Uniswap; - -beforeAll(async () => { - app = express(); - app.use(express.json()); - - binanceSmartChain = BinanceSmartChain.getInstance('mainnet'); - patchEVMNonceManager(binanceSmartChain.nonceManager); - await binanceSmartChain.init(); - - uniswap = Uniswap.getInstance('binance-smart-chain', 'mainnet'); - await uniswap.init(); - - app.use('/amm', AmmRoutes.router); -}); - -beforeEach(() => { - patchEVMNonceManager(binanceSmartChain.nonceManager); -}); - -afterEach(() => { - unpatch(); -}); - -afterAll(async () => { - await binanceSmartChain.close(); -}); - -const address: string = '0x242532ebDfcc760f2Ddfe8378eB51f5F847CE5bD'; - -const patchGetWallet = () => { - patch(binanceSmartChain, 'getWallet', () => { - return { - address: address, - }; - }); -}; - -const patchInit = () => { - patch(uniswap, 'init', async () => { - return; - }); -}; - -const patchStoredTokenList = () => { - patch(binanceSmartChain, 'tokenList', () => { - return [ - { - chainId: 56, - name: 'WBNB', - symbol: 'WBNB', - address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', - decimals: 18, - }, - { - chainId: 56, - name: 'DAI', - symbol: 'DAI', - address: '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', - decimals: 18, - }, - ]; - }); -}; - -const patchGetTokenBySymbol = () => { - patch(binanceSmartChain, 'getTokenBySymbol', (symbol: string) => { - if (symbol === 'WBNB') { - return { - chainId: 56, - name: 'WBNB', - symbol: 'WBNB', - address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', - decimals: 18, - }; - } else { - return { - chainId: 56, - name: 'DAI', - symbol: 'DAI', - address: '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', - decimals: 18, - }; - } - }); -}; - -const patchGetTokenByAddress = () => { - patch(binanceSmartChain, 'getTokenByAddress', () => { - return { - chainId: 56, - name: 'WBNB', - symbol: 'WBNB', - address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', - decimals: 18, - }; - }); -}; - -const patchGasPrice = () => { - patch(binanceSmartChain, 'gasPrice', () => 100); -}; - -const patchEstimateBuyTrade = () => { - patch(uniswap, 'estimateBuyTrade', () => { - return { - expectedAmount: { - toSignificant: () => 100, - }, - trade: { - executionPrice: { - invert: jest.fn().mockReturnValue({ - toSignificant: () => 100, - toFixed: () => '100', - }), - }, - }, - }; - }); -}; - -const patchEstimateSellTrade = () => { - patch(uniswap, 'estimateSellTrade', () => { - return { - expectedAmount: { - toSignificant: () => 100, - }, - trade: { - executionPrice: { - toSignificant: () => 100, - toFixed: () => '100', - }, - }, - }; - }); -}; - -const patchGetNonce = () => { - patch(binanceSmartChain.nonceManager, 'getNonce', () => 21); -}; - -const patchExecuteTrade = () => { - patch(uniswap, 'executeTrade', () => { - return { nonce: 21, hash: '000000000000000' }; - }); -}; - -describe('POST /amm/price', () => { - it('should return 200 for BUY', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patchGasPrice(); - patchEstimateBuyTrade(); - patchGetNonce(); - patchExecuteTrade(); - - await request(app) - .post(`/amm/price`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - side: 'BUY', - }) - .set('Accept', 'application/json') - .expect(200) - .then((res: any) => { - expect(res.body.amount).toEqual('10000.000000000000000000'); - expect(res.body.rawAmount).toEqual('10000000000000000000000'); - }); - }); - - it('should return 200 for SELL', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patchGasPrice(); - patchEstimateSellTrade(); - patchGetNonce(); - patchExecuteTrade(); - - await request(app) - .post(`/amm/price`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - side: 'SELL', - }) - .set('Accept', 'application/json') - .expect(200) - .then((res: any) => { - expect(res.body.amount).toEqual('10000.000000000000000000'); - expect(res.body.rawAmount).toEqual('10000000000000000000000'); - }); - }); - - it('should return 500 for unrecognized quote symbol', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - - await request(app) - .post(`/amm/price`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DOGE', - base: 'WBNB', - amount: '10000', - side: 'SELL', - }) - .set('Accept', 'application/json') - .expect(500); - }); - - it('should return 500 for unrecognized base symbol', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - - await request(app) - .post(`/amm/price`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'SHIBA', - amount: '10000', - side: 'SELL', - }) - .set('Accept', 'application/json') - .expect(500); - }); - - it('should return 500 for unrecognized base symbol with decimals in the amount and SELL', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - - await request(app) - .post(`/amm/price`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'SHIBA', - amount: '10.000', - side: 'SELL', - }) - .set('Accept', 'application/json') - .expect(500); - }); - - it('should return 500 for unrecognized base symbol with decimals in the amount and BUY', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - - await request(app) - .post(`/amm/price`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'SHIBA', - amount: '10.000', - side: 'BUY', - }) - .set('Accept', 'application/json') - .expect(500); - }); - - it('should return 500 when the priceSwapIn operation fails', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patch(uniswap, 'priceSwapIn', () => { - return 'error'; - }); - - await request(app) - .post(`/amm/price`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DOGE', - base: 'WBNB', - amount: '10000', - side: 'SELL', - }) - .set('Accept', 'application/json') - .expect(500); - }); - - it('should return 500 when the priceSwapOut operation fails', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patch(uniswap, 'priceSwapOut', () => { - return 'error'; - }); - - await request(app) - .post(`/amm/price`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DOGE', - base: 'WBNB', - amount: '10000', - side: 'BUY', - }) - .set('Accept', 'application/json') - .expect(500); - }); -}); - -describe('POST /amm/trade', () => { - const patchForBuy = () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patchGasPrice(); - patchEstimateBuyTrade(); - patchGetNonce(); - patchExecuteTrade(); - }; - it('should return 200 for BUY', async () => { - patchForBuy(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'BUY', - nonce: 21, - }) - .set('Accept', 'application/json') - .expect(200) - .then((res: any) => { - expect(res.body.nonce).toEqual(21); - }); - }); - - it('should return 200 for BUY without nonce parameter', async () => { - patchForBuy(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'BUY', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - it('should return 200 for BUY with maxFeePerGas and maxPriorityFeePerGas', async () => { - patchForBuy(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'BUY', - nonce: 21, - maxFeePerGas: '5000000000', - maxPriorityFeePerGas: '5000000000', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - const patchForSell = () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patchGasPrice(); - patchEstimateSellTrade(); - patchGetNonce(); - patchExecuteTrade(); - }; - it('should return 200 for SELL', async () => { - patchForSell(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'SELL', - nonce: 21, - }) - .set('Accept', 'application/json') - .expect(200) - .then((res: any) => { - expect(res.body.nonce).toEqual(21); - }); - }); - - it('should return 200 for SELL with maxFeePerGas and maxPriorityFeePerGas', async () => { - patchForSell(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'SELL', - nonce: 21, - maxFeePerGas: '5000000000', - maxPriorityFeePerGas: '5000000000', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - it('should return 200 for SELL with limitPrice', async () => { - patchForSell(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'SELL', - nonce: 21, - limitPrice: '9', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - it('should return 200 for BUY with limitPrice', async () => { - patchForBuy(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'BUY', - nonce: 21, - limitPrice: '999999999999999999999', - }) - .set('Accept', 'application/json') - .expect(200); - }); - - it('should return 500 for BUY with price smaller than limitPrice', async () => { - patchForBuy(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'BUY', - nonce: 21, - limitPrice: '9', - }) - .set('Accept', 'application/json') - .expect(500); - }); - - it('should return 500 for SELL with price higher than limitPrice', async () => { - patchForSell(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'SELL', - nonce: 21, - limitPrice: '99999999999', - }) - .set('Accept', 'application/json') - .expect(500); - }); - - it('should return 404 when parameters are incorrect', async () => { - patchInit(); - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: 10000, - address: 'da8', - side: 'comprar', - }) - .set('Accept', 'application/json') - .expect(404); - }); - it('should return 500 when the priceSwapIn operation fails', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patch(uniswap, 'priceSwapIn', () => { - return 'error'; - }); - - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'SELL', - nonce: 21, - maxFeePerGas: '5000000000', - maxPriorityFeePerGas: '5000000000', - }) - .set('Accept', 'application/json') - .expect(500); - }); - - it('should return 500 when the priceSwapOut operation fails', async () => { - patchGetWallet(); - patchInit(); - patchStoredTokenList(); - patchGetTokenBySymbol(); - patchGetTokenByAddress(); - patch(uniswap, 'priceSwapOut', () => { - return 'error'; - }); - - await request(app) - .post(`/amm/trade`) - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - quote: 'DAI', - base: 'WBNB', - amount: '10000', - address, - side: 'BUY', - nonce: 21, - maxFeePerGas: '5000000000', - maxPriorityFeePerGas: '5000000000', - }) - .set('Accept', 'application/json') - .expect(500); - }); -}); - -describe('POST /amm/estimateGas', () => { - it('should return 200 for valid connector', async () => { - patchInit(); - patchGasPrice(); - - await request(app) - .post('/amm/estimateGas') - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'uniswap', - }) - .set('Accept', 'application/json') - .expect(200) - .then((res: any) => { - expect(res.body.network).toEqual('mainnet'); - expect(res.body.gasPrice).toEqual(100); - expect(res.body.gasCost).toEqual( - gasCostInEthString(100, uniswap.gasLimitEstimate) - ); - }); - }); - - it('should return 500 for invalid connector', async () => { - patchInit(); - patchGasPrice(); - - await request(app) - .post('/amm/estimateGas') - .send({ - chain: 'binance-smart-chain', - network: 'mainnet', - connector: 'pangolin', - }) - .set('Accept', 'application/json') - .expect(500); - }); -}); diff --git a/test/connectors/uniswap/uniswap.routes.test.ts b/test/connectors/uniswap/uniswap.routes.test.ts index 642aeaf514..6be897a18f 100644 --- a/test/connectors/uniswap/uniswap.routes.test.ts +++ b/test/connectors/uniswap/uniswap.routes.test.ts @@ -670,7 +670,7 @@ describe('POST /amm/estimateGas', () => { .send({ chain: 'ethereum', network: 'goerli', - connector: 'pangolin', + connector: 'plenty', }) .set('Accept', 'application/json') .expect(500);