Skip to content

Commit

Permalink
test: only include required networks for e2e tests (#2149)
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanshparashar authored Jan 14, 2025
1 parent 89e2762 commit 17f1b88
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getBridgeUiConfigForChain } from '../../util/bridgeUiConfig'
import { getChainQueryParamForChain } from '../../types/ChainQueryParam'
import { trackEvent } from '../../util/AnalyticsUtils'
import { useIsTestnetMode } from '../../hooks/useIsTestnetMode'
import { isTestingEnvironment } from '../../util/CommonUtils'
import { isDevelopmentEnvironment } from '../../util/CommonUtils'

const shuffleArray = (array: PortalProject[]) => {
return array.sort(() => Math.random() - 0.5)
Expand Down Expand Up @@ -54,7 +54,7 @@ const fetchProjects = async (
}

if (isTestnetMode) {
return isTestingEnvironment ? generateTestnetProjects(chainId, 6) : [] // don't show any test projects in production
return isDevelopmentEnvironment ? generateTestnetProjects(chainId, 6) : [] // don't show any test projects in production
}

try {
Expand Down
6 changes: 4 additions & 2 deletions packages/arb-token-bridge-ui/src/util/CommonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ export function shortenTxHash(txHash: string) {
)}`
}

export const isTestingEnvironment =
!!window.Cypress || process.env.NODE_ENV !== 'production'
export const isE2eTestingEnvironment =
typeof window !== 'undefined' && !!window.Cypress

export const isDevelopmentEnvironment = process.env.NODE_ENV === 'development'
9 changes: 9 additions & 0 deletions packages/arb-token-bridge-ui/src/util/orbitChainsList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { NativeCurrencyBase } from '../hooks/useNativeCurrency'
import { ChainId } from '../types/ChainId'
import { isE2eTestingEnvironment } from './CommonUtils'
import { ChainWithRpcUrl } from './networks'
import orbitChainsData from './orbitChainsData.json'

Expand Down Expand Up @@ -59,6 +61,13 @@ export function getOrbitChains(
testnet: boolean
} = { mainnet: true, testnet: true }
): OrbitChainConfig[] {
if (isE2eTestingEnvironment) {
// During E2E tests, only return local chains
return Object.values(orbitChains).filter(
chain => chain.chainId === ChainId.L3Local
)
}

const mainnetChains = mainnet ? Object.values(orbitMainnets) : []
const testnetChains = testnet ? Object.values(orbitTestnets) : []

Expand Down
31 changes: 27 additions & 4 deletions packages/arb-token-bridge-ui/src/util/wagmi/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
base,
baseSepolia
} from './wagmiAdditionalNetworks'
import { isTestingEnvironment } from '../CommonUtils'
import {
isE2eTestingEnvironment,
isDevelopmentEnvironment
} from '../CommonUtils'
import { getCustomChainsFromLocalStorage, rpcURLs } from '../networks'
import { ChainId } from '../../types/ChainId'
import { getOrbitChains } from '../orbitChainsList'
Expand All @@ -47,8 +50,22 @@ const defaultChains = [
holesky
]

const chainList = isTestingEnvironment
? [
const getChainList = () => {
// for E2E tests, only have local + minimal required chains
if (isE2eTestingEnvironment) {
return [
local,
arbitrumLocal,
l3Local,
sepolia, // required for testing cctp
arbitrumSepolia, // required for testing cctp
mainnet // required for import token test
]
}

// for local env, have all local + default + user added chains
if (isDevelopmentEnvironment) {
return [
...defaultChains,
// Orbit chains
...wagmiOrbitChains,
Expand All @@ -59,7 +76,13 @@ const chainList = isTestingEnvironment
// user-added custom chains
...customChains
]
: [...defaultChains, ...wagmiOrbitChains, ...customChains]
}

// for preview + production env, return all non-local chains
return [...defaultChains, ...wagmiOrbitChains, ...customChains]
}

const chainList = getChainList()

const projectId = process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID!

Expand Down

0 comments on commit 17f1b88

Please sign in to comment.