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

test: forge test should be all green and exclude tests that require anvil #11148

Merged
Merged
6 changes: 3 additions & 3 deletions .github/workflows/protocol-devchain-anvil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
# Install `lsof` dependency, because it's not readily available on CI, but is required by
# `create_and_migrate_anvil_l2_devchain.sh`, because it uses `stop_anvil.sh` to kill
# existing anvil servers.
- name: Generate L1 migrations and run integration tests against L1 devchain
- name: Generate L1 migrations and run migration tests against L1 devchain
if: success() || failure()
run: |
sudo apt-get update
Expand All @@ -139,8 +139,8 @@ jobs:
echo "Starting L1 from scratch to circumvent Anvil bug"
source ./scripts/foundry/create_and_migrate_anvil_devchain.sh

forge test -vvv \
--match-path "test-sol/integration/*" \
FOUNDRY_PROFILE=devchain forge test -vvv \
--match-path "test-sol/devchain/migration/*" \
--fork-url $ANVIL_RPC_URL

./scripts/foundry/stop_anvil.sh
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/protocol_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,30 @@ jobs:
forge test -vvv \
--match-path "test-sol/unit/*"

- name: Run integration tests (that don't require an anvil devchain)
if: success() || failure()
run: |
forge test -vvv \
--match-path "test-sol/integration/*" \

- name: Generate migrations and run devchain
if: success() || failure()
run: ./scripts/foundry/create_and_migrate_anvil_devchain.sh

- name: Run integration tests against local anvil devchain
- name: Run migration tests against local anvil devchain
if: success() || failure()
run: |
source ./scripts/foundry/constants.sh

forge test -vvv \
--match-path "test-sol/integration/*" \
FOUNDRY_PROFILE=devchain forge test -vvv \
--match-path "test-sol/devchain/migration/*" \
--fork-url $ANVIL_RPC_URL

- name: Run e2e tests against local anvil devchain
if: success() || failure()
run: |
source ./scripts/foundry/constants.sh

forge test -vvv \
--match-path "test-sol/e2e/*" \
FOUNDRY_PROFILE=devchain forge test -vvv \
--match-path "test-sol/devchain/e2e/*" \
--fork-url $ANVIL_RPC_URL
13 changes: 9 additions & 4 deletions packages/protocol/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ remappings = [

no_match_test = "skip"

# `BLS12Passthrough.sol` is excluded, because it's tested in the celo-blockain repo as
# described here: https://github.com/celo-org/celo-monorepo/pull/10240
# `Random.sol` is excluded, but I'm not sure why. It was already excluded so I'm leaving it here.
no_match_path = "*test/{BLS12Passthrough.sol,RandomTest.sol}"
# 1. `BLS12Passthrough.sol` is excluded, because it's tested in the celo-blockain repo as described here: https://github.com/celo-org/celo-monorepo/pull/10240
# 2. `Random.sol` is excluded, but I'm not sure why. It was already excluded so I'm leaving it here.
arthurgousset marked this conversation as resolved.
Show resolved Hide resolved
# 3. `test-sol/devchain/` tests are excluded because they require an anvil devchain to be serving at a localhost
# Helper: Test glob patterns here: https://globster.xyz/
no_match_path = "{**/test/BLS12Passthrough.sol,**/test/RandomTest.sol,**/test-sol/devchain/**}"

fs_permissions = [
{ access = "read", path = "./out"},
Expand All @@ -34,4 +35,8 @@ fs_permissions = [
{ access = "read", path = "./artifacts/"}
]

[profile.devchain] # Special profile for the tests that require an anvil devchain
arthurgousset marked this conversation as resolved.
Show resolved Hide resolved
match_path = "**/test-sol/devchain/**"
no_match_path = "{**/test/BLS12Passthrough.sol,**/test/RandomTest.sol}"

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
42 changes: 42 additions & 0 deletions packages/protocol/test-sol/devchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Foundry tests that require an anvil devchain

All tests in this directory are intended to be run against an anvil devchain. To use `forge`
commands in this directory, consume the `[profile.devchain]` defined in
[`foundry.toml`](../../foundry.toml) by
[passing the profile as an environment variable](https://book.getfoundry.sh/config/#configuring-with-foundrytoml),
and use the `--fork-url` flag to point to the anvil devchain.

arthurgousset marked this conversation as resolved.
Show resolved Hide resolved
These tests are supposed to test the integrity of a chain after it was migrated.

For example:

1. Start a local devchain (check latest scripts in [package.json](../../package.json) in
case this command is out-of-date):

```sh
$ yarn anvil-devchain:start-L1

Waiting Anvil to launch on 8546...


_ _
(_) | |
__ _ _ __ __ __ _ | |
/ _` | | '_ \ \ \ / / | | | |
| (_| | | | | | \ V / | | | |
\__,_| |_| |_| \_/ |_| |_|

0.2.0 (f625d0f 2024-04-02T00:16:42.824772000Z)
https://github.com/foundry-rs/foundry

# ...
Listening on 127.0.0.1:8546
```

1. Run all tests in this directory against the anvil devchain serving at `$ANVIL_RPC_URL`:

```sh
$ FOUNDRY_PROFILE=devchain forge test -vvv \
--match-path "test-sol/devchain/e2e/*" \
--fork-url $ANVIL_RPC_URL
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.8.7 <0.8.20;

import "celo-foundry-8/Test.sol";
import { Devchain } from "@test-sol/e2e/utils.sol";
import { Devchain } from "@test-sol/devchain/e2e/utils.sol";

import "@celo-contracts-8/common/FeeCurrencyDirectory.sol";

Expand Down
Loading