-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
95af1c6
commit b10b77a
Showing
6 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/protocol/migrations_sol/run_e2e_tests_in_anvil.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# Generate and run devchain | ||
echo "Generating and running devchain before running e2e tests..." | ||
source $PWD/migrations_sol/create_and_migrate_anvil_devchain.sh | ||
|
||
# Run e2e tests | ||
echo "Running e2e tests..." | ||
forge test \ | ||
-vvv \ | ||
--match-path "*test-sol/e2e/*" \ | ||
--fork-url http://127.0.0.1:$ANVIL_PORT | ||
|
||
# helper kill anvil | ||
# kill $(lsof -i tcp:$ANVIL_PORT | tail -n 1 | awk '{print $2}') | ||
|
||
echo "Killing Anvil" | ||
if [[ -n $ANVIL_PID ]]; then | ||
kill $ANVIL_PID | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/protocol/test-sol/e2e/common/FeeCurrencyDirectory.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.7 <0.8.20; | ||
|
||
import "celo-foundry-8/Test.sol"; | ||
import { Devchain } from "@test-sol/e2e/utils.sol"; | ||
|
||
import "@celo-contracts-8/common/FeeCurrencyDirectory.sol"; | ||
|
||
contract E2EDemo is Test, Devchain { | ||
function test_ShouldAllowOwnerSetCurrencyConfig() public { | ||
address token = address(1); | ||
uint256 intrinsicGas = 21000; | ||
|
||
vm.prank(feeCurrencyDirectory.owner()); | ||
feeCurrencyDirectory.setCurrencyConfig(token, address(sortedOracles), intrinsicGas); | ||
FeeCurrencyDirectory.CurrencyConfig memory config = feeCurrencyDirectory.getCurrencyConfig( | ||
token | ||
); | ||
|
||
assertEq(config.oracle, address(sortedOracles)); | ||
assertEq(config.intrinsicGas, intrinsicGas); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.7 <0.8.20; | ||
|
||
import "@celo-contracts-8/common/UsingRegistry.sol"; | ||
import "@celo-contracts/common/interfaces/IRegistry.sol"; | ||
|
||
// All core contracts that are expected to be in the Registry on the devchain | ||
import "@celo-contracts-8/common/FeeCurrencyDirectory.sol"; | ||
import "@celo-contracts/stability/interfaces/ISortedOracles.sol"; | ||
|
||
contract Devchain is UsingRegistry { | ||
address constant registryAddress = address(0x000000000000000000000000000000000000ce10); | ||
|
||
// Used in exceptional circumstances when a contract is not in UsingRegistry.sol | ||
IRegistry devchainRegistry = IRegistry(registryAddress); | ||
|
||
// All core contracts that are expected to be in the Registry on the devchain | ||
ISortedOracles sortedOracles; | ||
FeeCurrencyDirectory feeCurrencyDirectory; | ||
|
||
constructor() { | ||
// The following line is required by UsingRegistry.sol | ||
setRegistry(registryAddress); | ||
|
||
// Fetch all core contracts that are expeceted to be in the Registry on the devchain | ||
sortedOracles = getSortedOracles(); | ||
feeCurrencyDirectory = FeeCurrencyDirectory( | ||
devchainRegistry.getAddressForStringOrDie("FeeCurrencyDirectory") | ||
); // FeeCurrencyDirectory is not in UsingRegistry.sol | ||
|
||
// TODO: Add missing core contracts below (see list in migrations_sol/constants.sol) | ||
// TODO: Consider asserting that all contracts we expect are available in the Devchain class | ||
// (see list in migrations_sol/constants.sol) | ||
} | ||
} |