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: proof of concept 2e2 test using anvil devchain #11020

Merged

Conversation

arthurgousset
Copy link
Contributor

@arthurgousset arthurgousset commented Jun 5, 2024

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.

MVP demo of an e2e test using the devchain. This is not the pattern I'll suggest, but good to see the test passes end-to-end.
@arthurgousset arthurgousset force-pushed the arthurgousset/test/anvil-proof-of-concept-2e2-test branch from 335a9c2 to 06416ac Compare June 5, 2024 14:23
@arthurgousset arthurgousset self-assigned this Jun 5, 2024
@arthurgousset arthurgousset force-pushed the arthurgousset/test/anvil-proof-of-concept-2e2-test branch from 082d130 to b5dc987 Compare June 6, 2024 09:55
I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```
I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```
In subsequent PRs, I'll rename this more accurately.
@arthurgousset arthurgousset merged commit b10b77a into master Jun 7, 2024
22 of 24 checks passed
@arthurgousset arthurgousset deleted the arthurgousset/test/anvil-proof-of-concept-2e2-test branch June 7, 2024 08:19
soloseng added a commit that referenced this pull request Jun 12, 2024
* test: proof of concept 2e2 test using anvil devchain (#11020)

* chore(test-sol/FeeCurrencyDirectory)): use `@celo-...` remapping not `../..`

* test(test-sol/FeeCurrencyDirectory)): MVP e2e test

MVP demo of an e2e test using the devchain. This is not the pattern I'll suggest, but good to see the test passes end-to-end.

* chore(foundry.toml): adds `@test-sol` remapping

* chore(test-sol/e2e): adds MVP `utils.sol`

Idea is to have a Devchain class that can be inherited by Test contracts to have access to the deployed contracts on the devchain.

* test(FeeCurrencyDirectory): MVP test using `Devchain` class

* chore(migrations_sol): adds MVP script to run e2e tests

* style(test-sol/e2e): linting

* refactor(test-sol/FeeCurrencyDirectory): moves file to `.../e2e/`

* chore(migrations_sol): use `test-sol/e2e/*` path

* chore(test-sol/FeeCurrencyDirectory): match contract name in unit and e2e test

* style(test-sol/FeeCurrencyDirectory): linting

* chore(e2e/utils): removes unused imports and more

Cleans up
Adds `TODO` comments

* test(test-sol/e2e): renames contract with "E2E..."

I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```

* chore(workflows/protocol_tests): excludes e2e test from workflow

I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```

* style(test-sol/e2e): linting

* chore(e2e): temporarily renames contract with "E2E..."

In subsequent PRs, I'll rename this more accurately.

* feat: add ReserveSpenderMultiSig to anvil migrations (#11028)

* feat(migrations_sol/migrationsConfig): adds `reserveSpenderMultiSig` configs

* feat(migrations_sol): adds `migrateReserveSpenderMultiSig`

Also adds contract calls in `migrateReserve` function.
Not tested, and not sure this works yet. I might be missing some changes.

* chore(test-sol/utils): adds `ReserveSpenderMultiSig.t.sol`

From the code comment:

  The purpose of this file is not to provide test coverage for `ReserveSpenderMultiSig.sol`.
  This is an empty test to force foundry to compile `ReserveSpenderMultiSig.sol`, and include its
  artifacts in the `/out` directory. `ReserveSpenderMultiSig.sol` is needed in the migrations
  script, but because it's on Solidity 0.5 it can't be imported there directly.
  If there is a better way to force foundry to compile `ReserveSpenderMultiSig.sol` without
  this file, this file can confidently be deleted.

* feat(migrations_sol/HelperInterFaces): adds `IReserveSpenderMultiSig`

The helper interface is used as a workaround to allow the migrations script (`Migrations.s.sol`) to be on Solidity 0.8, while the ReserveSpenderMultiSig contract is on Solidity 0.5. The migration script only needs to initialize the contract, which is why the helper interface only defines an `initialize` function.

* chore(migrations_sol): initialize `ReserveSpenderMultiSig`

* chore(migrations_sol): adds code comment for readability

* chore(migrations_sol): improves code comment, moves code block up

* chore(migrations_sol): fix typo

* style(migrations_sol): linting

* test: refactor foundry test directory into unit, e2e, and integration tests (#11023)

* chore(foundry.toml): adds `@mento-core/...` remapping

Also moves existing mappings into groups for better readability

* refactor(test-sol/common): moves files to `unit/common/`

Also updates imports respectively using remappings.

* refactor(test-sol/identity): moves files to `unit/identity/`

Also updates imports using remappings where necessary.

* refactor(test-sol/stability): moves files to `unit/stability/`

Also updates imports using remappings where necessary.

* refactor(test-sol/voting): moves files to `unit/voting/`

Also updates imports using remappings where necessary.

* refactor(test-sol/governance): moves files to `unit/governance/`

Also updates imports using remappings where necessary.

* chore(test-sol): update missing remappings

With these changes all contracts compile and resolve correctly.

* chore(workflows/protocol_tests): updates paths to `test-sol/unit`

* chore(workflows/protocol_tests): adds integration and e2e tests

* style(workflows/protocol_tests): refactors `forge test` for better readability

* chore(migrations_sol): moves scripts to `scripts/foundry/

Moves all bash scripts from `migrations_sol` to `scripts/foundry/`, and updates paths where necessary. We already have a directory for `scripts/truffle/` and `scripts/bash/`, so this makes it easier to find foundry-related bash scripts.

* test(governance/mock): move `MockGovernance` to `unit/` folder

* refactor(foundry.toml): rename `migrations-sol/` remapping

* refactor(workflows): refactor "run everything" step

Runs all tests in the `unit/` directory instead of all test files in the repo.
This makes sense from my perspective, because e2e tests (in the `e2e/` directory) and integration tests (in the `integration/` directory) require a connection to an anvil devchain serving at localhost.

The intent of this command is to ensure that no unit tests are forgotten, since unit tests are run explicitly by going through the directories above. But, the intention is not to run all tests in the repo generally.

* style(workflows/protocol-devchain-anvil): splits migration into 2 steps

This helps the script becoming more readable, and ensure error logs are clearly associated with a workflow step rather than a single bash script.

* chore(workflows): defines `ANVIL_PORT` env variable in workflow

Previously, the `$ANVIL_PORT` variable was exported and passed around as an env variable in a bash script.

But that required generating anvil migrations and running a devchain repeatedly.
Instead, the workflow does that once and different steps can access the devchain.

But, in that case the env variable is not passed around, so it has to be defined at the workflow level.

Source: https://docs.github.com/en/actions/learn-github-actions/variables

* chore(workflows/protocol_tests): removes code comment

* feat(scripts/foundry): adds `stop_anvil.sh`

* refactor(scripts/foundry): use `stop_anvil.sh` to stop anvil

* feat(protocol/package.json): adds `anvil-devchain:...` (`start` and `stop`)

* refactor(scripts/foundry): use `stop_anvil.sh` to stop anvil

* refactor(migrations_sol): update `@migrations-sol` remapping

Previous the remapping was called `@celo-migrations`.

* docs(migrations_sol/README): renames README file

Also changes title to match NPM package name. This is a matter of personal preference. IMO this is a small improvement in readability for 3rd party users.

* docs(scripts/foundry): adds more links to `package.json`

Adds `repository` and `directory` to `package.json`.
This ensures npmjs.org displays hyperlinks to the github repository.

* docs(migrations_sol/CONTRIBUTING): adds MVP dev docs

We can complete this doc with additional information regarding the anvil devchain and migrations going forward.

* docs(migrations_sol/README): adds "how we work" section

This is helpful for 3rd party developers that found this package on npmjs.org.
The links help developers take action and help improve the anvil devchain.

* Soloseng/CHORE-update-workflow (#11029)

* update workflow to run on push to release branches

* ++ mintgoldschedule to migration test constants

* update GH WF

---------

Co-authored-by: Arthur Gousset <[email protected]>
soloseng added a commit that referenced this pull request Jun 18, 2024
* test: proof of concept 2e2 test using anvil devchain (#11020)

* chore(test-sol/FeeCurrencyDirectory)): use `@celo-...` remapping not `../..`

* test(test-sol/FeeCurrencyDirectory)): MVP e2e test

MVP demo of an e2e test using the devchain. This is not the pattern I'll suggest, but good to see the test passes end-to-end.

* chore(foundry.toml): adds `@test-sol` remapping

* chore(test-sol/e2e): adds MVP `utils.sol`

Idea is to have a Devchain class that can be inherited by Test contracts to have access to the deployed contracts on the devchain.

* test(FeeCurrencyDirectory): MVP test using `Devchain` class

* chore(migrations_sol): adds MVP script to run e2e tests

* style(test-sol/e2e): linting

* refactor(test-sol/FeeCurrencyDirectory): moves file to `.../e2e/`

* chore(migrations_sol): use `test-sol/e2e/*` path

* chore(test-sol/FeeCurrencyDirectory): match contract name in unit and e2e test

* style(test-sol/FeeCurrencyDirectory): linting

* chore(e2e/utils): removes unused imports and more

Cleans up
Adds `TODO` comments

* test(test-sol/e2e): renames contract with "E2E..."

I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```

* chore(workflows/protocol_tests): excludes e2e test from workflow

I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```

* style(test-sol/e2e): linting

* chore(e2e): temporarily renames contract with "E2E..."

In subsequent PRs, I'll rename this more accurately.

* set EpochSize on L2

* allow voting and activating

* move election test contract to vote dir

* updated test to allow testing of L2 with no reward distribution

* feat: add ReserveSpenderMultiSig to anvil migrations (#11028)

* feat(migrations_sol/migrationsConfig): adds `reserveSpenderMultiSig` configs

* feat(migrations_sol): adds `migrateReserveSpenderMultiSig`

Also adds contract calls in `migrateReserve` function.
Not tested, and not sure this works yet. I might be missing some changes.

* chore(test-sol/utils): adds `ReserveSpenderMultiSig.t.sol`

From the code comment:

  The purpose of this file is not to provide test coverage for `ReserveSpenderMultiSig.sol`.
  This is an empty test to force foundry to compile `ReserveSpenderMultiSig.sol`, and include its
  artifacts in the `/out` directory. `ReserveSpenderMultiSig.sol` is needed in the migrations
  script, but because it's on Solidity 0.5 it can't be imported there directly.
  If there is a better way to force foundry to compile `ReserveSpenderMultiSig.sol` without
  this file, this file can confidently be deleted.

* feat(migrations_sol/HelperInterFaces): adds `IReserveSpenderMultiSig`

The helper interface is used as a workaround to allow the migrations script (`Migrations.s.sol`) to be on Solidity 0.8, while the ReserveSpenderMultiSig contract is on Solidity 0.5. The migration script only needs to initialize the contract, which is why the helper interface only defines an `initialize` function.

* chore(migrations_sol): initialize `ReserveSpenderMultiSig`

* chore(migrations_sol): adds code comment for readability

* chore(migrations_sol): improves code comment, moves code block up

* chore(migrations_sol): fix typo

* style(migrations_sol): linting

* test: refactor foundry test directory into unit, e2e, and integration tests (#11023)

* chore(foundry.toml): adds `@mento-core/...` remapping

Also moves existing mappings into groups for better readability

* refactor(test-sol/common): moves files to `unit/common/`

Also updates imports respectively using remappings.

* refactor(test-sol/identity): moves files to `unit/identity/`

Also updates imports using remappings where necessary.

* refactor(test-sol/stability): moves files to `unit/stability/`

Also updates imports using remappings where necessary.

* refactor(test-sol/voting): moves files to `unit/voting/`

Also updates imports using remappings where necessary.

* refactor(test-sol/governance): moves files to `unit/governance/`

Also updates imports using remappings where necessary.

* chore(test-sol): update missing remappings

With these changes all contracts compile and resolve correctly.

* chore(workflows/protocol_tests): updates paths to `test-sol/unit`

* chore(workflows/protocol_tests): adds integration and e2e tests

* style(workflows/protocol_tests): refactors `forge test` for better readability

* chore(migrations_sol): moves scripts to `scripts/foundry/

Moves all bash scripts from `migrations_sol` to `scripts/foundry/`, and updates paths where necessary. We already have a directory for `scripts/truffle/` and `scripts/bash/`, so this makes it easier to find foundry-related bash scripts.

* test(governance/mock): move `MockGovernance` to `unit/` folder

* refactor(foundry.toml): rename `migrations-sol/` remapping

* refactor(workflows): refactor "run everything" step

Runs all tests in the `unit/` directory instead of all test files in the repo.
This makes sense from my perspective, because e2e tests (in the `e2e/` directory) and integration tests (in the `integration/` directory) require a connection to an anvil devchain serving at localhost.

The intent of this command is to ensure that no unit tests are forgotten, since unit tests are run explicitly by going through the directories above. But, the intention is not to run all tests in the repo generally.

* style(workflows/protocol-devchain-anvil): splits migration into 2 steps

This helps the script becoming more readable, and ensure error logs are clearly associated with a workflow step rather than a single bash script.

* chore(workflows): defines `ANVIL_PORT` env variable in workflow

Previously, the `$ANVIL_PORT` variable was exported and passed around as an env variable in a bash script.

But that required generating anvil migrations and running a devchain repeatedly.
Instead, the workflow does that once and different steps can access the devchain.

But, in that case the env variable is not passed around, so it has to be defined at the workflow level.

Source: https://docs.github.com/en/actions/learn-github-actions/variables

* chore(workflows/protocol_tests): removes code comment

* feat(scripts/foundry): adds `stop_anvil.sh`

* refactor(scripts/foundry): use `stop_anvil.sh` to stop anvil

* feat(protocol/package.json): adds `anvil-devchain:...` (`start` and `stop`)

* refactor(scripts/foundry): use `stop_anvil.sh` to stop anvil

* refactor(migrations_sol): update `@migrations-sol` remapping

Previous the remapping was called `@celo-migrations`.

* docs(migrations_sol/README): renames README file

Also changes title to match NPM package name. This is a matter of personal preference. IMO this is a small improvement in readability for 3rd party users.

* docs(scripts/foundry): adds more links to `package.json`

Adds `repository` and `directory` to `package.json`.
This ensures npmjs.org displays hyperlinks to the github repository.

* docs(migrations_sol/CONTRIBUTING): adds MVP dev docs

We can complete this doc with additional information regarding the anvil devchain and migrations going forward.

* docs(migrations_sol/README): adds "how we work" section

This is helpful for 3rd party developers that found this package on npmjs.org.
The links help developers take action and help improve the anvil devchain.

* lint: function order

* Soloseng/CHORE-update-workflow (#11029)

* update workflow to run on push to release branches

* ++ mintgoldschedule to migration test constants

* initial validators contract review

* Remove block gas limit flag for `governance/voting` CI tests

* bump version

* ++ tests && format

* removed comments

* getValidatorGroupSlashingMultiplier allowed only on L1

* reverting changes to test contract size issue

* minimal changes

* allow slashing multiplier reset on L2

---------

Co-authored-by: Arthur Gousset <[email protected]>
soloseng added a commit that referenced this pull request Jun 18, 2024
* Yaml file drafts

* Update COPUSD Config

* Update KESUSD and rename USDKES.yaml to KESUSD.yaml

* Rename USDCOP.yaml to COPUSD.yaml

* Adding KESUSD data source

* CELOKES and KESUSD config

* chore: test USDTUSD config

* fix: remove openexchangerates from kesusd

* chore: add pair constants

* chore: add alfajores & baklava kesusd and usdtusd addresses

* fix: use pnpm instead of yarn

* fix: update min oracles for CELOKES

* chore: add mainnet kes hsms

* USDTUSD config from Nadiem

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

* chore(test-sol/FeeCurrencyDirectory)): use `@celo-...` remapping not `../..`

* test(test-sol/FeeCurrencyDirectory)): MVP e2e test

MVP demo of an e2e test using the devchain. This is not the pattern I'll suggest, but good to see the test passes end-to-end.

* chore(foundry.toml): adds `@test-sol` remapping

* chore(test-sol/e2e): adds MVP `utils.sol`

Idea is to have a Devchain class that can be inherited by Test contracts to have access to the deployed contracts on the devchain.

* test(FeeCurrencyDirectory): MVP test using `Devchain` class

* chore(migrations_sol): adds MVP script to run e2e tests

* style(test-sol/e2e): linting

* refactor(test-sol/FeeCurrencyDirectory): moves file to `.../e2e/`

* chore(migrations_sol): use `test-sol/e2e/*` path

* chore(test-sol/FeeCurrencyDirectory): match contract name in unit and e2e test

* style(test-sol/FeeCurrencyDirectory): linting

* chore(e2e/utils): removes unused imports and more

Cleans up
Adds `TODO` comments

* test(test-sol/e2e): renames contract with "E2E..."

I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```

* chore(workflows/protocol_tests): excludes e2e test from workflow

I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```

* style(test-sol/e2e): linting

* chore(e2e): temporarily renames contract with "E2E..."

In subsequent PRs, I'll rename this more accurately.

* chore: latest deployed images

* feat: add ReserveSpenderMultiSig to anvil migrations (#11028)

* feat(migrations_sol/migrationsConfig): adds `reserveSpenderMultiSig` configs

* feat(migrations_sol): adds `migrateReserveSpenderMultiSig`

Also adds contract calls in `migrateReserve` function.
Not tested, and not sure this works yet. I might be missing some changes.

* chore(test-sol/utils): adds `ReserveSpenderMultiSig.t.sol`

From the code comment:

  The purpose of this file is not to provide test coverage for `ReserveSpenderMultiSig.sol`.
  This is an empty test to force foundry to compile `ReserveSpenderMultiSig.sol`, and include its
  artifacts in the `/out` directory. `ReserveSpenderMultiSig.sol` is needed in the migrations
  script, but because it's on Solidity 0.5 it can't be imported there directly.
  If there is a better way to force foundry to compile `ReserveSpenderMultiSig.sol` without
  this file, this file can confidently be deleted.

* feat(migrations_sol/HelperInterFaces): adds `IReserveSpenderMultiSig`

The helper interface is used as a workaround to allow the migrations script (`Migrations.s.sol`) to be on Solidity 0.8, while the ReserveSpenderMultiSig contract is on Solidity 0.5. The migration script only needs to initialize the contract, which is why the helper interface only defines an `initialize` function.

* chore(migrations_sol): initialize `ReserveSpenderMultiSig`

* chore(migrations_sol): adds code comment for readability

* chore(migrations_sol): improves code comment, moves code block up

* chore(migrations_sol): fix typo

* style(migrations_sol): linting

* test: refactor foundry test directory into unit, e2e, and integration tests (#11023)

* chore(foundry.toml): adds `@mento-core/...` remapping

Also moves existing mappings into groups for better readability

* refactor(test-sol/common): moves files to `unit/common/`

Also updates imports respectively using remappings.

* refactor(test-sol/identity): moves files to `unit/identity/`

Also updates imports using remappings where necessary.

* refactor(test-sol/stability): moves files to `unit/stability/`

Also updates imports using remappings where necessary.

* refactor(test-sol/voting): moves files to `unit/voting/`

Also updates imports using remappings where necessary.

* refactor(test-sol/governance): moves files to `unit/governance/`

Also updates imports using remappings where necessary.

* chore(test-sol): update missing remappings

With these changes all contracts compile and resolve correctly.

* chore(workflows/protocol_tests): updates paths to `test-sol/unit`

* chore(workflows/protocol_tests): adds integration and e2e tests

* style(workflows/protocol_tests): refactors `forge test` for better readability

* chore(migrations_sol): moves scripts to `scripts/foundry/

Moves all bash scripts from `migrations_sol` to `scripts/foundry/`, and updates paths where necessary. We already have a directory for `scripts/truffle/` and `scripts/bash/`, so this makes it easier to find foundry-related bash scripts.

* test(governance/mock): move `MockGovernance` to `unit/` folder

* refactor(foundry.toml): rename `migrations-sol/` remapping

* refactor(workflows): refactor "run everything" step

Runs all tests in the `unit/` directory instead of all test files in the repo.
This makes sense from my perspective, because e2e tests (in the `e2e/` directory) and integration tests (in the `integration/` directory) require a connection to an anvil devchain serving at localhost.

The intent of this command is to ensure that no unit tests are forgotten, since unit tests are run explicitly by going through the directories above. But, the intention is not to run all tests in the repo generally.

* style(workflows/protocol-devchain-anvil): splits migration into 2 steps

This helps the script becoming more readable, and ensure error logs are clearly associated with a workflow step rather than a single bash script.

* chore(workflows): defines `ANVIL_PORT` env variable in workflow

Previously, the `$ANVIL_PORT` variable was exported and passed around as an env variable in a bash script.

But that required generating anvil migrations and running a devchain repeatedly.
Instead, the workflow does that once and different steps can access the devchain.

But, in that case the env variable is not passed around, so it has to be defined at the workflow level.

Source: https://docs.github.com/en/actions/learn-github-actions/variables

* chore(workflows/protocol_tests): removes code comment

* feat(scripts/foundry): adds `stop_anvil.sh`

* refactor(scripts/foundry): use `stop_anvil.sh` to stop anvil

* feat(protocol/package.json): adds `anvil-devchain:...` (`start` and `stop`)

* refactor(scripts/foundry): use `stop_anvil.sh` to stop anvil

* refactor(migrations_sol): update `@migrations-sol` remapping

Previous the remapping was called `@celo-migrations`.

* docs(migrations_sol/README): renames README file

Also changes title to match NPM package name. This is a matter of personal preference. IMO this is a small improvement in readability for 3rd party users.

* docs(scripts/foundry): adds more links to `package.json`

Adds `repository` and `directory` to `package.json`.
This ensures npmjs.org displays hyperlinks to the github repository.

* docs(migrations_sol/CONTRIBUTING): adds MVP dev docs

We can complete this doc with additional information regarding the anvil devchain and migrations going forward.

* docs(migrations_sol/README): adds "how we work" section

This is helpful for 3rd party developers that found this package on npmjs.org.
The links help developers take action and help improve the anvil devchain.

* Soloseng/CHORE-update-workflow (#11029)

* update workflow to run on push to release branches

* ++ mintgoldschedule to migration test constants

* set celo-foundry to 0.5

* force CI test after changing PR base

---------

Co-authored-by: Nadiem Sissouno <[email protected]>
Co-authored-by: Nadiem Sissouno <[email protected]>
Co-authored-by: Nelson Taveras <[email protected]>
Co-authored-by: Arthur Gousset <[email protected]>
Co-authored-by: soloseng <[email protected]>
soloseng added a commit that referenced this pull request Jul 16, 2024
* lint: function ordering

* Deprecate L1 hotfix;
Implement L2 hotfix;

* BUMP version

* prepare hotfix on L2

* cleanup

* ++ setters and checks

* ++ more test cases

* PR feedback

* PR feedback

* PR feedback

* resetHotfix is public

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

* chore(test-sol/FeeCurrencyDirectory)): use `@celo-...` remapping not `../..`

* test(test-sol/FeeCurrencyDirectory)): MVP e2e test

MVP demo of an e2e test using the devchain. This is not the pattern I'll suggest, but good to see the test passes end-to-end.

* chore(foundry.toml): adds `@test-sol` remapping

* chore(test-sol/e2e): adds MVP `utils.sol`

Idea is to have a Devchain class that can be inherited by Test contracts to have access to the deployed contracts on the devchain.

* test(FeeCurrencyDirectory): MVP test using `Devchain` class

* chore(migrations_sol): adds MVP script to run e2e tests

* style(test-sol/e2e): linting

* refactor(test-sol/FeeCurrencyDirectory): moves file to `.../e2e/`

* chore(migrations_sol): use `test-sol/e2e/*` path

* chore(test-sol/FeeCurrencyDirectory): match contract name in unit and e2e test

* style(test-sol/FeeCurrencyDirectory): linting

* chore(e2e/utils): removes unused imports and more

Cleans up
Adds `TODO` comments

* test(test-sol/e2e): renames contract with "E2E..."

I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```

* chore(workflows/protocol_tests): excludes e2e test from workflow

I'm temporarily adding the "E2E..." prefix to the contract so I can exclude this test and the integration tests during the CI run.

In a separate PR, I'll refactor the tests into a directory structure like:

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

That way we could run tests with something like this:

```
# 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/*"
```

* style(test-sol/e2e): linting

* chore(e2e): temporarily renames contract with "E2E..."

In subsequent PRs, I'll rename this more accurately.

* feat: add ReserveSpenderMultiSig to anvil migrations (#11028)

* feat(migrations_sol/migrationsConfig): adds `reserveSpenderMultiSig` configs

* feat(migrations_sol): adds `migrateReserveSpenderMultiSig`

Also adds contract calls in `migrateReserve` function.
Not tested, and not sure this works yet. I might be missing some changes.

* chore(test-sol/utils): adds `ReserveSpenderMultiSig.t.sol`

From the code comment:

  The purpose of this file is not to provide test coverage for `ReserveSpenderMultiSig.sol`.
  This is an empty test to force foundry to compile `ReserveSpenderMultiSig.sol`, and include its
  artifacts in the `/out` directory. `ReserveSpenderMultiSig.sol` is needed in the migrations
  script, but because it's on Solidity 0.5 it can't be imported there directly.
  If there is a better way to force foundry to compile `ReserveSpenderMultiSig.sol` without
  this file, this file can confidently be deleted.

* feat(migrations_sol/HelperInterFaces): adds `IReserveSpenderMultiSig`

The helper interface is used as a workaround to allow the migrations script (`Migrations.s.sol`) to be on Solidity 0.8, while the ReserveSpenderMultiSig contract is on Solidity 0.5. The migration script only needs to initialize the contract, which is why the helper interface only defines an `initialize` function.

* chore(migrations_sol): initialize `ReserveSpenderMultiSig`

* chore(migrations_sol): adds code comment for readability

* chore(migrations_sol): improves code comment, moves code block up

* chore(migrations_sol): fix typo

* style(migrations_sol): linting

* test: refactor foundry test directory into unit, e2e, and integration tests (#11023)

* chore(foundry.toml): adds `@mento-core/...` remapping

Also moves existing mappings into groups for better readability

* refactor(test-sol/common): moves files to `unit/common/`

Also updates imports respectively using remappings.

* refactor(test-sol/identity): moves files to `unit/identity/`

Also updates imports using remappings where necessary.

* refactor(test-sol/stability): moves files to `unit/stability/`

Also updates imports using remappings where necessary.

* refactor(test-sol/voting): moves files to `unit/voting/`

Also updates imports using remappings where necessary.

* refactor(test-sol/governance): moves files to `unit/governance/`

Also updates imports using remappings where necessary.

* chore(test-sol): update missing remappings

With these changes all contracts compile and resolve correctly.

* chore(workflows/protocol_tests): updates paths to `test-sol/unit`

* chore(workflows/protocol_tests): adds integration and e2e tests

* style(workflows/protocol_tests): refactors `forge test` for better readability

* chore(migrations_sol): moves scripts to `scripts/foundry/

Moves all bash scripts from `migrations_sol` to `scripts/foundry/`, and updates paths where necessary. We already have a directory for `scripts/truffle/` and `scripts/bash/`, so this makes it easier to find foundry-related bash scripts.

* test(governance/mock): move `MockGovernance` to `unit/` folder

* refactor(foundry.toml): rename `migrations-sol/` remapping

* refactor(workflows): refactor "run everything" step

Runs all tests in the `unit/` directory instead of all test files in the repo.
This makes sense from my perspective, because e2e tests (in the `e2e/` directory) and integration tests (in the `integration/` directory) require a connection to an anvil devchain serving at localhost.

The intent of this command is to ensure that no unit tests are forgotten, since unit tests are run explicitly by going through the directories above. But, the intention is not to run all tests in the repo generally.

* style(workflows/protocol-devchain-anvil): splits migration into 2 steps

This helps the script becoming more readable, and ensure error logs are clearly associated with a workflow step rather than a single bash script.

* chore(workflows): defines `ANVIL_PORT` env variable in workflow

Previously, the `$ANVIL_PORT` variable was exported and passed around as an env variable in a bash script.

But that required generating anvil migrations and running a devchain repeatedly.
Instead, the workflow does that once and different steps can access the devchain.

But, in that case the env variable is not passed around, so it has to be defined at the workflow level.

Source: https://docs.github.com/en/actions/learn-github-actions/variables

* chore(workflows/protocol_tests): removes code comment

* feat(scripts/foundry): adds `stop_anvil.sh`

* refactor(scripts/foundry): use `stop_anvil.sh` to stop anvil

* feat(protocol/package.json): adds `anvil-devchain:...` (`start` and `stop`)

* refactor(scripts/foundry): use `stop_anvil.sh` to stop anvil

* refactor(migrations_sol): update `@migrations-sol` remapping

Previous the remapping was called `@celo-migrations`.

* docs(migrations_sol/README): renames README file

Also changes title to match NPM package name. This is a matter of personal preference. IMO this is a small improvement in readability for 3rd party users.

* docs(scripts/foundry): adds more links to `package.json`

Adds `repository` and `directory` to `package.json`.
This ensures npmjs.org displays hyperlinks to the github repository.

* docs(migrations_sol/CONTRIBUTING): adds MVP dev docs

We can complete this doc with additional information regarding the anvil devchain and migrations going forward.

* docs(migrations_sol/README): adds "how we work" section

This is helpful for 3rd party developers that found this package on npmjs.org.
The links help developers take action and help improve the anvil devchain.

* Soloseng/CHORE-update-workflow (#11029)

* update workflow to run on push to release branches

* ++ mintgoldschedule to migration test constants

* fixed inheritance

* added pretest check

---------

Co-authored-by: Arthur Gousset <[email protected]>
Co-authored-by: Leszek Stachowski <[email protected]>
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.

Design proof of concept e2e test against Anvil devchain
2 participants