Skip to content

Commit 6cff42a

Browse files
committed
test: use a single docker image for contracts
1 parent d72f044 commit 6cff42a

File tree

8 files changed

+134
-111
lines changed

8 files changed

+134
-111
lines changed

.github/workflows/build-test.yml

Lines changed: 15 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ jobs:
226226
INTEGRATION_TEST_NITRO_CONTRACTS_BRANCH=${{matrix.config.nitro-contracts-branch}} \
227227
pnpm test:integration
228228
229-
publish-nitro-contracts-image:
230-
name: Publish Nitro Contracts Image
229+
publish-int-test-contracts-image:
230+
name: Publish Integration Test Contracts Image
231231
runs-on: ubuntu-latest
232232
permissions:
233233
contents: read
@@ -236,9 +236,9 @@ jobs:
236236
- name: Checkout
237237
uses: actions/checkout@v4
238238

239-
- name: Set nitro contracts image
239+
- name: Set integration test contracts image
240240
run: |
241-
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts-anvil:v3.2.0-2f747c7" >> "$GITHUB_ENV"
241+
echo "INT_TEST_CONTRACTS_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-int-test-contracts:v3.2.0-2f747c7-v1.2.5-5975d8f73608" >> "$GITHUB_ENV"
242242
243243
- name: Set up Docker Buildx
244244
uses: docker/setup-buildx-action@v3
@@ -250,73 +250,29 @@ jobs:
250250
username: ${{ github.actor }}
251251
password: ${{ secrets.GITHUB_TOKEN }}
252252

253-
- name: Check nitro contracts image
253+
- name: Check integration test contracts image
254254
id: check-image
255255
run: |
256-
if docker manifest inspect "${NITRO_CONTRACTS_GHCR_IMAGE}" >/dev/null 2>&1; then
256+
if docker manifest inspect "${INT_TEST_CONTRACTS_IMAGE}" >/dev/null 2>&1; then
257257
echo "exists=true" >> "$GITHUB_OUTPUT"
258258
else
259259
echo "exists=false" >> "$GITHUB_OUTPUT"
260260
fi
261261
262-
- name: Build and push nitro contracts image
262+
- name: Build and push integration test contracts image
263263
if: steps.check-image.outputs.exists != 'true'
264264
uses: docker/build-push-action@v6
265265
with:
266-
context: ./nitro-contracts
267-
file: ./nitro-contracts/Dockerfile
266+
context: ./src/integrationTestHelpers/docker-test-contracts
267+
file: ./src/integrationTestHelpers/docker-test-contracts/Dockerfile
268268
push: true
269269
tags: |
270-
${{ env.NITRO_CONTRACTS_GHCR_IMAGE }}
271-
272-
publish-token-bridge-contracts-image:
273-
name: Publish Token Bridge Contracts Image
274-
runs-on: ubuntu-latest
275-
permissions:
276-
contents: read
277-
packages: write
278-
steps:
279-
- name: Checkout
280-
uses: actions/checkout@v4
281-
282-
- name: Set token bridge contracts image
283-
run: |
284-
echo "TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-token-bridge-contracts-anvil:v1.2.5-5975d8f73608" >> "$GITHUB_ENV"
285-
286-
- name: Set up Docker Buildx
287-
uses: docker/setup-buildx-action@v3
288-
289-
- name: Log in to GHCR
290-
uses: docker/login-action@v3
291-
with:
292-
registry: ghcr.io
293-
username: ${{ github.actor }}
294-
password: ${{ secrets.GITHUB_TOKEN }}
295-
296-
- name: Check token bridge contracts image
297-
id: check-image
298-
run: |
299-
if docker manifest inspect "${TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE}" >/dev/null 2>&1; then
300-
echo "exists=true" >> "$GITHUB_OUTPUT"
301-
else
302-
echo "exists=false" >> "$GITHUB_OUTPUT"
303-
fi
304-
305-
- name: Build and push token bridge contracts image
306-
if: steps.check-image.outputs.exists != 'true'
307-
uses: docker/build-push-action@v6
308-
with:
309-
context: ./token-bridge-contracts
310-
file: ./token-bridge-contracts/Dockerfile.anvil
311-
push: true
312-
tags: |
313-
${{ env.TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE }}
270+
${{ env.INT_TEST_CONTRACTS_IMAGE }}
314271
315272
test-integration-anvil:
316273
name: Test (Integration Anvil)
317274
needs:
318-
- publish-nitro-contracts-image
319-
- publish-token-bridge-contracts-image
275+
- publish-int-test-contracts-image
320276
runs-on: ubuntu-latest
321277
permissions:
322278
contents: read
@@ -325,10 +281,9 @@ jobs:
325281
- name: Checkout
326282
uses: actions/checkout@v4
327283

328-
- name: Set nitro contracts image
284+
- name: Set integration test contracts image
329285
run: |
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"
286+
echo "INT_TEST_CONTRACTS_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-int-test-contracts:v3.2.0-2f747c7-v1.2.5-5975d8f73608" >> "$GITHUB_ENV"
332287
333288
- name: Log in to GHCR
334289
uses: docker/login-action@v3
@@ -337,11 +292,8 @@ jobs:
337292
username: ${{ github.actor }}
338293
password: ${{ secrets.GITHUB_TOKEN }}
339294

340-
- name: Load nitro contracts image
341-
run: docker pull "${NITRO_CONTRACTS_GHCR_IMAGE}"
342-
343-
- name: Load token bridge contracts image
344-
run: docker pull "${TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE}"
295+
- name: Load integration test contracts image
296+
run: docker pull "${INT_TEST_CONTRACTS_IMAGE}"
345297

346298
- name: Setup pnpm
347299
uses: pnpm/action-setup@v4

anvil-tooling/entrypoint.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
if [ "$#" -lt 2 ]; then
6+
echo "usage: chain-sdk-int-test-contracts <nitro-contracts|token-bridge-contracts> <command> [args...]" >&2
7+
exit 1
8+
fi
9+
10+
workspace="$1"
11+
shift
12+
13+
case "$workspace" in
14+
nitro-contracts)
15+
cd /workspace/nitro-contracts
16+
;;
17+
token-bridge-contracts)
18+
cd /workspace/token-bridge-contracts
19+
;;
20+
*)
21+
echo "unknown workspace: $workspace" >&2
22+
exit 1
23+
;;
24+
esac
25+
26+
exec yarn "$@"

src/integrationTestHelpers/anvilHarnessHelpers.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ import { tokenBridgeCreatorAddress } from '../contracts/TokenBridgeCreator';
2222
import { testConstants } from './constants';
2323
import {
2424
dockerAsync,
25-
getNitroContractsImage,
25+
getIntTestContractsImage,
2626
getRollupCreatorDockerArgs,
27-
getTokenBridgeContractsImage,
2827
getTokenBridgeCreatorDockerArgs,
2928
} from './dockerHelpers';
3029
import type { PrivateKeyAccountWithPrivateKey } from '../testHelpers';
@@ -472,7 +471,7 @@ async function withBlockAdvancing<T>(
472471
}
473472

474473
export async function deployRollupCreator(params: DeployRollupCreatorParams): Promise<Address> {
475-
const nitroContractsImage = getNitroContractsImage();
474+
const intTestContractsImage = getIntTestContractsImage();
476475
const stdout = await withBlockAdvancing(params.blockAdvancer, () =>
477476
dockerAsync(
478477
getRollupCreatorDockerArgs(
@@ -483,7 +482,7 @@ export async function deployRollupCreator(params: DeployRollupCreatorParams): Pr
483482
maxDataSize: params.maxDataSize,
484483
chainId: params.chainId,
485484
},
486-
nitroContractsImage,
485+
intTestContractsImage,
487486
),
488487
),
489488
);
@@ -494,15 +493,15 @@ export async function deployRollupCreator(params: DeployRollupCreatorParams): Pr
494493
export async function deployTokenBridgeCreator(
495494
params: DeployTokenBridgeCreatorParams,
496495
): Promise<Address> {
497-
const tokenBridgeContractsImage = getTokenBridgeContractsImage();
496+
const intTestContractsImage = getIntTestContractsImage();
498497
const hostname = new URL(params.rpcUrl).hostname;
499498
const rpcUrl = params.rpcUrl.replace(hostname, 'host.docker.internal');
500499

501500
const deploy = () =>
502501
dockerAsync(
503502
getTokenBridgeCreatorDockerArgs(
504503
{ ...params, rpcUrl, addHostDockerInternal: true },
505-
tokenBridgeContractsImage,
504+
intTestContractsImage,
506505
),
507506
);
508507

src/integrationTestHelpers/constants.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import { ethers } from 'ethers';
44
export const testConstants = {
55
ANVIL_IMAGE: 'ghcr.io/foundry-rs/foundry:v1.3.1',
66
NITRO_IMAGE: 'offchainlabs/nitro-node:v3.9.5-66e42c4',
7-
DEFAULT_NITRO_CONTRACTS_IMAGE:
8-
'ghcr.io/offchainlabs/chain-sdk-nitro-contracts-anvil:v3.2.0-2f747c7',
9-
DEFAULT_TOKEN_BRIDGE_CONTRACTS_IMAGE:
10-
'ghcr.io/offchainlabs/chain-sdk-token-bridge-contracts-anvil:v1.2.5-5975d8f73608',
7+
INT_TEST_CONTRACTS_IMAGE:
8+
'ghcr.io/offchainlabs/chain-sdk-int-test-contracts:v3.2.0-2f747c7-v1.2.5-5975d8f73608',
119
DEPLOYER_PRIVATE_KEY:
1210
'0x490d84b7602e4b470af4f86a3ad095607a8bb5a4fa8ba148f41fcfd236b4fdf5' as Address,
1311
L2_CHAIN_ID: 421_337,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM ghcr.io/foundry-rs/foundry:v1.3.1 AS foundry
2+
3+
FROM node:20-bullseye-slim AS builder
4+
5+
COPY --from=foundry /usr/local/bin/forge /usr/local/bin/forge
6+
7+
RUN apt-get update \
8+
&& apt-get install -y git python3 build-essential \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
WORKDIR /workspace
12+
13+
RUN mkdir nitro-contracts
14+
WORKDIR /workspace/nitro-contracts
15+
RUN git init . \
16+
&& git remote add origin https://github.com/OffchainLabs/nitro-contracts.git \
17+
&& git fetch --depth 1 origin 2f747c722d98d5fd662bfda08cd86aa534b22be2 \
18+
&& git checkout --detach FETCH_HEAD \
19+
&& git submodule update --init --recursive --depth 1
20+
RUN cp scripts/config.example.ts scripts/config.ts
21+
RUN yarn install --frozen-lockfile
22+
RUN yarn build:all
23+
24+
WORKDIR /workspace
25+
RUN mkdir token-bridge-contracts
26+
WORKDIR /workspace/token-bridge-contracts
27+
RUN git init . \
28+
&& git remote add origin https://github.com/OffchainLabs/token-bridge-contracts.git \
29+
&& git fetch --depth 1 origin 5975d8f7360816341be7f94fd333ef240f4aec23 \
30+
&& git checkout --detach FETCH_HEAD
31+
RUN yarn install --frozen-lockfile
32+
RUN yarn build
33+
34+
FROM node:20-bullseye-slim
35+
36+
WORKDIR /workspace
37+
38+
COPY --from=builder /workspace/nitro-contracts /workspace/nitro-contracts
39+
COPY --from=builder /workspace/token-bridge-contracts /workspace/token-bridge-contracts
40+
COPY entrypoint.sh /usr/local/bin/chain-sdk-int-test-contracts
41+
42+
RUN chmod +x /usr/local/bin/chain-sdk-int-test-contracts
43+
44+
ENTRYPOINT ["chain-sdk-int-test-contracts"]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
if [ "$#" -lt 2 ]; then
6+
echo "usage: chain-sdk-int-test-contracts <nitro-contracts|token-bridge-contracts> <command> [args...]" >&2
7+
exit 1
8+
fi
9+
10+
workspace="$1"
11+
shift
12+
13+
case "$workspace" in
14+
nitro-contracts)
15+
cd /workspace/nitro-contracts
16+
;;
17+
token-bridge-contracts)
18+
cd /workspace/token-bridge-contracts
19+
;;
20+
*)
21+
echo "unknown workspace: $workspace" >&2
22+
exit 1
23+
;;
24+
esac
25+
26+
exec yarn "$@"

src/integrationTestHelpers/dockerHelpers.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,20 @@ export function dockerAsync(args: string[]): Promise<string> {
3636
});
3737
}
3838

39-
export function getNitroContractsImage(): string {
40-
const image =
41-
process.env.NITRO_CONTRACTS_GHCR_IMAGE ?? testConstants.DEFAULT_NITRO_CONTRACTS_IMAGE;
39+
export function getIntTestContractsImage(): string {
40+
const image = testConstants.INT_TEST_CONTRACTS_IMAGE;
4241
try {
4342
docker(['image', 'inspect', image]);
4443
return image;
4544
} catch {
46-
const nitroContractsDir = join(process.cwd(), 'nitro-contracts');
47-
const dockerfilePath = join(process.cwd(), 'nitro-contracts', 'Dockerfile');
48-
docker(['build', '-f', dockerfilePath, '-t', image, nitroContractsDir]);
49-
50-
return image;
51-
}
52-
}
53-
54-
export function getTokenBridgeContractsImage(): string {
55-
const image =
56-
process.env.TOKEN_BRIDGE_CONTRACTS_GHCR_IMAGE ??
57-
testConstants.DEFAULT_TOKEN_BRIDGE_CONTRACTS_IMAGE;
58-
try {
59-
docker(['image', 'inspect', image]);
60-
return image;
61-
} catch {
62-
const tokenBridgeContractsDir = join(process.cwd(), 'token-bridge-contracts');
63-
const dockerfilePath = join(tokenBridgeContractsDir, 'Dockerfile.anvil');
64-
docker(['build', '-f', dockerfilePath, '-t', image, tokenBridgeContractsDir]);
45+
const intTestContractsDir = join(
46+
process.cwd(),
47+
'src',
48+
'integrationTestHelpers',
49+
'docker-test-contracts',
50+
);
51+
const dockerfilePath = join(intTestContractsDir, 'Dockerfile');
52+
docker(['build', '-f', dockerfilePath, '-t', image, intTestContractsDir]);
6553

6654
return image;
6755
}
@@ -75,7 +63,7 @@ export function getRollupCreatorDockerArgs(
7563
maxDataSize: number;
7664
chainId: number;
7765
},
78-
nitroContractsImage: string,
66+
intTestContractsImage: string,
7967
) {
8068
return [
8169
'run',
@@ -98,7 +86,8 @@ export function getRollupCreatorDockerArgs(
9886
'DISABLE_VERIFICATION=true',
9987
'-e',
10088
'IGNORE_MAX_DATA_SIZE_WARNING=true',
101-
nitroContractsImage,
89+
intTestContractsImage,
90+
'nitro-contracts',
10291
'hardhat',
10392
'run',
10493
'--no-compile',
@@ -116,7 +105,7 @@ export function getTokenBridgeCreatorDockerArgs(
116105
wethAddress: Address;
117106
addHostDockerInternal?: boolean;
118107
},
119-
tokenBridgeContractsImage: string,
108+
intTestContractsImage: string,
120109
) {
121110
return [
122111
'run',
@@ -135,7 +124,8 @@ export function getTokenBridgeCreatorDockerArgs(
135124
`POLLING_INTERVAL=${testConstants.POLLING_INTERVAL}`,
136125
'-e',
137126
'DISABLE_CONTRACT_VERIFICATION=true',
138-
tokenBridgeContractsImage,
127+
intTestContractsImage,
128+
'token-bridge-contracts',
139129
'deploy:token-bridge-creator',
140130
];
141131
}

token-bridge-contracts/Dockerfile.anvil

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)