Skip to content
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

ci: use anvil node for fork test #1293

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
49 changes: 47 additions & 2 deletions .github/workflows/foundry-advanced.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
strategy:
matrix:
suite: [Fork]
max-parallel: 1

steps:
# Check out repository with all submodules for complete codebase access.
Expand Down Expand Up @@ -59,11 +60,55 @@ jobs:
forge --version
forge build --sizes

# Run the test suite in parallel based on the matrix configuration.
# # 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 "${{ secrets.RPC_MAINNET }}" ;;
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
Loading