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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f4b5c45
chore(test-sol/FeeCurrencyDirectory)): use `@celo-...` remapping not …
arthurgousset Jun 5, 2024
06416ac
test(test-sol/FeeCurrencyDirectory)): MVP e2e test
arthurgousset Jun 5, 2024
327d761
chore(foundry.toml): adds `@test-sol` remapping
arthurgousset Jun 6, 2024
ad195d0
chore(test-sol/e2e): adds MVP `utils.sol`
arthurgousset Jun 6, 2024
e925181
test(FeeCurrencyDirectory): MVP test using `Devchain` class
arthurgousset Jun 6, 2024
23432eb
chore(migrations_sol): adds MVP script to run e2e tests
arthurgousset Jun 6, 2024
687e3e0
style(test-sol/e2e): linting
arthurgousset Jun 6, 2024
0ca1c67
Merge branch 'master' into arthurgousset/test/anvil-proof-of-concept-…
arthurgousset Jun 6, 2024
1a66ba1
refactor(test-sol/FeeCurrencyDirectory): moves file to `.../e2e/`
arthurgousset Jun 6, 2024
80ff4e2
chore(migrations_sol): use `test-sol/e2e/*` path
arthurgousset Jun 6, 2024
b5dc987
chore(test-sol/FeeCurrencyDirectory): match contract name in unit and…
arthurgousset Jun 6, 2024
51758a2
style(test-sol/FeeCurrencyDirectory): linting
arthurgousset Jun 6, 2024
27b01c8
chore(e2e/utils): removes unused imports and more
arthurgousset Jun 6, 2024
e6a4f4b
test(test-sol/e2e): renames contract with "E2E..."
arthurgousset Jun 6, 2024
f8795e5
chore(workflows/protocol_tests): excludes e2e test from workflow
arthurgousset Jun 6, 2024
9eb0580
style(test-sol/e2e): linting
arthurgousset Jun 6, 2024
bb19b8f
chore(e2e): temporarily renames contract with "E2E..."
arthurgousset Jun 6, 2024
bfbad45
Merge branch 'master' into arthurgousset/test/anvil-proof-of-concept-…
arthurgousset Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/protocol_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ jobs:
exit 1
fi

- name: Run Everything just in case something was missed
- name: Run everything just in case something was missed (excl. integration and e2e tests)
# can't use gas limit because some setUp function use more than the limit
# Excludes integration tests, because they require an anvil devchain running on the localhost.
run: forge test -vvv --no-match-contract RegistryIntegrationTest
run: forge test -vvv --no-match-contract "RegistryIntegrationTest|E2EDemo"

- name: Generate migrations
if: success() || failure()
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ remappings = [
'@celo-contracts-8=contracts-0.8/',
'@openzeppelin/contracts8/=lib/openzeppelin-contracts8/contracts/',
'@celo-contracts/=contracts/',
'@celo-migrations/=migrations_sol/'
'@celo-migrations/=migrations_sol/',
'@test-sol/=test-sol/'
]

no_match_test = "skip"
Expand Down
21 changes: 21 additions & 0 deletions packages/protocol/migrations_sol/run_e2e_tests_in_anvil.sh
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity >=0.8.7 <0.8.20;

import "celo-foundry-8/Test.sol";
import "../../contracts-0.8/common/FeeCurrencyDirectory.sol";
import "../../contracts-0.8/common/mocks/MockOracle.sol";
import "@celo-contracts-8/common/FeeCurrencyDirectory.sol";
import "@celo-contracts-8/common/mocks/MockOracle.sol";

contract FeeCurrencyDirectoryTestBase is Test {
FeeCurrencyDirectory directory;
Expand Down
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);
}
}
35 changes: 35 additions & 0 deletions packages/protocol/test-sol/e2e/utils.sol
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)
}
}
Loading