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

Conversation

arthurgousset
Copy link
Contributor

@arthurgousset arthurgousset commented Jul 18, 2024

Description

  1. adds a Foundry profile in foundry.toml ([profile.devchain]) that defines custom configs when passing the FOUNDRY_PROFILE=devchain env variable in Foundry commands (e.g. FOUNDRY_PROFILE=devchain forge test)
  2. adds a config in the default Foundry profile ([profile.default]) to exclude all files in **/test-sol/devchain/** when running forge test

Other changes

  1. creates new test-sol/devchain/ directory.
  2. moves e2e/ directory to devchain/ directory.
  3. renames migration test to Migration.t.sol (formerly Integration.t.sol), and moves it to devchain/migration directory.

Tested

Tested locally and on CI.

  1. forge test is all green ✅

    $ forge test
  2. forge test in devchain/ directory is all green ✅

    # with anvil instance running locally
    FOUNDRY_PROFILE=devchain forge test -vvv \
    --match-path "test-sol/devchain/migration/*" \
    --fork-url $ANVIL_RPC_URL

Related issues

Backwards compatibility

Brief explanation of why these changes are/are not backwards compatible.

Documentation

Yes, copy-pasted from test-sol/devchain/README.md:

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 by passing the profile as an environment variable, 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 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
    ```
    
  2. Run all tests in this directory against the anvil devchain serving at $ANVIL_RPC_URL:

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

This allows us to exclude all tests in the `devchain/` directory when running `forge test`
Previously this was called Integration.t.sol, but that's not super obvious naming.
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)
```
This ensures that the correct profile is consumed on CI and the correct tests are run.
This ensures that the correct profile is consumed on CI and the correct tests are run.
Copy link

gitguardian bot commented Jul 18, 2024

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
Once a secret has been leaked into a git repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@arthurgousset arthurgousset changed the base branch from master to release/core-contracts/12 July 18, 2024 14:56
@arthurgousset arthurgousset marked this pull request as ready for review July 18, 2024 14:58
@arthurgousset arthurgousset requested review from a team as code owners July 18, 2024 14:58
@arthurgousset arthurgousset marked this pull request as draft July 18, 2024 14:59
@arthurgousset arthurgousset marked this pull request as ready for review July 18, 2024 15:36
@arthurgousset arthurgousset merged commit d464ce5 into release/core-contracts/12 Jul 19, 2024
23 checks passed
@arthurgousset arthurgousset deleted the arthurgousset/test/forge-test-all-green branch July 19, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

forge test should be all green and exclude e2e tests that require a devchain
3 participants