Skip to content

Commit

Permalink
feat: /foundry is canoncial build of foundry. e2e tests can start own…
Browse files Browse the repository at this point in the history
… anvil. (#5522)

We want e2e tests to be able to launch their own anvil. This will enable
deterministic L1 states for the test.
* We use viems anvil package and get-port to find a random port to run
anvil on, and launch it and use it if no `ETHEREUM_HOST` env var is set.
* Anvil is wrapped in wrapper script to ensure it's process is killed
when the parent dies, no matter what.
* This is as close as we can get to what looks like an "in-memory"
blockchain for testing with no side-effects.
* Anvil needs to be present *within* the e2e image to achieve this. This
means we need an x86 and arm build of anvil in our image, and we want it
to be whatever our chosen version of foundry is (which is often some
random pinned nightly that only has x86 builds).
* Solution, foundry build in monorepo! `/foundry` now contains an
Earthly ubuntu build of foundry using their `local` build target which
keeps builds at about 1m on a decent core machine.
* L1 contracts, yarn-project, and any other code that uses foundry,
should take foundry from the foundry image we build.
* We also do some cleanup in `yarn-project/Earthfile`, and leverage
layer caching to only reinstall dependencies if bb.js, noir-packages, or
package.json files change.

---------

Co-authored-by: ludamad <[email protected]>
Co-authored-by: ludamad <[email protected]>
  • Loading branch information
3 people authored Apr 5, 2024
1 parent eb66fc6 commit 510daa0
Show file tree
Hide file tree
Showing 21 changed files with 245 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .github/ci-setup-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ runs:
id: cache-submodules
uses: actions/cache@v3
with:
path: .git
path: .git/modules
key: submodules-${{ hashFiles('.gitmodules') }}

- name: Checkout Submodules
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
- name: Build
working-directory: ./yarn-project
run: |
# push to registry
earthly-cloud build x86 --push +build-end-to-end
# We base our e2e list used in e2e-x86 off the targets in ./yarn-project/end-to-end
Expand Down Expand Up @@ -111,14 +110,14 @@ jobs:
run: |
docker pull aztecprotocol/aztec-cache:$(git rev-parse HEAD)
docker pull aztecprotocol/end-to-end-cache:$(git rev-parse HEAD)
docker pull aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-amd64:latest
docker tag aztecprotocol/aztec-cache:$(git rev-parse HEAD) aztecprotocol/aztec:latest
docker tag aztecprotocol/end-to-end-cache:$(git rev-parse HEAD) aztecprotocol/end-to-end:latest
docker tag aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-amd64:latest aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-amd64:latest
- name: Test
working-directory: ./yarn-project/end-to-end/
run: |
# we blank earthly token just to be sure this is a pure local run
EARTHLY_TOKEN="" earthly -P --no-output +${{ matrix.test }} --e2e_mode=cache
earthly -P --no-output +${{ matrix.test }} --e2e_mode=cache
# barretenberg (prover) native tests
bb-native-tests:
Expand Down
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build-ci:
BUILD ./noir/+packages
BUILD ./noir/+nargo
BUILD ./noir-projects/+build
BUILD ./yarn-project/+end-to-end-minimal
BUILD ./yarn-project/+end-to-end
BUILD ./yarn-project/+aztec

build-ci-small:
Expand Down
1 change: 1 addition & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ git submodule update --init --recursive
PROJECTS=(
barretenberg
noir
foundry
l1-contracts
avm-transpiler
noir-projects
Expand Down
2 changes: 2 additions & 0 deletions foundry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
foundry-repo
35 changes: 0 additions & 35 deletions foundry/Dockerfile

This file was deleted.

28 changes: 16 additions & 12 deletions foundry/Earthfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
VERSION 0.8

builder:
FROM rust:bookworm
ARG TARGETARCH
WORKDIR /usr/src/foundry
COPY bootstrap.sh bootstrap.sh
RUN ./bootstrap.sh && rm -rf foundry-repo
SAVE ARTIFACT bin /usr/src/foundry/bin

build:
FROM ubuntu:lunar
ARG TARGETARCH
FROM DOCKERFILE .
COPY --dir +builder/usr/src/foundry/bin /usr/src/foundry/bin
SAVE ARTIFACT /usr/src/foundry/bin /usr/src/foundry/bin
SAVE IMAGE --push aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-$TARGETARCH:latest

# Relies on both steps being published
build-multiplatform:
FROM --platform=linux/amd64 aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-amd64:latest
SAVE IMAGE --push aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991:latest
FROM --platform=linux/arm64 aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991-arm64:latest
SAVE IMAGE --push aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991:latest

get:
ARG TARGETARCH
# If this is failing, we need to run earthly --push +build on both archs then earthly --push +build-multiplatform on any runner
FROM aztecprotocol/foundry-nightly-de33b6af53005037b463318d2628b5cfcaf3991:latest
build-save-local:
# for renaming the image as a local image, used with e2e runners
ARG image
FROM +build
SAVE IMAGE $image
25 changes: 25 additions & 0 deletions foundry/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -eu

cd $(dirname $0)

rm -rf bin share

[ "${TARGETARCH:-$(uname -m)}" = "arm64" ] && echo "export CFLAGS=-mno-outline-atomics" >> $HOME/.profile || true

if [ ! -d './foundry-repo' ]; then
git clone --depth 1 --branch nightly-de33b6af53005037b463318d2628b5cfcaf39916 \
https://github.com/foundry-rs/foundry.git foundry-repo
fi

(cd foundry-repo && cargo build --profile local)

mkdir bin \
&& mv foundry-repo/target/local/forge bin/forge \
&& mv foundry-repo/target/local/cast bin/cast \
&& mv foundry-repo/target/local/anvil bin/anvil \
&& mv foundry-repo/target/local/chisel bin/chisel \
&& strip bin/forge \
&& strip bin/cast \
&& strip bin/chisel \
&& strip bin/anvil;
30 changes: 15 additions & 15 deletions l1-contracts/Earthfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
VERSION 0.8
FROM ubuntu:lunar
RUN apt update && apt install curl git jq bash nodejs npm python3.11-full python3-pip -y

# Use virtualenv, do not try to use pipx, it's not working.
RUN python3 -m venv /root/.venv
RUN /root/.venv/bin/pip3 install slither-analyzer==0.10.0 slitherin==0.5.0
RUN curl -L https://foundry.paradigm.xyz | bash
build:
FROM ubuntu:lunar
RUN apt update && apt install curl git jq bash nodejs npm python3.11-full python3-pip -y

# Set env variables for foundry and venv
ENV PATH="${PATH}:/root/.foundry/bin:/root/.venv/bin"
RUN foundryup --version nightly-de33b6af53005037b463318d2628b5cfcaf39916
# Use virtualenv, do not try to use pipx, it's not working.
RUN python3 -m venv /root/.venv
RUN /root/.venv/bin/pip3 install slither-analyzer==0.10.0 slitherin==0.5.0
ENV PATH="${PATH}:/root/.venv/bin"

# Install yarn and solhint.
RUN npm install --global yarn solhint
# Install yarn and solhint.
RUN npm install --global yarn solhint

WORKDIR /usr/src
COPY --dir lib scripts src terraform test *.json *.toml *.sh .
# Install our build of foundry.
COPY --dir ../foundry/+build/usr/src/foundry/bin /usr/src/foundry/bin
ENV PATH="${PATH}:/usr/src/foundry/bin"

build:
WORKDIR /usr/src/l1-contracts
COPY --dir lib scripts src terraform test *.json *.toml *.sh .
RUN git init && git add . && yarn lint && yarn slither && yarn slither-has-diff
RUN forge clean && forge fmt --check && forge build && forge test --no-match-contract UniswapPortalTest
SAVE ARTIFACT out
SAVE ARTIFACT /usr/src/l1-contracts /usr/src/l1-contracts
7 changes: 2 additions & 5 deletions l1-contracts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ fi
# Attempt to just pull artefacts from CI and exit on success.
[ -n "${USE_CACHE:-}" ] && ./bootstrap_cache.sh && exit

# Install foundry.
. ./scripts/install_foundry.sh

# Clean
rm -rf broadcast cache out serve

# Install
forge install --no-commit
../foundry/bin/forge install --no-commit

# Ensure libraries are at the correct version
git submodule update --init --recursive ./lib

# Compile contracts
forge build
../foundry/bin/forge build
4 changes: 2 additions & 2 deletions l1-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"solhint": "https://github.com/LHerskind/solhint#master"
},
"scripts": {
"format": "./.foundry/bin/forge fmt",
"format": "../foundry/bin/forge fmt",
"lint": "solhint --config ./.solhint.json --fix \"src/**/*.sol\"",
"slither": "forge clean && forge build --build-info --skip '*/test/**' --force && slither . --checklist --ignore-compile --show-ignored-findings --config-file ./slither.config.json | tee slither_output.md",
"slither": "../foundry/bin/forge clean && ../foundry/bin/forge build --build-info --skip '*/test/**' --force && slither . --checklist --ignore-compile --show-ignored-findings --config-file ./slither.config.json | tee slither_output.md",
"slither-has-diff": "./slither_has_diff.sh"
}
}
29 changes: 0 additions & 29 deletions l1-contracts/scripts/install_foundry.sh

This file was deleted.

Loading

0 comments on commit 510daa0

Please sign in to comment.