Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
64 changes: 55 additions & 9 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,73 @@ jobs:
INTEGRATION_TEST_NITRO_CONTRACTS_BRANCH=${{matrix.config.nitro-contracts-branch}} \
pnpm test:integration

test-integration-anvil:
name: Test (Integration Anvil)
publish-nitro-contracts-image:
name: Publish Nitro Contracts Image
runs-on: ubuntu-latest
env:
NITRO_CONTRACTS_IMAGE_REF: v3.2.0-2f747c7
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set nitro contracts image
run: |
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts:v3.2.0-2f747c7" >> "$GITHUB_ENV"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build nitro contracts image
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Check nitro contracts image
id: check-image
run: |
if docker manifest inspect "${NITRO_CONTRACTS_GHCR_IMAGE}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi

- name: Build and push nitro contracts image
if: steps.check-image.outputs.exists != 'true'
uses: docker/build-push-action@v6
with:
context: ./nitro-contracts
file: ./nitro-contracts/Dockerfile
tags: chain-sdk-nitro-contracts:${{ env.NITRO_CONTRACTS_IMAGE_REF }}
load: true
cache-from: type=gha,scope=chain-sdk-nitro-contracts-${{ env.NITRO_CONTRACTS_IMAGE_REF }}
cache-to: type=gha,mode=max,scope=chain-sdk-nitro-contracts-${{ env.NITRO_CONTRACTS_IMAGE_REF }}
push: true
tags: |
${{ env.NITRO_CONTRACTS_GHCR_IMAGE }}

test-integration-anvil:
name: Test (Integration Anvil)
needs: publish-nitro-contracts-image
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set nitro contracts image
run: |
echo "NITRO_CONTRACTS_GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chain-sdk-nitro-contracts:v3.2.0-2f747c7" >> "$GITHUB_ENV"

- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Load nitro contracts image
run: docker pull "${NITRO_CONTRACTS_GHCR_IMAGE}"

- name: Setup pnpm
uses: pnpm/action-setup@v4
Expand Down
2 changes: 1 addition & 1 deletion src/integrationTestHelpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ethers } from 'ethers';
export const testConstants = {
DEFAULT_ANVIL_IMAGE: 'ghcr.io/foundry-rs/foundry:v1.3.1',
DEFAULT_NITRO_IMAGE: 'offchainlabs/nitro-node:v3.9.5-66e42c4',
DEFAULT_NITRO_CONTRACTS_REF: 'v3.2.0-2f747c7',
DEFAULT_NITRO_CONTRACTS_IMAGE: 'ghcr.io/offchainlabs/chain-sdk-nitro-contracts:v3.2.0-2f747c7',
DEFAULT_L2_CHAIN_ID: 421_337,
DEFAULT_L3_CHAIN_ID: 421_338,
DEFAULT_L1_RPC_PORT: 9645,
Expand Down
19 changes: 7 additions & 12 deletions src/integrationTestHelpers/dockerHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,19 @@ export function dockerAsync(args: string[]): Promise<string> {
});
}

function sanitizeDockerTagPart(value: string): string {
return value.replace(/[^a-zA-Z0-9_.-]+/g, '-');
}

export function getNitroContractsImage(): string {
const imageTag = `chain-sdk-nitro-contracts:${sanitizeDockerTagPart(
testConstants.DEFAULT_NITRO_CONTRACTS_REF,
)}`;

const image =
process.env.NITRO_CONTRACTS_GHCR_IMAGE ?? testConstants.DEFAULT_NITRO_CONTRACTS_IMAGE;
try {
docker(['image', 'inspect', imageTag]);
docker(['image', 'inspect', image]);
return image;
} catch {
const nitroContractsDir = join(process.cwd(), 'nitro-contracts');
const dockerfilePath = join(process.cwd(), 'nitro-contracts', 'Dockerfile');
docker(['build', '-f', dockerfilePath, '-t', imageTag, nitroContractsDir]);
}
docker(['build', '-f', dockerfilePath, '-t', image, nitroContractsDir]);

return imageTag;
return image;
}
}

export function createDockerNetwork(networkName: string) {
Expand Down
Loading