celo-org / celo-monorepo

Official repository for core projects comprising the Celo platform
https://celo.org
Apache License 2.0
697 stars 370 forks source link

test: proof of concept 2e2 test using anvil devchain #11020

Closed arthurgousset closed 4 months ago

arthurgousset commented 4 months ago

Description

  1. adds a Devchain class (in test-sol/e2e/utils.sol). This class can be inherited by e2e test files to have access to the deployed contracts on the devchain.
  2. adds a demo e2e test FeeCurrencyDirectory.t.sol (in test-sol/e2e/common/FeeCurrencyDirectory.t.sol) that leverages the Devchain class, and runs e2e tests against the FeeCurrencyDirectory contract on the anvil devchain
  3. adds a script to run e2e tests (run_e2e_tests_in_anvil.sh) that can be used in CI workflows.

Other changes

  1. replaces ../.. with @celo-... remapping in FeeCurrencyDirectory.t.sol

Note

I decided to keep this PR small, but in a subsequent PR, I'd like to refactor the test-sol/ directory structure like:

test-sol/unit/
test-sol/e2e/
test-sol/integration/

That way we could run tests on CI with a command structure like:

# unit tests
forge test --match-path "*test-sol/unit/*"

# e2e tests
forge test --match-path "*test-sol/e2e/*"

# integration tests
forge test --match-path "*test-sol/integration/*"

Here is an issue to track this:

Tested

Yes, tested locally ✅

Steps to reproduce e2e test locally:

  1. Create and run anvil devchain (in a separate terminal)

    cd packages/protocol
    ./migrations_sol/create_and_migrate_anvil_devchain.sh
  2. Run e2e test against anvil devchain

    forge test \
    -vvv \
    --match-path "*test-sol/e2e/*" \
    --fork-url http://127.0.0.1:8546
    
    Ran 1 test for test-sol/e2e/common/FeeCurrencyDirectory.t.sol:E2EDemo
    [PASS] test_ShouldAllowOwnerSetCurrencyConfig() (gas: 94493)
    Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 9.52ms (1.59ms CPU time)
    
    Ran 1 test suite in 176.73ms (9.52ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)

Not tested on CI. I'll include e2e tests on CI after I refactor the test-sol/ directory structure as described here:

Related issues

Backwards compatibility

Yes, only adds tests.

Documentation

No, we'll need better documentation for Foundry tests in general once the directory structure is cleaner.