From 62121763915ca85100994aa4bc959081c2af308c Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Thu, 18 Jul 2024 14:41:29 +0100 Subject: [PATCH 1/9] test(devchain/e2e): moves e2e demo test into new `devchain/` directory This allows us to exclude all tests in the `devchain/` directory when running `forge test` --- .../{ => devchain}/e2e/common/FeeCurrencyDirectory.t.sol | 2 +- packages/protocol/test-sol/{ => devchain}/e2e/utils.sol | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/protocol/test-sol/{ => devchain}/e2e/common/FeeCurrencyDirectory.t.sol (91%) rename packages/protocol/test-sol/{ => devchain}/e2e/utils.sol (100%) diff --git a/packages/protocol/test-sol/e2e/common/FeeCurrencyDirectory.t.sol b/packages/protocol/test-sol/devchain/e2e/common/FeeCurrencyDirectory.t.sol similarity index 91% rename from packages/protocol/test-sol/e2e/common/FeeCurrencyDirectory.t.sol rename to packages/protocol/test-sol/devchain/e2e/common/FeeCurrencyDirectory.t.sol index 26ecbb6e416..f613eb2574a 100644 --- a/packages/protocol/test-sol/e2e/common/FeeCurrencyDirectory.t.sol +++ b/packages/protocol/test-sol/devchain/e2e/common/FeeCurrencyDirectory.t.sol @@ -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"; diff --git a/packages/protocol/test-sol/e2e/utils.sol b/packages/protocol/test-sol/devchain/e2e/utils.sol similarity index 100% rename from packages/protocol/test-sol/e2e/utils.sol rename to packages/protocol/test-sol/devchain/e2e/utils.sol From 29c2ef3aec5e0f42dad17cc0bbdbccb2603a3c9a Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Thu, 18 Jul 2024 14:42:18 +0100 Subject: [PATCH 2/9] test(devchain/migration): renames migration test to Migration.t.sol Previously this was called Integration.t.sol, but that's not super obvious naming. --- .../Integration.t.sol => devchain/migration/Migration.t.sol} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/protocol/test-sol/{integration/Integration.t.sol => devchain/migration/Migration.t.sol} (100%) diff --git a/packages/protocol/test-sol/integration/Integration.t.sol b/packages/protocol/test-sol/devchain/migration/Migration.t.sol similarity index 100% rename from packages/protocol/test-sol/integration/Integration.t.sol rename to packages/protocol/test-sol/devchain/migration/Migration.t.sol From 703abe22ca4c8eba4d12d97d5ed92ef418529035 Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Thu, 18 Jul 2024 14:43:03 +0100 Subject: [PATCH 3/9] feat(foundry.toml): excludes `/devchain` directory when running `forge test` --- packages/protocol/foundry.toml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/protocol/foundry.toml b/packages/protocol/foundry.toml index f661999753f..db989319997 100644 --- a/packages/protocol/foundry.toml +++ b/packages/protocol/foundry.toml @@ -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. +# 3. `test-sol/devchain/` is excluded because all its tests 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"}, From 254bf9c087f90aa0b3b9f135f8cbee9c7ae08ee6 Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:28:58 +0100 Subject: [PATCH 4/9] feat(foundry.toml): adds profile for tests that require a devchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The configs of this profile extend or overwrite the default profile. That means we can customise the `match_path` and `no_match_path` configs in that profile and run `forge test` with that profile by passing an environment variable `FOUNDRY_PROFILE=devchain`. For example, once a devchain is serving at localhost: ```sh FOUNDRY_PROFILE=devchain forge test -vvv \ --match-path "test-sol/devchain/e2e/*" \ --fork-url $ANVIL_RPC_URL [⠒] Compiling... No files changed, compilation skipped Ran 1 test for test-sol/devchain/e2e/common/FeeCurrencyDirectory.t.sol:E2EDemo [PASS] test_ShouldAllowOwnerSetCurrencyConfig() (gas: 94493) Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 12.92ms (2.35ms CPU time) Ran 1 test suite in 164.71ms (12.92ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests) ``` --- packages/protocol/foundry.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/protocol/foundry.toml b/packages/protocol/foundry.toml index db989319997..1557a1e57f8 100644 --- a/packages/protocol/foundry.toml +++ b/packages/protocol/foundry.toml @@ -24,7 +24,7 @@ no_match_test = "skip" # 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. -# 3. `test-sol/devchain/` is excluded because all its tests require an anvil devchain to be serving at a localhost +# 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/**}" @@ -35,4 +35,8 @@ fs_permissions = [ { access = "read", path = "./artifacts/"} ] +[profile.devchain] # Special profile for the tests that require an anvil devchain +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 From a49e3bc0eb5de9602d8117b9000800c5610a649c Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:40:40 +0100 Subject: [PATCH 5/9] docs(devchain/README): adds documentation for future reference --- packages/protocol/test-sol/devchain/README.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 packages/protocol/test-sol/devchain/README.md diff --git a/packages/protocol/test-sol/devchain/README.md b/packages/protocol/test-sol/devchain/README.md new file mode 100644 index 00000000000..a4e451dca62 --- /dev/null +++ b/packages/protocol/test-sol/devchain/README.md @@ -0,0 +1,40 @@ +# 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. + +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 + ``` From 7ea5e86f9b676ffff816008e74e8b26ecd7d9fb1 Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:51:25 +0100 Subject: [PATCH 6/9] feat(workflows): adds profile env variable to CI workflows This ensures that the correct profile is consumed on CI and the correct tests are run. --- .github/workflows/protocol_tests.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/protocol_tests.yml b/.github/workflows/protocol_tests.yml index 936733fbd23..48e1313930e 100644 --- a/.github/workflows/protocol_tests.yml +++ b/.github/workflows/protocol_tests.yml @@ -121,17 +121,23 @@ 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 @@ -139,6 +145,6 @@ jobs: 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 \ No newline at end of file From 1b07f30cf9fdc35f78b8bb0d37f2a0c81552e349 Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:55:25 +0100 Subject: [PATCH 7/9] feat(workflows): adds profile env variable to CI workflows This ensures that the correct profile is consumed on CI and the correct tests are run. --- .github/workflows/protocol-devchain-anvil.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/protocol-devchain-anvil.yml b/.github/workflows/protocol-devchain-anvil.yml index e1374da8fe8..7e9461089e7 100644 --- a/.github/workflows/protocol-devchain-anvil.yml +++ b/.github/workflows/protocol-devchain-anvil.yml @@ -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 @@ -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 From 125391cd0a5b1fcedd79cef89439fde582074053 Mon Sep 17 00:00:00 2001 From: alvarof2 Date: Thu, 18 Jul 2024 17:15:59 +0200 Subject: [PATCH 8/9] Trigger Build From 64508c08c5ba004936e7cc9b8ed833aae4d3c314 Mon Sep 17 00:00:00 2001 From: Arthur Gousset <46296830+arthurgousset@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:48:47 +0100 Subject: [PATCH 9/9] docs(README): add note on devchain tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Martín Volpe --- packages/protocol/test-sol/devchain/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/protocol/test-sol/devchain/README.md b/packages/protocol/test-sol/devchain/README.md index a4e451dca62..2a5099ca230 100644 --- a/packages/protocol/test-sol/devchain/README.md +++ b/packages/protocol/test-sol/devchain/README.md @@ -6,6 +6,8 @@ commands in this directory, consume the `[profile.devchain]` defined in [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. +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