From 8f319ae6e8976916bbea4d399942109b96e75bc6 Mon Sep 17 00:00:00 2001 From: yogurtandjam Date: Mon, 14 Oct 2024 18:18:50 -0400 Subject: [PATCH] add tests --- src/constants/__test__/cctp.spec.ts | 38 +++++++++++++++++++++++++++++ src/constants/cctp.ts | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/constants/__test__/cctp.spec.ts b/src/constants/__test__/cctp.spec.ts index d0abb3e381..b953feaf71 100644 --- a/src/constants/__test__/cctp.spec.ts +++ b/src/constants/__test__/cctp.spec.ts @@ -5,8 +5,10 @@ import { getMapOfHighestFeeTokensByChainId, getMapOfLowestFeeTokensByChainId, getMapOfLowestFeeTokensByDenom, + isTokenCctp, } from '@/constants/cctp'; +import cctpTokens from '../../../public/configs/cctp.json'; import { TransferType } from '../abacus'; describe('getLowestFeeChainNames', () => { @@ -252,3 +254,39 @@ describe('getMapOfHighestFeeTokensByChainId', () => { }); }); }); + +describe('isTokenCctp', () => { + const getTestAssetWithDenom = (denom: string) => ({ + denom, + chainID: '1', + originDenom: denom, + originChainID: '1', + trace: 'test-trace', + isCW20: false, + isEVM: true, + isSVM: false, + symbol: 'test-symbol', + name: 'test-name', + logoURI: 'test-logoURI', + decimals: 10, + tokenContract: 'test-contract', + description: 'test-description', + coingeckoID: 'test-coingeckoID', + recommendedSymbol: 'test-recommendedSymbol', + }); + it('returns true for cctp token', () => { + const denom = cctpTokens[0].tokenAddress; + const asset = getTestAssetWithDenom(denom); + expect(isTokenCctp(asset)).toBe(true); + }); + it('returns true for cctp token case insensitive', () => { + const denom = cctpTokens[0].tokenAddress.toLowerCase(); + const asset = getTestAssetWithDenom(denom); + expect(isTokenCctp(asset)).toBe(true); + }); + it('returns false for non-cctp tokens', () => { + const denom = 'non-cctp-denom'; + const asset = getTestAssetWithDenom(denom); + expect(isTokenCctp(asset)).toBe(false); + }); +}); diff --git a/src/constants/cctp.ts b/src/constants/cctp.ts index 4a8de6b07f..67166ba8b7 100644 --- a/src/constants/cctp.ts +++ b/src/constants/cctp.ts @@ -88,5 +88,5 @@ export const isTokenCctp = (token: Asset | undefined) => { const isDenomCctp = (denom: string | undefined) => { if (!denom) return false; - return cctpTokensByDenom[denom.toUpperCase()]; + return Boolean(cctpTokensByDenom[denom.toUpperCase()]); };