Skip to content

ci: use anvil node for fork test #1293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed
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
26 changes: 13 additions & 13 deletions .github/workflows/automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ on:
types: [opened, edited, synchronize]

jobs:
triage:
runs-on: protocol-x64-16core
name: Labels
permissions:
contents: read
pull-requests: write
# triage:
# runs-on: protocol-x64-16core
# name: Labels
# permissions:
# contents: read
# pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v4
# steps:
# - name: Checkout code
# uses: actions/checkout@v4

- uses: actions/labeler@v5
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true
# - uses: actions/labeler@v5
# with:
# repo-token: "${{ secrets.GITHUB_TOKEN }}"
# sync-labels: true

lint-pr-title:
runs-on: ubuntu-latest
Expand Down
114 changes: 114 additions & 0 deletions .github/workflows/foundry-advanced.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Foundry

on:
workflow_dispatch:
pull_request:
push:
branches:
- main


env:
FOUNDRY_PROFILE: medium

jobs:
# -----------------------------------------------------------------------
# Forge Test
# -----------------------------------------------------------------------

test-suite:
name: Test
runs-on: protocol-x64-16core
strategy:
matrix:
suite: [Fork]
max-parallel: 1

steps:
# Check out repository with all submodules for complete codebase access.
- uses: actions/checkout@v4
with:
submodules: recursive

# Restore Forge cache
- name: Cache Forge Build
uses: actions/cache@v3
with:
path: |
cache/
out/
key: ${{ runner.os }}-forge-${{ hashFiles('**/foundry.toml', '**/remappings.txt', 'src/**/*.sol', 'lib/**/*.sol') }}
restore-keys: |
${{ runner.os }}-forge-

# Install the Foundry toolchain.
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable

# Run Forge's formatting checker to ensure consistent code style.
- name: "Forge Fmt"
run: |
forge fmt --check
FOUNDRY_PROFILE=test forge fmt --check
id: fmt

# Build the project and display contract sizes.
- name: Forge Build
run: |
forge --version
forge build --sizes

# # Run the test suite in parallel based on the matrix configuration.
# - name: Run ${{ matrix.suite }} tests
# run: |
# case "${{ matrix.suite }}" in
# Fork) forge test --match-contract Integration --fork-url "${{ secrets.RPC_MAINNET }}" ;;
# esac
# env:
# FOUNDRY_PROFILE: ${{ matrix.suite == 'Fork' && 'forktest' || 'medium' }}

# Start Anvil with a forked state from mainnet
- name: Start Anvil Fork
run: |
# Show Anvil version
anvil --version

# Start Anvil with the latest block and public RPC endpoint
anvil --fork-url https://eth.llamarpc.com \
--port 8545 \
--chain-id 1 \
--block-time 12 \
--no-rate-limit \
--fork-block-number 22179220 &

# Give it time to start up
sleep 10

# Check if Anvil is running
if ! curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H "Content-Type: application/json" http://localhost:8545 > /dev/null; then
echo "Anvil failed to start properly"
exit 1
fi

# Save the PID so we can kill it later
echo $! > anvil.pid

# Run the test suite with the local Anvil instance
- name: Run ${{ matrix.suite }} tests
run: |
case "${{ matrix.suite }}" in
Fork) forge test --match-contract Integration --fork-url http://localhost:8545 --fork-retries 1 -vvv ;;
esac
env:
FOUNDRY_PROFILE: ${{ matrix.suite == 'Fork' && 'forktest' || 'medium' }}
RPC_MAINNET: "http://localhost:8545" # Set the environment variable to point to Anvil

# Clean up Anvil when done
- name: Clean up Anvil
if: always()
run: |
if [ -f anvil.pid ]; then
kill $(cat anvil.pid) || true
fi
26 changes: 12 additions & 14 deletions .github/workflows/foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ on:
pull_request:
push:
branches:
- "dev"
- main


env:
FOUNDRY_PROFILE: medium
RPC_MAINNET: ${{ secrets.RPC_MAINNET }}
RPC_HOLESKY: ${{ secrets.RPC_HOLESKY }}
CHAIN_ID: ${{ secrets.CHAIN_ID }}

jobs:
# -----------------------------------------------------------------------
Expand All @@ -24,7 +21,7 @@ jobs:
runs-on: protocol-x64-16core
strategy:
matrix:
suite: [Unit, Integration, Fork]
suite: [Unit, Integration]

steps:
# Check out repository with all submodules for complete codebase access.
Expand Down Expand Up @@ -68,7 +65,6 @@ jobs:
case "${{ matrix.suite }}" in
Unit) forge test --no-match-contract Integration ;;
Integration) forge test --match-contract Integration ;;
Fork) forge test --match-contract Integration ;;
esac
env:
FOUNDRY_PROFILE: ${{ matrix.suite == 'Fork' && 'forktest' || 'medium' }}
Expand All @@ -80,8 +76,8 @@ jobs:
continuous-fuzzing:
name: Test (Intense)
runs-on: protocol-x64-16core
# Only run on push events to dev branch, not on PR events
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
# Only run on push events to main branch, not on PR events
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
strategy:
fail-fast: true
steps:
Expand Down Expand Up @@ -120,7 +116,7 @@ jobs:
echo -e "\033[1;33mWarning: This workflow may take several hours to complete.\033[0m"
echo -e "\033[1;33mThis intense fuzzing workflow is optional but helps catch edge cases through extended testing.\033[0m"
FOUNDRY_PROFILE=intense forge test -vvv

# -----------------------------------------------------------------------
# Forge Storage Diff
# -----------------------------------------------------------------------
Expand Down Expand Up @@ -164,13 +160,15 @@ jobs:
run-coverage:
name: Coverage
runs-on: protocol-x64-16core
# Only run coverage checks on dev, testnet-holesky, and mainnet branches, or PRs targeting these branches
# Only run coverage checks on main, preprod, testnet, and mainnet branches, or PRs targeting these branches
if: |
github.ref == 'refs/heads/dev' ||
github.ref == 'refs/heads/testnet-holesky' ||
github.ref == 'refs/heads/main' ||
github.ref == 'refs/heads/preprod' ||
github.ref == 'refs/heads/testnet' ||
github.ref == 'refs/heads/mainnet' ||
github.base_ref == 'dev' ||
github.base_ref == 'testnet-holesky' ||
github.base_ref == 'main' ||
github.base_ref == 'preprod' ||
github.base_ref == 'testnet' ||
github.base_ref == 'mainnet'
strategy:
fail-fast: true
Expand Down
Loading