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

feat(foundry): publish L2 state in @celo/devchain-anvil #11107

Merged
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
17dc558
refactor(scripts/foundry): moves `run_e2e_tests...sh` file
arthurgousset Jul 3, 2024
7ec412e
feat(package.json): adds yarn commands for e2e and integration tests
arthurgousset Jul 3, 2024
ccb8962
refactor(migrations_sol): groups imports for better readability
arthurgousset Jul 3, 2024
d772383
feat(scripts/foundry): adds MVP L2 migration script
arthurgousset Jul 3, 2024
4a6b28a
feat(package.json): adds two helper yarn commands
arthurgousset Jul 3, 2024
884523e
chore(migrations_sol): fix typo in function name
arthurgousset Jul 3, 2024
6c50678
chore(migrations_sol): nit simplifies code comment for better readabi…
arthurgousset Jul 4, 2024
651c9b7
feat(scripts/foundry): activates CeloDistributionSchedule
arthurgousset Jul 4, 2024
1b90853
refactor(scripts/foundry): moves variables to `constants.sh`
arthurgousset Jul 4, 2024
4a7606b
refactor(scripts/foundry): moves more variables to `constants.sh`
arthurgousset Jul 4, 2024
2fc22ef
refactor(constants.sh): read bytecode from Foundry instead of Truffle
arthurgousset Jul 4, 2024
7315121
chore(scripts/foundry): adds TODO comment
arthurgousset Jul 4, 2024
3ea0477
Merge branch 'release/core-contracts/12' into arthurgousset/feat/publ…
arthurgousset Jul 4, 2024
563ec74
refactor(scripts/foundry): rename to `create_and_migrate_anvil_l2_dev…
arthurgousset Jul 5, 2024
a5c8bf0
style(migrations_sol): linting
arthurgousset Jul 5, 2024
fca75d4
chore(scripts/foundry): remove debugging statements
arthurgousset Jul 5, 2024
209ca83
refactor(constants): adds L1 and L2 state file names
arthurgousset Jul 5, 2024
e4671eb
feat(scripts/foundry): successfully dumps L2 state
arthurgousset Jul 5, 2024
92c1dd8
refactor(constants): uses `$ANVIL_RPC_URL` instead of hardcoded URL
arthurgousset Jul 5, 2024
ed9a6c0
refactor(constants): moves libraries to constants
arthurgousset Jul 5, 2024
9e04ad9
fix(constants): adds `$PWD` to prevent errors on CI
arthurgousset Jul 5, 2024
ad5d1ba
chore(workflows): debugging `jq` error on CI
arthurgousset Jul 5, 2024
9215e50
fix(constants): moves bytecode operation back into scripts
arthurgousset Jul 5, 2024
05f3532
chore(workflows): debugging `jq` CI error
arthurgousset Jul 5, 2024
95d5a6d
fix(scripts/foundry): uses Foundry `out/` directory
arthurgousset Jul 5, 2024
dea18dd
chore(scripts/foundry): removes debugging statement
arthurgousset Jul 5, 2024
5e60f18
feat(package.json): updates yarn command names
arthurgousset Jul 5, 2024
05579f6
docs(CONTRIBUTING): updates yarn command docs
arthurgousset Jul 5, 2024
c505eba
chore(workflows): add back NPM install step
arthurgousset Jul 5, 2024
276b569
chore(workflows): removes code comment
arthurgousset Jul 5, 2024
1e4cc56
feat(workflows): publishes L1 and L2 state
arthurgousset Jul 5, 2024
6311800
fix(scripts/foundry): remove unnecessary `stop_anvil` call
arthurgousset Jul 5, 2024
ec192f3
refactor(workflows): replace CI env with variable from `constants.sh`
arthurgousset Jul 5, 2024
58a1fd0
fix(workflows): adds back `stop_anvil.sh` and installs `lsof` explicitly
arthurgousset Jul 5, 2024
fa243ca
chore(scripts/foundry): removes code comment
arthurgousset Jul 5, 2024
ab7f5d0
fix(workflows): install `lsof` in the same step
arthurgousset Jul 8, 2024
28464b6
fix(workflows): hacky fix to run L2 anvil
arthurgousset Jul 8, 2024
d29b220
refactor(scripts/foundry): simplifying `lsof` query to find PID
arthurgousset Jul 8, 2024
cd6ca05
fix(workflows): try to terminate anvil server again
arthurgousset Jul 8, 2024
a906048
fix(workflows): hacky workaround to prevent Anvil bug when loading state
arthurgousset Jul 8, 2024
b88b337
Update .github/workflows/protocol-devchain-anvil.yml
arthurgousset Jul 12, 2024
ff291e0
Update .github/workflows/protocol-devchain-anvil.yml
arthurgousset Jul 12, 2024
06e7fe7
feat(constants): set CeloDistributionSchedule initial balance to 700M…
arthurgousset Jul 12, 2024
85895b5
docs(README): improves README
arthurgousset Jul 12, 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
31 changes: 24 additions & 7 deletions .github/workflows/protocol-devchain-anvil.yml
arthurgousset marked this conversation as resolved.
Show resolved Hide resolved
arthurgousset marked this conversation as resolved.
Show resolved Hide resolved
arthurgousset marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ env:
FOUNDRY_CACHE_KEY: 1
# Supported Foundry version defined at celo-org (GitHub organisation) level, for consistency across workflows.
SUPPORTED_FOUNDRY_VERSION: ${{ vars.SUPPORTED_FOUNDRY_VERSION }}
ANVIL_PORT: 8546

jobs:
build:
Expand Down Expand Up @@ -124,17 +123,35 @@ jobs:
- name: 'Install packages'
shell: bash
run: yarn

- name: Generate migrations and run devchain

# Install `lsof` dependency, because it's not readily available on CI, but is required by
# `create_and_migrate_anvil_l2_devchain.sh`, because it uses `stop_anvil.sh` to kill
# existing anvil servers.
- name: Generate L1 and L2 migrations
if: success() || failure()
run: ./scripts/foundry/create_and_migrate_anvil_devchain.sh
run: |
sudo apt-get update
sudo apt-get install -y lsof

./scripts/foundry/create_and_migrate_anvil_l2_devchain.sh

- name: Run integration tests against local anvil devchain
- name: Run integration tests against L1 devchain
if: success() || failure()
run: |
source ./scripts/foundry/constants.sh

anvil \
--port 8547 \
--state $TMP_FOLDER/$L1_DEVCHAIN_FILE_NAME \
--state-interval $STATE_INTERVAL \
--gas-limit $GAS_LIMIT \
--code-size-limit $CODE_SIZE_LIMIT \
--balance $BALANCE \
--steps-tracing &

forge test -vvv \
--match-path "test-sol/integration/*" \
--fork-url http://127.0.0.1:${{ env.ANVIL_PORT }}
--fork-url http://127.0.0.1:8547
arthurgousset marked this conversation as resolved.
Show resolved Hide resolved

- name: Sanitize ref name
id: sanitize-ref-name
Expand All @@ -158,7 +175,7 @@ jobs:
env:
RELEASE_TYPE: ${{ env.RELEASE_TYPE }}
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}

- name: Upload devchain as artifact
uses: actions/upload-artifact@v4
with:
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/protocol_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ env:
FOUNDRY_CACHE_KEY: 2
# Supported Foundry version defined at celo-org (GitHub organisation) level, for consistency across workflows.
SUPPORTED_FOUNDRY_VERSION: ${{ vars.SUPPORTED_FOUNDRY_VERSION }}
ANVIL_PORT: 8546

jobs:
check:
Expand Down Expand Up @@ -129,13 +128,17 @@ jobs:
- name: Run integration tests against local anvil devchain
if: success() || failure()
run: |
source ./scripts/foundry/constants.sh

forge test -vvv \
--match-path "test-sol/integration/*" \
--fork-url http://127.0.0.1:${{ env.ANVIL_PORT }}
--fork-url $ANVIL_RPC_URL

- name: Run e2e tests against local anvil devchain
if: success() || failure()
run: |
source ./scripts/foundry/constants.sh

forge test -vvv \
--match-path "test-sol/e2e/*" \
--fork-url http://127.0.0.1:${{ env.ANVIL_PORT }}
--fork-url $ANVIL_RPC_URL
56 changes: 33 additions & 23 deletions packages/protocol/migrations_sol/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,51 @@ This devchain is useful for testing and development of the Celo protocol.

## Usage

### Start devchain
### Start L1 devchain

```sh
$ yarn anvil-devchain:start
$ yarn anvil-devchain:start-L1
```

Starts a new anvil devchain serving at localhost (default port 8546).

For example:
You can now run commands against the local devchain. For example:

```sh
$ yarn anvil-devchain:start

yarn run v1.22.22
$ ./scripts/foundry/create_and_migrate_anvil_devchain.sh
# ...
Total elapsed time: 193 seconds
✨ Done in 193.09s.
cast block-number \
--rpc-url http://127.0.0.1:8546
266
```

You can now run commands against the local devchain.
### Start L2 devchain

```sh
$ yarn anvil-devchain:start-L2
```

For example:
Starts a new anvil devchain serving at localhost (default port 8546).

You can now run commands against the local devchain. For example:

```sh
cast block-number \
--rpc-url http://127.0.0.1:8546
266
# Call `isL2()` on `CeloDistributionSchedule.sol`
cast call \
0xA16cF67AFa80BB9Ce7a325597F80057c6B290fD4 \
"isL2()(bool)" \
--rpc-url=http://127.0.0.1:8546
true
```

### Check if devchain is running

```sh
$ yarn anvil-devchain:status

# If devchain is running
Devchain is serving at http://localhost:8546

# If devchain is not running
Devchain is not running.
```

### Stop devchain
Expand All @@ -41,17 +58,10 @@ cast block-number \
$ yarn anvil-devchain:stop
```

Terminates any anvil nodes serving at localhost.

For example:
Terminates any anvil nodes serving at localhost. For example:

```sh
# in packages/protocol/ directory
$ yarn anvil-devchain:stop

yarn run v1.22.22
$ ./scripts/foundry/stop_anvil.sh
Connection to localhost port 8546 [tcp/*] succeeded!
Killed Anvil
✨ Done in 0.11s.
```
51 changes: 25 additions & 26 deletions packages/protocol/migrations_sol/Migration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@ pragma solidity >=0.8.7 <0.8.20;

import { Script } from "forge-std-8/Script.sol";

// Foundry imports
import "forge-std/console.sol";
import "forge-std/StdJson.sol";

import "@celo-contracts/common/interfaces/IProxyFactory.sol";
// Helper contract imports
import "@migrations-sol/HelperInterFaces.sol";
import { Constants } from "@migrations-sol/constants.sol";
import "@openzeppelin/contracts8/utils/math/Math.sol";

// Initializer of the core contracts
// Core contract imports on Solidity 0.5
import "@celo-contracts/common/interfaces/IProxy.sol";
import "@celo-contracts/common/interfaces/IProxyFactory.sol";
import "@celo-contracts/common/interfaces/IRegistry.sol";
import "@celo-contracts/common/interfaces/IRegistryInitializer.sol";
import "@celo-contracts/common/interfaces/IFreezer.sol";
import "@celo-contracts/common/interfaces/IFreezerInitializer.sol";
import "@celo-contracts-8/common/interfaces/IFeeCurrencyDirectoryInitializer.sol";
import "@celo-contracts/common/interfaces/ICeloTokenInitializer.sol";
import "@celo-contracts/common/interfaces/IAccountsInitializer.sol";
import "@celo-contracts/common/interfaces/IFeeHandlerSellerInitializer.sol";
import "@celo-contracts/common/interfaces/IFeeHandler.sol";
import "@celo-contracts/common/interfaces/IFeeHandlerInitializer.sol";
import "@celo-contracts/common/interfaces/IFeeCurrencyWhitelist.sol";
import "@celo-contracts/common/interfaces/IAccounts.sol";
import "@celo-contracts/governance/interfaces/ILockedGoldInitializer.sol";
import "@celo-contracts/governance/interfaces/IValidatorsInitializer.sol";
import "@celo-contracts/governance/interfaces/IElectionInitializer.sol";
Expand All @@ -24,34 +37,22 @@ import "@celo-contracts/governance/interfaces/IDoubleSigningSlasherInitializer.s
import "@celo-contracts/governance/interfaces/IDowntimeSlasherInitializer.sol";
import "@celo-contracts/governance/interfaces/IGovernanceApproverMultiSigInitializer.sol";
import "@celo-contracts/governance/interfaces/IGovernanceInitializer.sol";
import "@celo-contracts/common/interfaces/IAccountsInitializer.sol";
import "@celo-contracts/common/interfaces/IFeeHandlerSellerInitializer.sol";
import "@celo-contracts/common/interfaces/IFeeHandlerInitializer.sol";
import "@celo-contracts/governance/interfaces/ILockedGold.sol";
import "@celo-contracts/governance/interfaces/IGovernance.sol";
import "@celo-contracts/identity/interfaces/IRandomInitializer.sol";
import "@celo-contracts/identity/interfaces/IEscrowInitializer.sol";
import "@celo-contracts/identity/interfaces/IOdisPaymentsInitializer.sol";
import "@celo-contracts/identity/interfaces/IFederatedAttestationsInitializer.sol";
import "@celo-contracts/stability/interfaces/ISortedOraclesInitializer.sol";
import "@celo-contracts/stability/interfaces/ISortedOracles.sol";

// Core contract imports on Solidity 0.8
import "@celo-contracts-8/common/interfaces/IFeeCurrencyDirectoryInitializer.sol";
import "@celo-contracts-8/common/interfaces/IGasPriceMinimumInitializer.sol";
import "@celo-contracts-8/common/interfaces/ICeloDistributionScheduleInitializer.sol";

import "@celo-contracts/common/interfaces/IProxy.sol";
import "@celo-contracts/common/interfaces/IRegistry.sol";
import "@celo-contracts/common/interfaces/IFreezer.sol";
import "@celo-contracts/common/interfaces/IFeeCurrencyWhitelist.sol";
import "@celo-contracts-8/common/interfaces/IFeeCurrencyDirectory.sol";
import "@celo-contracts/common/interfaces/IAccounts.sol";
import "@celo-contracts/governance/interfaces/ILockedGold.sol";
import "@celo-contracts/governance/interfaces/IGovernance.sol";
import "@celo-contracts/common/interfaces/IFeeHandler.sol";
import "@celo-contracts/stability/interfaces/ISortedOracles.sol";

import "@migrations-sol/HelperInterFaces.sol";
import "@openzeppelin/contracts8/utils/math/Math.sol";
import "@celo-contracts-8/common/UsingRegistry.sol";

import { Constants } from "@migrations-sol/constants.sol";

contract ForceTx {
// event to trigger so a tx can be processed
event VanillaEvent(string);
Expand All @@ -66,9 +67,7 @@ contract ForceTx {
contract Migration is Script, UsingRegistry, Constants {
using stdJson for string;

/**
* This is Anvil's default account
*/
// This is Anvil's default account
address constant deployerAccount = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;

IProxyFactory proxyFactory;
Expand Down Expand Up @@ -980,10 +979,10 @@ contract Migration is Script, UsingRegistry, Constants {
);

_setConstitution(governanceProxyAddress, json);
_transferOwnerShipCoreContact(governanceProxyAddress, json);
_transferOwnerShipCoreContract(governanceProxyAddress, json);
}

function _transferOwnerShipCoreContact(address governanceAddress, string memory json) public {
function _transferOwnerShipCoreContract(address governanceAddress, string memory json) public {
bool skipTransferOwnership = abi.decode(
json.parseRaw(".governance.skipTransferOwnership"),
(bool)
Expand Down
6 changes: 5 additions & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@
"truffle:migrate": "truffle migrate",
"devchain": "yarn ts-node scripts/devchain.ts",
"devchain:reset": "yarn devchain generate-tar .tmp/devchain.tar.gz --upto 29",
"anvil-devchain:start": "./scripts/foundry/create_and_migrate_anvil_devchain.sh",
"anvil-devchain:start-L1": "./scripts/foundry/create_and_migrate_anvil_devchain.sh",
"anvil-devchain:start-L2": "./scripts/foundry/create_and_migrate_anvil_l2_devchain.sh",
"anvil-devchain:status": "if nc -z localhost 8546; then echo 'Devchain is serving at http://localhost:8546'; else echo 'Devchain is not running.'; fi",
"anvil-devchain:stop": "./scripts/foundry/stop_anvil.sh",
"anvil-devchain:e2e-tests": "./scripts/foundry/run_e2e_tests_in_anvil.sh",
"anvil-devchain:integration-tests": "./scripts/foundry/run_integration_tests_in_anvil.sh",
"view-tags": "git for-each-ref 'refs/tags/core-contracts.*' --sort=-committerdate --format='%(color:magenta)%(committerdate:short) %(color:blue)%(tree) %(color:green)github.com/celo-org/celo-monorepo/releases/tag/%(color:yellow)%(refname:short)'",
"generate-stabletoken-files": "yarn ts-node ./scripts/generate-stabletoken-files.ts",
"truffle-verify": "yarn truffle run verify"
Expand Down
61 changes: 61 additions & 0 deletions packages/protocol/scripts/foundry/constants.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Anvil accounts
export FROM_ACCOUNT_NO_ZERO="f39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # Anvil default account (1)
export FROM_ACCOUNT="0x$FROM_ACCOUNT_NO_ZERO" # Anvil default account (1)
export FROM_ACCOUNT_PRIVATE_KEY_NO_ZERO="ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" # Anvil default account (1)
export FROM_ACCOUNT_PRIVATE_KEY="0x$FROM_ACCOUNT_PRIVATE_KEY_NO_ZERO" # Anvil default account (1)

# Anvil configurations (Source: https://book.getfoundry.sh/reference/anvil/)
export ANVIL_PORT=8546
export ANVIL_RPC_URL="http://127.0.0.1:$ANVIL_PORT"
export GAS_LIMIT=50000000
export CODE_SIZE_LIMIT=245760 # EIP-170: Contract code size limit in bytes. Useful to increase for tests. [default: 0x6000 (~25kb)]
export BALANCE=60000 # Set the balance of the accounts. [default: 10000]
export STATE_INTERVAL=1 # Interval in seconds at which the state and block environment is to be dumped to disk.
export STEPS_TRACING="--steps-tracing" # Steps tracing used for debug calls returning geth-style traces. Enable: "--steps-tracing" / Disable: ""

# Forge migration script configurations (Source: https://book.getfoundry.sh/reference/forge/forge-script)
export MIGRATION_SCRIPT_PATH="migrations_sol/Migration.s.sol" # Path to migration script
export TARGET_CONTRACT="Migration" # The name of the contract you want to run.
export BROADCAST="--broadcast" # Broadcasts the transactions. Enable: "--broadcast" / Disable: ""
export SKIP_SIMULATION="" # Skips on-chain simulation. Enable: "--skip-simulation" / Disable: ""
export NON_INTERACTIVE="--non-interactive" # Remove interactive prompts which appear if the contract is near the EIP-170 size limit.
export VERBOSITY_LEVEL="-vvv" # Pass multiple times to increase the verbosity (e.g. -v, -vv, -vvv).
export REGISTRY_OWNER_ADDRESS=$FROM_ACCOUNT_NO_ZERO

# Foundry directories and file names
export L1_DEVCHAIN_FILE_NAME="devchain.json" # Name of the file that will be published to NPM
export L2_DEVCHAIN_FILE_NAME="l2-devchain.json" # Name of the file that will be published to NPM
export TMP_FOLDER="$PWD/.tmp"
export TEMP_DIR="$PWD/.tmp/libraries"
export ANVIL_FOLDER="$TMP_FOLDER/devchain"

# Contract addresses
export REGISTRY_ADDRESS="0x000000000000000000000000000000000000ce10"
export PROXY_ADMIN_ADDRESS='0x4200000000000000000000000000000000000018' # This address is defined in `IsL2Check.sol`

# Contract configurations
export COMMUNITY_REWARD_FRACTION="100000000000000000000" # 0.01 in fixidity format
export CARBON_OFFSETTING_PARTNER="0x22579CA45eE22E2E16dDF72D955D6cf4c767B0eF"
export CARBON_OFFSETTING_FRACTION="10000000000000000000" # 0.001 in fixidity format
export REGISTRY_STORAGE_LOCATION="0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103" # Position is bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1);
export CELO_DISTRIBUTION_SCHEDULE_INITIAL_BALANCE="10000" # Arbitrary balance choosen at random. During the real L2 genesis, the VM will calculate and set an appropriate balance.
arthurgousset marked this conversation as resolved.
Show resolved Hide resolved

# Contract libraries
export LIBRARIES_PATH=("contracts/common/linkedlists/AddressSortedLinkedListWithMedian.sol:AddressSortedLinkedListWithMedian"
"contracts/common/Signatures.sol:Signatures"
"contracts/common/linkedlists/AddressLinkedList.sol:AddressLinkedList"
"contracts/common/linkedlists/AddressSortedLinkedList.sol:AddressSortedLinkedList"
"contracts/common/linkedlists/IntegerSortedLinkedList.sol:IntegerSortedLinkedList"
"contracts/governance/Proposals.sol:Proposals"
)
export LIBRARY_DEPENDENCIES_PATH=(
"contracts/common/FixidityLib.sol"
"contracts/common/linkedlists/LinkedList.sol"
"contracts/common/linkedlists/SortedLinkedList.sol"
"contracts/common/linkedlists/SortedLinkedListWithMedian.sol"
"lib/openzeppelin-contracts/contracts/math/SafeMath.sol"
"lib/openzeppelin-contracts/contracts/math/Math.sol"
"lib/openzeppelin-contracts/contracts/cryptography/ECDSA.sol"
"lib/openzeppelin-contracts/contracts/utils/Address.sol"
"lib/solidity-bytes-utils/contracts/BytesLib.sol"
)
Loading
Loading