Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Dockerize Integration Tests (ethereum-optimism#670)
Browse files Browse the repository at this point in the history
* test: add docker image for integration tests

* feat: add to docker-compose with scale 0

* ci: run and publish integration tests to dockerhub

* test: add option to not bring network up for docker integration tests

* chore: add --fail --show-error to curl
  • Loading branch information
gakonst authored May 3, 2021
1 parent e401a5c commit cf0907e
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 15 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,13 @@ jobs:
working-directory: ./ops
run: ./scripts/build-ci.sh

- name: Run the integration tests
working-directory: ./integration-tests
run: |
yarn build:contracts
yarn build:contracts:ovm
yarn test:integration
env:
FORCE_COLOR: 1
ENABLE_GAS_REPORT: 1
- name: Bring the stack up
working-directory: ./ops
run: docker-compose up -d

- name: Print gas report
run: cat integration-tests/gas-report.txt
- name: Run the integration tests
working-directory: ./ops
run: docker-compose run integration_tests

# Examples Tests
- name: Test & deploy hardhat-example on hardhat (regression)
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ jobs:
message-relayer: ${{ needs.release.outputs.message-relayer }}
data-transport-layer: ${{ needs.release.outputs.data-transport-layer }}
contracts: ${{ needs.release.outputs.contracts }}
integration-tests: ${{ needs.release.outputs.integration-tests }}

steps:
- name: Checkout
Expand Down Expand Up @@ -228,3 +229,29 @@ jobs:
file: ./ops/docker/Dockerfile.deployer
push: true
tags: ethereumoptimism/deployer:${{ needs.builder.outputs.contracts }}

integration_tests:
name: Publish Integration tests ${{ needs.builder.outputs.integration-tests }}
needs: builder
if: needs.builder.outputs.integration-tests != ''
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_ACCESS_TOKEN_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN_SECRET }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./ops/docker/Dockerfile.integration-tests
push: true
tags: ethereumoptimism/integration-tests:${{ needs.builder.outputs.integration-tests }}
2 changes: 1 addition & 1 deletion integration-tests/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config: HardhatUserConfig = {
},
networks: {
optimism: {
url: 'http://localhost:8545',
url: process.env.L2_URL || 'http://localhost:8545',
ovm: true,
},
},
Expand Down
6 changes: 4 additions & 2 deletions integration-tests/test/setup-docker-compose-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ const { DockerComposeNetwork } = require("./shared/docker-compose")


before(async () => {
await new DockerComposeNetwork().up()
})
if (!process.env.NO_NETWORK) {
await new DockerComposeNetwork().up()
}
})
15 changes: 15 additions & 0 deletions ops/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,18 @@ services:
L2_NODE_WEB3_URL: http://l2geth:8545
URL: http://deployer:8081/addresses.json
SEQUENCER_PRIVATE_KEY: "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"

integration_tests:
image: ethereumoptimism/integration-tests
deploy:
replicas: 0
build:
context: ..
dockerfile: ./ops/docker/Dockerfile.integration-tests
entrypoint: ./integration-tests.sh
environment:
L1_URL: http://l1_chain:8545
L2_URL: http://l2geth:8545
URL: http://deployer:8081/addresses.json
ENABLE_GAS_REPORT: 1
NO_NETWORK: 1
26 changes: 26 additions & 0 deletions ops/docker/Dockerfile.integration-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ethereumoptimism/builder AS builder

FROM node:14-alpine

RUN apk add --no-cache git curl python bash jq

WORKDIR /opt/optimism/

COPY --from=builder /optimism/*.json /optimism/yarn.lock ./
COPY --from=builder /optimism/node_modules ./node_modules

# copy deps (would have been nice if docker followed the symlinks required)
COPY --from=builder /optimism/packages/core-utils/package.json ./packages/core-utils/package.json
COPY --from=builder /optimism/packages/core-utils/dist ./packages/core-utils/dist

COPY --from=builder /optimism/packages/hardhat-ovm/package.json ./packages/hardhat-ovm/package.json
COPY --from=builder /optimism/packages/hardhat-ovm/dist ./packages/hardhat-ovm/dist

COPY --from=builder /optimism/packages/contracts ./packages/contracts

# get the needed built artifacts
WORKDIR /opt/optimism/integration-tests
COPY --from=builder /optimism/integration-tests ./

COPY ./ops/scripts/integration-tests.sh ./
ENTRYPOINT yarn test:integration
5 changes: 5 additions & 0 deletions ops/docker/Dockerfile.monorepo
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ COPY packages/contracts/package.json ./packages/contracts/package.json
COPY packages/data-transport-layer/package.json ./packages/data-transport-layer/package.json
COPY packages/batch-submitter/package.json ./packages/batch-submitter/package.json
COPY packages/message-relayer/package.json ./packages/message-relayer/package.json
COPY integration-tests/package.json ./integration-tests/package.json

RUN yarn install --frozen-lockfile

Expand All @@ -45,17 +46,21 @@ WORKDIR /optimism
# code changes
COPY --from=builder /optimism/node_modules ./node_modules
COPY --from=builder /optimism/packages ./packages
COPY --from=builder /optimism/integration-tests ./integration-tests

# the following steps are cheap
COPY *.json yarn.lock ./
# copy over the source
COPY ./packages ./packages
COPY ./integration-tests ./integration-tests
# copy over solc to save time building (35+ seconds vs not doing this step)
COPY --from=downloader solc /root/.cache/hardhat-nodejs/compilers/linux-amd64/solc-linux-amd64-v0.7.6+commit.7338295f
COPY --from=downloader ovm-solc /root/.cache/hardhat-nodejs/compilers/ovm/0.7.6.js

# build it!
RUN yarn build
# build integration tests' contracts
RUN yarn workspace @eth-optimism/integration-tests build:integration
# get the dump
RUN yarn --cwd ./packages/contracts ts-node bin/take-dump.ts

Expand Down
2 changes: 1 addition & 1 deletion ops/scripts/build-ci.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# build in 2 steps
function build_images() {
docker-compose build --parallel -- builder l2geth l1_chain
docker-compose build --parallel -- deployer dtl batch_submitter relayer
docker-compose build --parallel -- deployer dtl batch_submitter relayer integration_test
}

function build_dependencies() {
Expand Down
26 changes: 26 additions & 0 deletions ops/scripts/integration-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -e

RETRIES=${RETRIES:-60}
JSON='{"jsonrpc":"2.0","id":0,"method":"rollup_getInfo","params":[]}'

if [[ ! -z "$URL" ]]; then
# get the addrs from the URL provided
ADDRESSES=$(curl --fail --show-error --silent --retry-connrefused --retry $RETRIES --retry-delay 5 $URL)
export ADDRESS_MANAGER=$(echo $ADDRESSES | jq -r '.AddressManager')
fi

# wait for the sequencer to be up
curl \
--silent \
--fail \
--show-error \
-H "Content-Type: application/json" \
--retry-connrefused \
--retry $RETRIES \
--retry-delay 3 \
-d $JSON \
--output /dev/null \
$L2_URL

npx hardhat test --network optimism --no-compile

0 comments on commit cf0907e

Please sign in to comment.