diff --git a/ui/ducks/bridge/selectors.test.ts b/ui/ducks/bridge/selectors.test.ts index 2b9e81b24ec4..2497f8eb7148 100644 --- a/ui/ducks/bridge/selectors.test.ts +++ b/ui/ducks/bridge/selectors.test.ts @@ -495,10 +495,17 @@ describe('Bridge selectors', () => { describe('getBridgeQuotes', () => { it('returns quote list and fetch data, insufficientBal=false,quotesRefreshCount=5', () => { const state = createBridgeMockStore( - { extensionConfig: { maxRefreshCount: 5 } }, { - toChainId: '0x1', + extensionConfig: { + maxRefreshCount: 5, + }, + destNetworkAllowlist: ['0x89'], + }, + { + toChainId: '0x89', fromTokenExchangeRate: 1, + fromToken: { address: zeroAddress(), symbol: 'TEST' }, + toToken: { address: zeroAddress(), symbol: 'TEST' }, toTokenExchangeRate: 0.99, toNativeExchangeRate: 0.354073, }, @@ -516,8 +523,20 @@ describe('Bridge selectors', () => { currencyRates: { ETH: { conversionRate: 1, + usdConversionRate: 1, + }, + POL: { + conversionRate: 1, + usdConversionRate: 1, }, }, + marketData: {}, + ...mockNetworkState( + { chainId: CHAIN_IDS.MAINNET }, + { chainId: CHAIN_IDS.LINEA_MAINNET }, + { chainId: CHAIN_IDS.POLYGON }, + { chainId: CHAIN_IDS.OPTIMISM }, + ), }, ); @@ -568,12 +587,16 @@ describe('Bridge selectors', () => { it('returns quote list and fetch data, insufficientBal=false,quotesRefreshCount=2', () => { const state = createBridgeMockStore( - { extensionConfig: { maxRefreshCount: 5 } }, { - toChainId: '0x1', + extensionConfig: { maxRefreshCount: 5 }, + destNetworkAllowlist: ['0x89'], + }, + { + toChainId: '0x89', + fromToken: { address: zeroAddress(), symbol: 'ETH' }, + toToken: { address: zeroAddress(), symbol: 'TEST' }, fromTokenExchangeRate: 1, toTokenExchangeRate: 0.99, - toNativeExchangeRate: 0.354073, }, { quoteRequest: { insufficientBal: false }, @@ -590,23 +613,34 @@ describe('Bridge selectors', () => { ETH: { conversionRate: 1, }, + POL: { + conversionRate: 0.354073, + usdConversionRate: 1, + }, }, + marketData: {}, + ...mockNetworkState( + { chainId: CHAIN_IDS.MAINNET }, + { chainId: CHAIN_IDS.LINEA_MAINNET }, + { chainId: CHAIN_IDS.POLYGON }, + { chainId: CHAIN_IDS.OPTIMISM }, + ), }, ); const result = getBridgeQuotes(state as never); const recommendedQuoteMetadata = { adjustedReturn: { - fiat: new BigNumber('13.84343712858974048'), + fiat: new BigNumber('13.843437128589739081572'), }, - cost: { fiat: new BigNumber('0.15656287141025952') }, + cost: { fiat: new BigNumber('0.156562871410260918428') }, sentAmount: { fiat: new BigNumber('14'), amount: new BigNumber('14'), }, swapRate: new BigNumber('0.998877142857142857142857142857142857'), toTokenAmount: { - fiat: new BigNumber('13.8444372'), + fiat: new BigNumber('13.844437199999998601572'), amount: new BigNumber('13.98428'), }, gasFee: { @@ -620,8 +654,8 @@ describe('Bridge selectors', () => { }; expect(result.sortedQuotes).toHaveLength(2); const EXPECTED_SORTED_COSTS = [ - { fiat: new BigNumber('0.15656287141025952') }, - { fiat: new BigNumber('0.33900008283534464') }, + { fiat: new BigNumber('0.156562871410260918428') }, + { fiat: new BigNumber('0.33900008283534602') }, ]; result.sortedQuotes.forEach((quote, idx) => { expect(quote.cost).toStrictEqual(EXPECTED_SORTED_COSTS[idx]); @@ -647,12 +681,16 @@ describe('Bridge selectors', () => { it('returns quote list and fetch data, insufficientBal=true', () => { const state = createBridgeMockStore( - { extensionConfig: { maxRefreshCount: 5 } }, { - toChainId: '0x1', + extensionConfig: { maxRefreshCount: 5 }, + destNetworkAllowlist: ['0x89'], + }, + { + toChainId: '0x89', + fromToken: { address: zeroAddress(), symbol: 'ETH' }, + toToken: { address: zeroAddress(), symbol: 'TEST' }, fromTokenExchangeRate: 1, toTokenExchangeRate: 0.99, - toNativeExchangeRate: 0.354073, }, { quoteRequest: { insufficientBal: true }, @@ -669,7 +707,18 @@ describe('Bridge selectors', () => { ETH: { conversionRate: 1, }, + POL: { + conversionRate: 1, + usdConversionRate: 1, + }, }, + marketData: {}, + ...mockNetworkState( + { chainId: CHAIN_IDS.MAINNET }, + { chainId: CHAIN_IDS.LINEA_MAINNET }, + { chainId: CHAIN_IDS.POLYGON }, + { chainId: CHAIN_IDS.OPTIMISM }, + ), }, ); const result = getBridgeQuotes(state as never); @@ -861,11 +910,14 @@ describe('Bridge selectors', () => { it('should recommend 2nd fastest quote if adjustedReturn is less than 80% of cheapest quote', () => { const state = createBridgeMockStore( - {}, + { destNetworkAllowlist: ['0x89'] }, { + toChainId: '0x89', + fromToken: { address: zeroAddress(), symbol: 'ETH' }, + toToken: { address: zeroAddress(), symbol: 'TEST' }, + fromTokenExchangeRate: 2524.25, sortOrder: SortOrder.ETA_ASC, toTokenExchangeRate: 0.998781, - toNativeExchangeRate: 0.354073, }, { quotes: [ @@ -886,7 +938,18 @@ describe('Bridge selectors', () => { ETH: { conversionRate: 2524.25, }, + POL: { + conversionRate: 0.354073, + usdConversionRate: 1, + }, }, + marketData: {}, + ...mockNetworkState( + { chainId: CHAIN_IDS.MAINNET }, + { chainId: CHAIN_IDS.LINEA_MAINNET }, + { chainId: CHAIN_IDS.POLYGON }, + { chainId: CHAIN_IDS.OPTIMISM }, + ), }, ); @@ -1049,11 +1112,19 @@ describe('Bridge selectors', () => { it('should return isInsufficientGasBalance=true when balance is 0 and fromToken is erc20', () => { const state = createBridgeMockStore( - {}, + { destNetworkAllowlist: ['0x89'] }, { - toChainId: '0x1', + toChainId: '0x89', + toToken: { + address: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359', + symbol: 'TEST', + }, fromTokenInputValue: '0.001', - fromToken: { address: '0x123', decimals: 6 }, + fromToken: { + address: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359', + decimals: 6, + }, + toTokenExchangeRate: 0.798781, }, { srcTokens: { '0x00': { address: '0x00', symbol: 'TEST' } }, @@ -1061,6 +1132,19 @@ describe('Bridge selectors', () => { quotesLastFetched: Date.now(), quoteRequest: { srcTokenAmount: '100000000' }, }, + { + currencyRates: { + POL: { + conversionRate: 0.354073, + usdConversionRate: 1, + }, + }, + ...mockNetworkState( + { chainId: CHAIN_IDS.MAINNET }, + { chainId: CHAIN_IDS.LINEA_MAINNET }, + { chainId: CHAIN_IDS.POLYGON }, + ), + }, ); const result = getValidationErrors(state as never); @@ -1163,10 +1247,13 @@ describe('Bridge selectors', () => { it('should return isEstimatedReturnLow=true return value is 20% less than sent funds', () => { const state = createBridgeMockStore( - {}, + { destNetworkAllowlist: ['0x89'] }, { + toChainId: '0x89', + fromToken: { address: zeroAddress(), symbol: 'ETH' }, + toToken: { address: zeroAddress(), symbol: 'TEST' }, + fromTokenExchangeRate: 2524.25, toTokenExchangeRate: 0.798781, - toNativeExchangeRate: 0.354073, }, { quotes: mockBridgeQuotesNativeErc20, @@ -1176,7 +1263,18 @@ describe('Bridge selectors', () => { ETH: { conversionRate: 2524.25, }, + POL: { + conversionRate: 0.354073, + usdConversionRate: 1, + }, }, + marketData: {}, + ...mockNetworkState( + { chainId: CHAIN_IDS.MAINNET }, + { chainId: CHAIN_IDS.LINEA_MAINNET }, + { chainId: CHAIN_IDS.POLYGON }, + { chainId: CHAIN_IDS.OPTIMISM }, + ), }, ); const result = getValidationErrors(state as never); @@ -1195,10 +1293,13 @@ describe('Bridge selectors', () => { it('should return isEstimatedReturnLow=false when return value is more than 80% of sent funds', () => { const state = createBridgeMockStore( - {}, + { destNetworkAllowlist: ['0x89'] }, { + toChainId: '0x89', + fromToken: { address: zeroAddress(), symbol: 'ETH' }, + toToken: { address: zeroAddress(), symbol: 'TEST' }, + fromTokenExchangeRate: 2524.25, toTokenExchangeRate: 0.998781, - toNativeExchangeRate: 0.354073, }, { quotes: mockBridgeQuotesNativeErc20, @@ -1207,8 +1308,20 @@ describe('Bridge selectors', () => { currencyRates: { ETH: { conversionRate: 2524.25, + usdConversionRate: 1, + }, + POL: { + conversionRate: 1, + usdConversionRate: 1, }, }, + marketData: {}, + ...mockNetworkState( + { chainId: CHAIN_IDS.MAINNET }, + { chainId: CHAIN_IDS.LINEA_MAINNET }, + { chainId: CHAIN_IDS.POLYGON }, + { chainId: CHAIN_IDS.OPTIMISM }, + ), }, ); const result = getValidationErrors(state as never);