Skip to content

Commit d72f044

Browse files
committed
test: update anvil integration constants and polling intervals
1 parent 1732e77 commit d72f044

File tree

11 files changed

+141
-62
lines changed

11 files changed

+141
-62
lines changed

.github/workflows/build-test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ jobs:
238238

239239
- name: Set nitro contracts image
240240
run: |
241-
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts:v3.2.0-2f747c7" >> "$GITHUB_ENV"
241+
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts-anvil:v3.2.0-2f747c7" >> "$GITHUB_ENV"
242242
243243
- name: Set up Docker Buildx
244244
uses: docker/setup-buildx-action@v3
@@ -281,7 +281,7 @@ jobs:
281281

282282
- name: Set token bridge contracts image
283283
run: |
284-
echo "TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-token-bridge-contracts:v1.2.2" >> "$GITHUB_ENV"
284+
echo "TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-token-bridge-contracts-anvil:v1.2.5-5975d8f73608" >> "$GITHUB_ENV"
285285
286286
- name: Set up Docker Buildx
287287
uses: docker/setup-buildx-action@v3
@@ -307,7 +307,7 @@ jobs:
307307
uses: docker/build-push-action@v6
308308
with:
309309
context: ./token-bridge-contracts
310-
file: ./token-bridge-contracts/Dockerfile
310+
file: ./token-bridge-contracts/Dockerfile.anvil
311311
push: true
312312
tags: |
313313
${{ env.TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE }}
@@ -327,8 +327,8 @@ jobs:
327327

328328
- name: Set nitro contracts image
329329
run: |
330-
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts:v3.2.0-2f747c7" >> "$GITHUB_ENV"
331-
echo "TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-token-bridge-contracts:v1.2.2" >> "$GITHUB_ENV"
330+
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts-anvil:v3.2.0-2f747c7" >> "$GITHUB_ENV"
331+
echo "TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-token-bridge-contracts-anvil:v1.2.5-5975d8f73608" >> "$GITHUB_ENV"
332332
333333
- name: Log in to GHCR
334334
uses: docker/login-action@v3

nitro-contracts/Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ FROM ghcr.io/foundry-rs/foundry:v1.3.1 AS foundry
22

33
FROM node:20-bullseye-slim AS builder
44

5-
ARG NITRO_CONTRACTS_REPO_URL=https://github.com/OffchainLabs/nitro-contracts.git
6-
ARG NITRO_CONTRACTS_GIT_COMMIT=2f747c722d98d5fd662bfda08cd86aa534b22be2
7-
85
COPY --from=foundry /usr/local/bin/forge /usr/local/bin/forge
96

107
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
118

129
WORKDIR /workspace
1310

1411
RUN git init . \
15-
&& git remote add origin "${NITRO_CONTRACTS_REPO_URL}" \
16-
&& git fetch --depth 1 origin "${NITRO_CONTRACTS_GIT_COMMIT}" \
12+
&& git remote add origin https://github.com/OffchainLabs/nitro-contracts.git \
13+
&& git fetch --depth 1 origin 2f747c722d98d5fd662bfda08cd86aa534b22be2 \
1714
&& git checkout --detach FETCH_HEAD \
1815
&& git submodule update --init --recursive --depth 1
1916

src/contracts/Inbox.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const inboxABI = [
2+
{
3+
stateMutability: 'view',
4+
type: 'function',
5+
inputs: [
6+
{ name: 'dataLength', type: 'uint256' },
7+
{ name: 'baseFee', type: 'uint256' },
8+
],
9+
name: 'calculateRetryableSubmissionFee',
10+
outputs: [{ type: 'uint256' }],
11+
},
12+
{
13+
stateMutability: 'payable',
14+
type: 'function',
15+
inputs: [
16+
{ name: 'to', type: 'address' },
17+
{ name: 'l2CallValue', type: 'uint256' },
18+
{ name: 'maxSubmissionCost', type: 'uint256' },
19+
{ name: 'excessFeeRefundAddress', type: 'address' },
20+
{ name: 'callValueRefundAddress', type: 'address' },
21+
{ name: 'gasLimit', type: 'uint256' },
22+
{ name: 'maxFeePerGas', type: 'uint256' },
23+
{ name: 'data', type: 'bytes' },
24+
],
25+
name: 'createRetryableTicketNoRefundAliasRewrite',
26+
outputs: [{ type: 'uint256' }],
27+
},
28+
] as const;

src/createTokenBridge.integration.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { scaleFrom18DecimalsToNativeTokenDecimals } from './utils/decimals';
2222
import { getWethAddress } from './utils/getWethAddress';
2323
import { isAnvilTestMode, getAnvilTestStack } from './integrationTestHelpers/injectedMode';
2424
import { Address } from 'viem';
25+
import { testConstants } from './integrationTestHelpers/constants';
2526

2627
const env = isAnvilTestMode() ? getAnvilTestStack() : undefined;
2728

@@ -54,16 +55,19 @@ if (env) {
5455
const l1Client = createPublicClient({
5556
chain: env ? env.l1.chain : nitroTestnodeL1,
5657
transport: env ? http(env.l1.rpcUrl) : http(nitroTestnodeL1.rpcUrls.default.http[0]),
58+
...(env ? { pollingInterval: testConstants.POLLING_INTERVAL } : {}),
5759
});
5860

5961
const l2Client = createPublicClient({
6062
chain: env ? env.l2.chain : nitroTestnodeL2,
6163
transport: env ? http(env.l2.rpcUrl) : http(nitroTestnodeL2.rpcUrls.default.http[0]),
64+
...(env ? { pollingInterval: testConstants.POLLING_INTERVAL } : {}),
6265
});
6366

6467
const l3Client = createPublicClient({
6568
chain: env ? env.l3.chain : nitroTestnodeL3,
6669
transport: env ? http(env.l3.rpcUrl) : http(nitroTestnodeL3.rpcUrls.default.http[0]),
70+
...(env ? { pollingInterval: testConstants.POLLING_INTERVAL } : {}),
6771
});
6872

6973
function checkTokenBridgeContracts(tokenBridgeContracts: TokenBridgeContracts) {

src/ethers-compat/publicClientToProvider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ export function publicClientToProvider<TChain extends Chain | undefined>(
2020
const transportUrl = publicClient.transport.url as string | undefined;
2121
const url = transportUrl ?? chain.rpcUrls.default.http[0];
2222

23-
return new providers.StaticJsonRpcProvider(url, network);
23+
const provider = new providers.StaticJsonRpcProvider(url, network);
24+
provider.pollingInterval = publicClient.pollingInterval;
25+
26+
return provider;
2427
}

src/integrationTestHelpers/anvilHarness.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,13 @@ export function hydrateAnvilTestStack(env: InjectedAnvilTestStack): AnvilTestSta
272272
publicClient: createPublicClient({
273273
chain: l2Chain,
274274
transport: http(env.l2.rpcUrl),
275+
pollingInterval: testConstants.POLLING_INTERVAL,
275276
}),
276277
walletClient: createWalletClient({
277278
chain: l2Chain,
278279
transport: http(env.l2.rpcUrl),
279280
account: blockAdvancerAccount,
281+
pollingInterval: testConstants.POLLING_INTERVAL,
280282
}),
281283
account: blockAdvancerAccount,
282284
}),
@@ -316,15 +318,15 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
316318
dockerNetworkName = `chain-sdk-int-test-net-${Date.now()}`;
317319
createDockerNetwork(dockerNetworkName);
318320

319-
const l2ChainId = testConstants.DEFAULT_L2_CHAIN_ID;
321+
const l2ChainId = testConstants.L2_CHAIN_ID;
320322
const l3ChainId = l2ChainId + 1;
321-
const l1RpcPort = testConstants.DEFAULT_L1_RPC_PORT;
322-
const l2RpcPort = testConstants.DEFAULT_L2_RPC_PORT;
323-
const l3RpcPort = testConstants.DEFAULT_L3_RPC_PORT;
324-
const anvilImage = testConstants.DEFAULT_ANVIL_IMAGE;
325-
const nitroImage = testConstants.DEFAULT_NITRO_IMAGE;
326-
const sepoliaBeaconRpc = testConstants.DEFAULT_SEPOLIA_BEACON_RPC;
327-
const anvilForkUrl = testConstants.DEFAULT_SEPOLIA_RPC;
323+
const l1RpcPort = testConstants.L1_RPC_PORT;
324+
const l2RpcPort = testConstants.L2_RPC_PORT;
325+
const l3RpcPort = testConstants.L3_RPC_PORT;
326+
const anvilImage = testConstants.ANVIL_IMAGE;
327+
const nitroImage = testConstants.NITRO_IMAGE;
328+
const sepoliaBeaconRpc = testConstants.SEPOLIA_BEACON_RPC;
329+
const anvilForkUrl = testConstants.SEPOLIA_RPC;
328330
const rollupCreatorVersion: RollupCreatorSupportedVersion = 'v3.2';
329331
const rollupTimingParams: CustomTimingParams = {
330332
confirmPeriodBlocks: 150n,
@@ -353,7 +355,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
353355
});
354356

355357
l1RpcCachingProxy = await startRpcCachingProxy(anvilForkUrl, cacheFilePath, {
356-
forkBlockNumber: testConstants.DEFAULT_SEPOLIA_FORK_BLOCK_NUMBER,
358+
forkBlockNumber: testConstants.SEPOLIA_FORK_BLOCK_NUMBER,
357359
});
358360

359361
const l1RpcUrlWithCaching = l1RpcCachingProxy.proxyUrl;
@@ -374,7 +376,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
374376
l1RpcPort,
375377
anvilImage,
376378
anvilForkUrl: l1RpcUrlWithCaching,
377-
anvilForkBlockNumber: testConstants.DEFAULT_SEPOLIA_FORK_BLOCK_NUMBER,
379+
anvilForkBlockNumber: testConstants.SEPOLIA_FORK_BLOCK_NUMBER,
378380
chainId: sepolia.id,
379381
});
380382

@@ -389,6 +391,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
389391
const l1Client = createPublicClient({
390392
chain: l1Chain,
391393
transport: http(l1RpcUrl),
394+
pollingInterval: testConstants.POLLING_INTERVAL,
392395
});
393396
registerChainForRpcUrl({ rpcUrl: l1RpcUrl, chain: l1Chain });
394397

@@ -462,7 +465,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
462465
validatorPrivateKey: validatorAccount.privateKey,
463466
stakeToken: l2RollupConfig.stakeToken,
464467
parentChainId: sepolia.id,
465-
parentChainRpcUrl: `http://${l1ContainerName}:8545`,
468+
parentChainRpcUrl: `http://${l1ContainerName}:${l1RpcPort}`,
466469
parentChainBeaconRpcUrl: sepoliaBeaconRpc,
467470
});
468471

@@ -535,12 +538,14 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
535538
let l2Client: PublicClient<Transport, Chain> = createPublicClient({
536539
chain: l2BootstrapChain,
537540
transport: http(l2RpcUrl),
541+
pollingInterval: testConstants.POLLING_INTERVAL,
538542
});
539543

540544
const l2WalletClient = createWalletClient({
541545
chain: l2BootstrapChain,
542546
transport: http(l2RpcUrl),
543547
account: harnessDeployer,
548+
pollingInterval: testConstants.POLLING_INTERVAL,
544549
});
545550

546551
const l2BlockAdvancer = createBlockAdvancer({
@@ -549,6 +554,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
549554
chain: l2BootstrapChain,
550555
transport: http(l2RpcUrl),
551556
account: l2BlockAdvancerAccount,
557+
pollingInterval: testConstants.POLLING_INTERVAL,
552558
}),
553559
account: l2BlockAdvancerAccount,
554560
});
@@ -566,6 +572,8 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
566572
console.log('L2 create2 factory is ready\n');
567573

568574
const l2Provider = new ethers.providers.JsonRpcProvider(l2RpcUrl);
575+
l2Provider.pollingInterval = testConstants.POLLING_INTERVAL;
576+
569577
const l2Signer = new ethers.Wallet(harnessDeployer.privateKey, l2Provider);
570578

571579
console.log('Deploying L2 custom gas token...');
@@ -635,6 +643,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
635643
l2Client = createPublicClient({
636644
chain: l2Chain,
637645
transport: http(l2RpcUrl),
646+
pollingInterval: testConstants.POLLING_INTERVAL,
638647
});
639648

640649
console.log('Deploying L3 rollup contracts on L2...');
@@ -679,7 +688,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
679688
stakeToken: l3RollupConfig.stakeToken,
680689
parentChainId: l2ChainId as ParentChainId,
681690
parentChainIsArbitrum: true,
682-
parentChainRpcUrl: `http://${l2ContainerName}:8449`,
691+
parentChainRpcUrl: `http://${l2ContainerName}:${l2RpcPort}`,
683692
});
684693

685694
if (
@@ -737,11 +746,13 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
737746
const l3Client = createPublicClient({
738747
chain: l3Chain,
739748
transport: http(l3RpcUrl),
749+
pollingInterval: testConstants.POLLING_INTERVAL,
740750
});
741751
const l3WalletClient = createWalletClient({
742752
chain: l3Chain,
743753
transport: http(l3RpcUrl),
744754
account: harnessDeployer,
755+
pollingInterval: testConstants.POLLING_INTERVAL,
745756
});
746757

747758
await (
@@ -814,6 +825,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
814825
chain: l2Chain,
815826
transport: http(l2RpcUrl),
816827
account: l2BlockAdvancerAccount,
828+
pollingInterval: testConstants.POLLING_INTERVAL,
817829
});
818830

819831
const l3BlockAdvancer = createBlockAdvancer({
@@ -822,6 +834,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
822834
chain: l3Chain,
823835
transport: http(l3RpcUrl),
824836
account: l3BlockAdvancerAccount,
837+
pollingInterval: testConstants.POLLING_INTERVAL,
825838
}),
826839
account: l3BlockAdvancerAccount,
827840
});

src/integrationTestHelpers/anvilHarnessHelpers.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import { ethers } from 'ethers';
1616

1717
import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner';
1818
import { erc20ABI } from '../contracts/ERC20';
19-
import { erc20InboxABI } from '../contracts/IERC20Inbox';
19+
import { inboxABI } from '../contracts/Inbox';
20+
import { erc20InboxABI } from '../contracts/ERC20Inbox';
2021
import { tokenBridgeCreatorAddress } from '../contracts/TokenBridgeCreator';
2122
import { testConstants } from './constants';
2223
import {
@@ -92,7 +93,7 @@ async function getRequiredRetryableFunding(
9293

9394
const retryableSubmissionFee = await l1Client.readContract({
9495
address: inbox,
95-
abi: testConstants.inboxFundingAbi,
96+
abi: inboxABI,
9697
functionName: 'calculateRetryableSubmissionFee',
9798
args: [0n, l1BaseFeePerGas],
9899
});
@@ -197,13 +198,25 @@ export async function fundL2Deployer(params: {
197198
inbox: Address;
198199
}) {
199200
const { l1RpcUrl, l2RpcUrl, l2Chain, deployer, inbox } = params;
200-
const l1Client = createPublicClient({ chain: sepolia, transport: http(l1RpcUrl) });
201+
202+
const l1Client = createPublicClient({
203+
chain: sepolia,
204+
transport: http(l1RpcUrl),
205+
pollingInterval: testConstants.POLLING_INTERVAL,
206+
});
207+
201208
const l1WalletClient = createWalletClient({
202209
chain: sepolia,
203210
transport: http(l1RpcUrl),
204211
account: deployer,
212+
pollingInterval: testConstants.POLLING_INTERVAL,
213+
});
214+
215+
const l2Client = createPublicClient({
216+
chain: l2Chain,
217+
transport: http(l2RpcUrl),
218+
pollingInterval: testConstants.POLLING_INTERVAL,
205219
});
206-
const l2Client = createPublicClient({ chain: l2Chain, transport: http(l2RpcUrl) });
207220

208221
const fundAmount = parseEther('1000');
209222
const retryableGasLimit = BigInt(100_000);
@@ -225,7 +238,7 @@ export async function fundL2Deployer(params: {
225238
to: inbox,
226239
value: fundAmount + maxSubmissionCost + retryableGasLimit * l2MaxFeePerGas,
227240
data: encodeFunctionData({
228-
abi: testConstants.inboxFundingAbi,
241+
abi: inboxABI,
229242
functionName: 'createRetryableTicketNoRefundAliasRewrite',
230243
args: [
231244
deployer.address,
@@ -250,7 +263,7 @@ export async function fundL2Deployer(params: {
250263
return currentBalance;
251264
}
252265

253-
await sleep(1000);
266+
await sleep(100);
254267
}
255268

256269
throw new Error(
@@ -309,8 +322,7 @@ export async function bridgeNativeTokenToOrbitChain(params: {
309322
if (updatedBalance >= targetBalance) {
310323
return updatedBalance;
311324
}
312-
313-
await sleep(1000);
325+
await sleep(100);
314326
}
315327

316328
const finalBalance = await childPublicClient.getBalance({ address: depositor.address });
@@ -359,15 +371,21 @@ export async function setBalanceOnL1(params: {
359371
address: Address;
360372
balance: bigint;
361373
}) {
362-
const publicClient = createPublicClient({ transport: http(params.rpcUrl) });
374+
const publicClient = createPublicClient({
375+
transport: http(params.rpcUrl),
376+
pollingInterval: testConstants.POLLING_INTERVAL,
377+
});
363378
await publicClient.request({
364379
method: 'anvil_setBalance' as never,
365380
params: [params.address, `0x${params.balance.toString(16)}`] as never,
366381
});
367382
}
368383

369384
export async function refreshForkTime(params: { rpcUrl: string }) {
370-
const publicClient = createPublicClient({ transport: http(params.rpcUrl) });
385+
const publicClient = createPublicClient({
386+
transport: http(params.rpcUrl),
387+
pollingInterval: testConstants.POLLING_INTERVAL,
388+
});
371389
const now = Math.floor(Date.now() / 1000);
372390

373391
await publicClient.request({
@@ -428,7 +446,7 @@ export function startBlockAdvancing(blockAdvancer: BlockAdvancer): void {
428446
// ignore and keep advancing blocks
429447
}
430448

431-
await sleep(1000);
449+
await sleep(100);
432450
}
433451
} finally {
434452
if (blockAdvancingStates.get(blockAdvancer) === state) {
@@ -498,7 +516,11 @@ export async function deployTokenBridgeCreator(
498516
(chain.contracts.tokenBridgeCreator as ChainContract).address = address;
499517
} else {
500518
const chainId =
501-
chain?.id ?? (await createPublicClient({ transport: http(params.rpcUrl) }).getChainId());
519+
chain?.id ??
520+
(await createPublicClient({
521+
transport: http(params.rpcUrl),
522+
pollingInterval: testConstants.POLLING_INTERVAL,
523+
}).getChainId());
502524
(tokenBridgeCreatorAddress as Record<number, Address>)[chainId] = address;
503525
}
504526

0 commit comments

Comments
 (0)