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

test: add custom gas token e2e tests #1960

Merged
merged 91 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
8c26fad
e2e custom fee token
brtkx Oct 3, 2024
d58b2e8
fix
brtkx Oct 3, 2024
591f930
fixes
brtkx Oct 3, 2024
b882660
fix
brtkx Oct 3, 2024
60a0f25
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Oct 3, 2024
56ff3a2
bump nitro ref
brtkx Oct 3, 2024
803da84
use different deployer wallet
brtkx Oct 4, 2024
9ae9435
fix
brtkx Oct 4, 2024
a664e54
fix
brtkx Oct 4, 2024
6972d52
fixes
brtkx Oct 4, 2024
ed7b34d
fix
brtkx Oct 4, 2024
d2eca87
fix weth
brtkx Oct 4, 2024
3c84690
logs
brtkx Oct 4, 2024
d2e18e2
fix network
brtkx Oct 4, 2024
d313756
logs
brtkx Oct 4, 2024
12a2270
fix
brtkx Oct 4, 2024
8283fdd
fix
brtkx Oct 4, 2024
a4c18a5
try
brtkx Oct 4, 2024
65918a4
fix
brtkx Oct 4, 2024
4886113
fix
brtkx Oct 4, 2024
37a7ef1
fix
brtkx Oct 4, 2024
067b64c
fixes
brtkx Oct 7, 2024
bc2c217
fix
brtkx Oct 7, 2024
59575c8
fix
brtkx Oct 7, 2024
b4b650f
fixes
brtkx Oct 7, 2024
05f2bbd
fix
brtkx Oct 7, 2024
9b5ca65
try
brtkx Oct 7, 2024
9b7e665
fix
brtkx Oct 7, 2024
3125d8e
fix
brtkx Oct 7, 2024
f28912a
fix
brtkx Oct 7, 2024
52eb29e
fix
brtkx Oct 8, 2024
1053116
fix
brtkx Oct 8, 2024
ecd415d
fix
brtkx Oct 8, 2024
3f3b88d
fix
brtkx Oct 8, 2024
e7583be
fix
brtkx Oct 8, 2024
83d290a
fix
brtkx Oct 8, 2024
25dfa4c
fixes
brtkx Oct 8, 2024
f9f632c
logs
brtkx Oct 8, 2024
ebb974f
fixes
brtkx Oct 8, 2024
84f1d2e
fixes
brtkx Oct 8, 2024
d021e89
fixes
brtkx Oct 8, 2024
39dd637
clean up
brtkx Oct 8, 2024
b3a797d
clean up
brtkx Oct 8, 2024
bbf4134
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Oct 8, 2024
b02242c
fix
brtkx Oct 8, 2024
30ee752
fix
brtkx Oct 8, 2024
a7eb5e9
logs
brtkx Oct 8, 2024
10a11ae
logs
brtkx Oct 8, 2024
5dba15f
fix
brtkx Oct 9, 2024
6a2962f
formatting
brtkx Oct 9, 2024
ae8ee3f
fixes
brtkx Oct 9, 2024
57b7063
fix
brtkx Oct 9, 2024
7e575ce
fix
brtkx Oct 9, 2024
ff9704c
whoops
brtkx Oct 9, 2024
f5d180f
fixes
brtkx Oct 9, 2024
23b4c73
fixes
brtkx Oct 9, 2024
07a25fc
fixes
brtkx Oct 9, 2024
d72ee4d
fix
brtkx Oct 9, 2024
4cdd228
bump nitro
brtkx Oct 9, 2024
ef46573
update rollup address, revert nitro ref
brtkx Oct 9, 2024
c67dcd5
fix
brtkx Oct 9, 2024
2caaf94
Merge branch 'master' into e2e-custom-fee-token
brtkx Oct 9, 2024
89004d1
fix
brtkx Oct 10, 2024
1376bbd
Merge branch 'e2e-custom-fee-token' of github.com:OffchainLabs/arbitr…
brtkx Oct 10, 2024
b9f89f7
clean up
brtkx Oct 10, 2024
3a83629
typo
brtkx Oct 10, 2024
01a7d8e
revert default timeout
brtkx Oct 10, 2024
3bb3308
revert
brtkx Oct 10, 2024
c5bd311
Merge branch 'master' into e2e-custom-fee-token
brtkx Oct 10, 2024
5de44b6
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Oct 17, 2024
c1c1d4f
Merge branch 'master' into e2e-custom-fee-token
dewanshparashar Oct 17, 2024
9200dbe
updates
brtkx Oct 17, 2024
d12583b
merge
brtkx Oct 17, 2024
e1e8c5a
Merge branch 'master' into e2e-custom-fee-token
dewanshparashar Oct 18, 2024
8010212
fix
brtkx Oct 18, 2024
7a0a6e9
Merge branch 'e2e-custom-fee-token' of github.com:OffchainLabs/arbitr…
brtkx Oct 18, 2024
c85a086
fix
brtkx Oct 18, 2024
a0d7974
fix
brtkx Oct 18, 2024
c3e86de
fix
brtkx Oct 18, 2024
18c66d2
fix
brtkx Oct 18, 2024
76987d6
Merge branch 'master' into e2e-custom-fee-token
brtkx Oct 21, 2024
816c3e0
try
brtkx Oct 22, 2024
eb14269
logs
brtkx Oct 22, 2024
702f391
fix
brtkx Oct 22, 2024
4f040ff
fix
brtkx Oct 22, 2024
a3ab216
fix
brtkx Oct 22, 2024
5837521
fix
brtkx Oct 22, 2024
05d02e4
clean up
brtkx Oct 22, 2024
50cf4f4
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Oct 22, 2024
f08047e
Merge branch 'master' into e2e-custom-fee-token
brtkx Oct 22, 2024
d7e0104
Merge branch 'master' into e2e-custom-fee-token
brtkx Oct 22, 2024
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
19 changes: 13 additions & 6 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: echo "e2eFiles=$(node .github/workflows/formatSpecfiles.js ${{ inputs.test_type }} | jq . --compact-output)" >> $GITHUB_OUTPUT

test-e2e:
name: "Test E2E - ${{ matrix.test.name }}${{ matrix.test.type == 'orbit' && ' with L3' || ''}}"
name: "${{ matrix.test.name }}${{ matrix.test.type == 'orbit-eth' && ' with L3' || matrix.test.type == 'orbit-custom' && ' with custom fee token' || ''}}"
needs: [load-e2e-files]
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -91,15 +91,22 @@ jobs:
if: inputs.test_type != 'cctp'
uses: OffchainLabs/actions/run-nitro-test-node@a20a76172ce524832ac897bef2fa10a62ed81c29
with:
nitro-testnode-ref: aab133aceadec2e622f15fa438f6327e3165392d
l3-node: ${{ matrix.test.type == 'orbit' }}
no-l3-token-bridge: ${{ matrix.test.type != 'orbit' }}
nitro-testnode-ref: badbcbea9b43d46e115da4d7c9f2f57c31af8431
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a newer tag that funds the wallet with native currency on L2. You can see the change here:
OffchainLabs/nitro-testnode@badbcbe

l3-node: ${{ matrix.test.type != 'regular' }}
no-l3-token-bridge: ${{ matrix.test.type == 'regular' }}
args: ${{ matrix.test.type == 'orbit-custom' && '--l3-fee-token' || '' }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this line - but we must update the README.md to have the instructions to setup testnode for Custom native token' E2Es. (--l3-fee-token)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


- name: Run e2e tests via cypress-io/github-action
uses: cypress-io/github-action@0da3c06ed8217b912deea9d8ee69630baed1737e # [email protected]
with:
start: yarn start
command: "yarn test:e2e${{ (matrix.test.type == 'cctp' && ':cctp') || (matrix.test.type == 'orbit' && ':orbit') || '' }} --browser chrome"
command: >-
${{
(matrix.test.type == 'orbit-eth') && 'yarn test:e2e:orbit --browser chrome' ||
(matrix.test.type == 'orbit-custom' && 'yarn test:e2e:orbit:custom-gas-token --browser chrome') ||
(matrix.test.type == 'cctp' && 'yarn test:e2e:cctp --browser chrome') ||
'yarn test:e2e --browser chrome'
dewanshparashar marked this conversation as resolved.
Show resolved Hide resolved
}}
wait-on: http://127.0.0.1:3000
wait-on-timeout: 120
spec: ./packages/arb-token-bridge-ui/tests/e2e/specs/*
Expand All @@ -121,7 +128,7 @@ jobs:
uses: actions/upload-artifact@v4
if: always()
with:
name: e2e-artifacts-${{ github.sha }}-${{ matrix.test.name }}-${{ (matrix.test.type == 'cctp' && 'cctp') || (matrix.test.type == 'orbit' && 'l3') || 'regular'}}
name: e2e-artifacts-${{ github.sha }}-${{ matrix.test.name }}-${{ (matrix.test.type == 'cctp' && 'cctp') || (matrix.test.type == 'orbit-eth' && 'l3') || (matrix.test.type == 'orbit-custom' && 'custom-fee-token') || 'regular'}}
path: |
./packages/arb-token-bridge-ui/cypress/videos
./packages/arb-token-bridge-ui/cypress/screenshots
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/formatSpecfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ switch (testType) {
});
tests.push({
...spec,
type: "orbit",
type: "orbit-eth",
});
tests.push({
...spec,
type: "orbit-custom",
});
});
break;
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ It is important for any code change to pass both unit and end-to-end tests. This
./test-node.bash --init --no-simple --tokenbridge --l3node --l3-token-bridge
```

To run with a custom fee token also include the following flags:

```bash
--l3-fee-token --l3-fee-token-decimals 18
```

2. When the Nitro test-node is up and running you should see logs like `sequencer_1` and `staker-unsafe_1` in the terminal. This can take up to 10 minutes.

2. At the root of the token bridge UI:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"lint:fix": "yarn workspace arb-token-bridge-ui lint:fix",
"test:e2e": "yarn workspace arb-token-bridge-ui env-cmd --silent --file .e2e.env yarn synpress run --configFile synpress.config.ts",
"test:e2e:cctp": "yarn test:e2e --configFile synpress.cctp.config.ts",
"test:e2e:orbit": "E2E_ORBIT=true yarn test:e2e"
"test:e2e:orbit": "E2E_ORBIT=true yarn test:e2e",
"test:e2e:orbit:custom-gas-token": "E2E_ORBIT_CUSTOM_GAS_TOKEN=true yarn test:e2e"
},
"resolutions": {
"**/@walletconnect/ethereum-provider": "2.13.1",
Expand Down
8 changes: 0 additions & 8 deletions packages/arb-token-bridge-ui/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@ import 'tippy.js/themes/light.css'

import '@rainbow-me/rainbowkit/styles.css'

import { registerLocalNetwork } from '../util/networks'
import { Layout } from '../components/common/Layout'
import { siteTitle } from './_document'

import '../styles/tailwind.css'
import '../styles/purple.css'
import { isUserRejectedError } from '../util/isUserRejectedError'

if (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Register local network is async now so we do it when importing the component. See index.tsx

process.env.NODE_ENV !== 'production' ||
process.env.NEXT_PUBLIC_IS_E2E_TEST
) {
registerLocalNetwork()
}

dayjs.extend(utc)
dayjs.extend(relativeTime)
dayjs.extend(timeZone)
Expand Down
54 changes: 39 additions & 15 deletions packages/arb-token-bridge-ui/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react'
import React, { ComponentType, useEffect } from 'react'
import { GetServerSidePropsContext, GetServerSidePropsResult } from 'next'
import dynamic from 'next/dynamic'
import { decodeString, encodeString } from 'use-query-params'
Expand All @@ -7,7 +7,8 @@ import { registerCustomArbitrumNetwork } from '@arbitrum/sdk'
import { Loader } from '../components/common/atoms/Loader'
import {
getCustomChainsFromLocalStorage,
mapCustomChainToNetworkData
mapCustomChainToNetworkData,
registerLocalNetwork
} from '../util/networks'
import { getOrbitChains } from '../util/orbitChainsList'
import { sanitizeQueryParams } from '../hooks/useNetworks'
Expand All @@ -17,17 +18,32 @@ import {
} from '../hooks/useArbQueryParams'
import { sanitizeExperimentalFeaturesQueryParam } from '../util'

const App = dynamic(() => import('../components/App/App'), {
ssr: false,
loading: () => (
<>
<div className="h-12 w-full lg:h-16" />
<div className="fixed inset-0 m-auto h-[44px] w-[44px]">
<Loader size="large" color="white" />
</div>
</>
)
})
const App = dynamic(
() => {
return new Promise<{ default: ComponentType }>(async resolve => {
if (
process.env.NODE_ENV !== 'production' ||
process.env.NEXT_PUBLIC_IS_E2E_TEST
) {
await registerLocalNetwork()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's async we do it before rendering the component

}

const AppComponent = await import('../components/App/App')
resolve(AppComponent)
})
},
{
ssr: false,
loading: () => (
<>
<div className="h-12 w-full lg:h-16" />
<div className="fixed inset-0 m-auto h-[44px] w-[44px]">
<Loader size="large" color="white" />
</div>
</>
)
}
)

function getDestinationWithSanitizedQueryParams(
sanitized: {
Expand Down Expand Up @@ -89,9 +105,11 @@ function addOrbitChainsToArbitrumSDK() {
)
}

export function getServerSideProps({
export async function getServerSideProps({
query
}: GetServerSidePropsContext): GetServerSidePropsResult<Record<string, never>> {
}: GetServerSidePropsContext): Promise<
GetServerSidePropsResult<Record<string, never>>
> {
const sourceChainId = decodeChainQueryParam(query.sourceChain)
const destinationChainId = decodeChainQueryParam(query.destinationChain)
const experiments = decodeString(query.experiments)
Expand All @@ -103,6 +121,12 @@ export function getServerSideProps({
}
}

if (
process.env.NODE_ENV !== 'production' ||
process.env.NEXT_PUBLIC_IS_E2E_TEST
) {
await registerLocalNetwork()
Copy link
Contributor Author

@brtkx brtkx Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to register networks so that it recognises L3 local and doesn't change the chain to default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to do this twice - once while importing the component, and once during server side generation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need it server side to recognize local networks and correctly sanitize network pairs, and we need it in UI so we add them when importing the component

}
// it's necessary to call this before sanitization to make sure all chains are registered
addOrbitChainsToArbitrumSDK()

Expand Down
7 changes: 7 additions & 0 deletions packages/arb-token-bridge-ui/src/util/TokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ function getErc20DataCache(params: GetErc20DataCacheParams): Erc20Data | null
function getErc20DataCache(
params?: GetErc20DataCacheParams
): Erc20DataCache | (Erc20Data | null) {
if (
typeof window === 'undefined' ||
typeof window.localStorage === 'undefined'
) {
return null
}

const cache: Erc20DataCache = JSON.parse(
// intentionally using || instead of ?? for it to work with an empty string
localStorage.getItem(erc20DataCacheLocalStorageKey) || '{}'
Expand Down
62 changes: 60 additions & 2 deletions packages/arb-token-bridge-ui/src/util/networks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { StaticJsonRpcProvider } from '@ethersproject/providers'
import {
ArbitrumNetwork,
getChildrenForNetwork,
Expand All @@ -9,6 +10,7 @@ import {
import { loadEnvironmentVariableWithFallback } from './index'
import { getBridgeUiConfigForChain } from './bridgeUiConfig'
import { chainIdToInfuraUrl } from './infura'
import { fetchErc20Data } from './TokenUtils'

export enum ChainId {
// L1
Expand Down Expand Up @@ -385,6 +387,42 @@ export const defaultL3Network: ArbitrumNetwork = {
}
}

export const defaultL3CustomGasTokenNetwork: ArbitrumNetwork = {
chainId: 333333,
parentChainId: ChainId.ArbitrumLocal,
confirmPeriodBlocks: 20,
ethBridge: {
bridge: '0xA584795e24628D9c067A6480b033C9E96281fcA3',
inbox: '0xDcA690902d3154886Ec259308258D10EA5450996',
outbox: '0xda243bD61B011024FC923164db75Dde198AC6175',
rollup: process.env.NEXT_PUBLIC_IS_E2E_TEST
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as with other local chains, different address in CI

? '0x17d70d77AAEe46ACDF8b87BB2f085f36f63eC638'
: '0x7a23F33C1C384eFc11b8Cf207420c464ba2959CC',
sequencerInbox: '0x16c54EE2015CD824415c2077F4103f444E00A8cb'
},
nativeToken: '0xE069078bA9ACCE4eeAE609d8754515Cf13dd6706',
isCustom: true,
isTestnet: true,
name: 'L3 Local',
retryableLifetimeSeconds: 604800,
tokenBridge: {
parentCustomGateway: '0xCe02eA568090ae7d5184B0a98df90f6aa69C1552',
parentErc20Gateway: '0x59156b0596689D965Ba707E160e5370AF22461a0',
parentGatewayRouter: '0x0C085152C2799834fc1603533ff6916fa1FdA302',
parentMultiCall: '0x20a3627Dcc53756E38aE3F92717DE9B23617b422',
parentProxyAdmin: '0x1A61102c26ad3f64bA715B444C93388491fd8E68',
parentWeth: '0xA1abD387192e3bb4e84D3109181F9f005aBaF5CA',
parentWethGateway: '0x59156b0596689D965Ba707E160e5370AF22461a0',
childCustomGateway: '0xD4816AeF8f85A3C1E01Cd071a81daD4fa941625f',
childErc20Gateway: '0xaa7d51aFFEeB32d99b1CB2fd6d81D7adA4a896e8',
childGatewayRouter: '0x8B6BC759226f8Fe687c8aD8Cc0DbF85E095e9297',
childMultiCall: '0x052B15c8Ff0544287AE689C4F2FC53A3905d7Db3',
childProxyAdmin: '0x36C56eC2CF3a3f53db9F01d0A5Ae84b36fb0A1e2',
childWeth: '0x0000000000000000000000000000000000000000',
childWethGateway: '0x0000000000000000000000000000000000000000'
}
}

export const localL1NetworkRpcUrl = loadEnvironmentVariableWithFallback({
env: process.env.NEXT_PUBLIC_LOCAL_ETHEREUM_RPC_URL,
fallback: 'http://127.0.0.1:8545'
Expand All @@ -398,14 +436,34 @@ export const localL3NetworkRpcUrl = loadEnvironmentVariableWithFallback({
fallback: 'http://127.0.0.1:3347'
})

export function registerLocalNetwork() {
export async function registerLocalNetwork() {
try {
rpcURLs[defaultL1Network.chainId] = localL1NetworkRpcUrl
rpcURLs[defaultL2Network.chainId] = localL2NetworkRpcUrl
rpcURLs[defaultL3Network.chainId] = localL3NetworkRpcUrl

registerCustomArbitrumNetwork(defaultL2Network)
registerCustomArbitrumNetwork(defaultL3Network)

let isLocalCustomNativeToken = false

try {
const data = await fetchErc20Data({
address: defaultL3CustomGasTokenNetwork.nativeToken!,
provider: new StaticJsonRpcProvider(localL2NetworkRpcUrl)
})
if (data.symbol === 'TN') {
isLocalCustomNativeToken = true
}
} catch (e) {
// not the native token
isLocalCustomNativeToken = false
}

registerCustomArbitrumNetwork(
isLocalCustomNativeToken
? defaultL3CustomGasTokenNetwork
: defaultL3Network
)
} catch (error: any) {
console.error(`Failed to register local network: ${error.message}`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ import { ChainId, ChainWithRpcUrl, explorerUrls, rpcURLs } from '../networks'
import { getBridgeUiConfigForChain } from '../bridgeUiConfig'

export function chainToWagmiChain(chain: ChainWithRpcUrl): Chain {
const { nativeTokenData } = getBridgeUiConfigForChain(chain.chainId)
let { nativeTokenData } = getBridgeUiConfigForChain(chain.chainId)

if (chain.chainId === ChainId.L3Local) {
nativeTokenData = chain.nativeToken
? {
name: 'testnode',
symbol: 'TN',
decimals: 18
}
: ether
}

return {
id: chain.chainId,
Expand Down
Loading