-
Notifications
You must be signed in to change notification settings - Fork 47
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
AVS-507: Integration test scaffold: add anvil chain with deployed contracts to be able to test sdk features like bindings, txmgr, etc #176
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
571ca42
wip: deploying contracts to anvil state
samlaf 6e53b99
fix compilation
samlaf ef69080
fix tests
samlaf 64198d5
fix start-anvil-chain command and add to makefile
samlaf 346dc12
chore: forge init
samlaf 21ba88a
clean-up contracts forge folder
samlaf 13abf24
fix anvil scripts
samlaf c7e1b8c
added avs deployment contracts and scripts
samlaf 03c8a17
add ContractsRegistry to generate-bindings + make bindings
samlaf 783d5e6
update StartAnvilContainer + make egnaddrs test use new deployed anvi…
samlaf a630ea1
Refactored DeployMockAvs into 2 separate contracts (one for serviceMa…
samlaf 065066c
small refactor + cleanup of DeployMockAvs
samlaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "contracts/lib/eigenlayer-middleware"] | ||
path = contracts/lib/eigenlayer-middleware | ||
url = [email protected]:Layr-Labs/eigenlayer-middleware.git | ||
[submodule "contracts/lib/forge-std"] | ||
path = contracts/lib/forge-std | ||
url = [email protected]/foundry-rs/forge-std |
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
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
1 change: 0 additions & 1 deletion
1
cmd/egnaddrs/test_data/eigenlayer-and-registries-deployed-anvil-state.json
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
# Compiler files | ||
cache/ | ||
out/ | ||
|
||
# Ignores development broadcast logs | ||
!/broadcast | ||
/broadcast/*/31337/ | ||
/broadcast/**/dry-run/ | ||
|
||
# Docs | ||
docs/ | ||
|
||
# Dotenv file | ||
.env |
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 @@ | ||
# Integration Tests | ||
|
||
We store an anvil state files in this directory, so that we can start an anvil chain with the correct state for integration tests. | ||
``` | ||
anvil --load-state STATE_FILE.json | ||
``` | ||
|
||
## Eigenlayer deployment state file | ||
`eigenlayer-deployed-anvil-state.json` contains the eigenlayer deployment. | ||
|
||
It was created by running this [deploy script](https://github.com/Layr-Labs/eigenlayer-contracts/blob/2cb9ed107c6c918b9dfbac94cd71b4ab7c94e8c2/script/testing/M2_Deploy_From_Scratch.s.sol). If you ever need to redeploy a new version of eigenlayer contracts, first start an anvil chain that dumps its state after exiting | ||
``` | ||
anvil --dump-state eigenlayer-deployed-anvil-state.json | ||
``` | ||
Then run the deploy script | ||
``` | ||
forge script script/testing/M2_Deploy_From_Scratch.s.sol --rpc-url http://localhost:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast --sig "run(string memory configFile)" -- M2_deploy_from_scratch.anvil.config.json | ||
``` | ||
and finally kill the anvil chain with `Ctrl-C`. Make sure to copy the deployment [output file](https://github.com/Layr-Labs/eigenlayer-contracts/blob/master/script/output/M2_from_scratch_deployment_data.json) to [eigenlayer_deployment_output.json](../../contracts/script/output/31337/eigenlayer_deployment_output.json) so that the tests can find the deployed contracts. | ||
|
||
See the main [README](../../README.md#dependencies) to understand why we deploy from the `experimental-reduce-strategy-manager-bytecode-size` branch of eigenlayer-contracts. |
Large diffs are not rendered by default.
Oops, something went wrong.
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,73 @@ | ||
#!/bin/bash | ||
|
||
# Enable the script to exit immediately if a command exits with a non-zero status | ||
set -o errexit -o nounset -o pipefail | ||
|
||
# Define your cleanup function | ||
clean_up() { | ||
echo "Executing cleanup function..." | ||
set +e | ||
pkill -f anvil | ||
|
||
# Check if the exit status is non-zero | ||
exit_status=$? | ||
if [ $exit_status -ne 0 ]; then | ||
echo "Script exited due to set -e on line $1 with command '$2'. Exit status: $exit_status" | ||
fi | ||
} | ||
# Use trap to call the clean_up function when the script exits | ||
trap 'clean_up $LINENO "$BASH_COMMAND"' EXIT | ||
|
||
# cd to the directory of this script so that this can be run from anywhere | ||
anvil_dir=$( | ||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
pwd -P | ||
) | ||
root_dir=$(realpath $anvil_dir/../..) | ||
|
||
set -a | ||
source $anvil_dir/utils.sh | ||
# we overwrite some variables here because should always deploy to anvil (localhost) | ||
ETH_HTTP_URL=http://localhost:8545 | ||
DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 | ||
set +a | ||
|
||
# start an empty anvil chain in the background and dump its state to a json file upon exit | ||
start_anvil_docker "" $anvil_dir/contracts-deployed-anvil-state.json | ||
sleep 1 | ||
|
||
CHAIN_ID=$(cast chain-id) | ||
|
||
# DEPLOY CONTRACT REGISTRY | ||
cd $root_dir/contracts | ||
forge create src/ContractsRegistry.sol:ContractsRegistry --rpc-url $ETH_HTTP_URL --private-key $DEPLOYER_PRIVATE_KEY | ||
|
||
# DEPLOY EIGENLAYER | ||
EIGEN_CONTRACTS_DIR=$root_dir/contracts/lib/eigenlayer-middleware/lib/eigenlayer-contracts | ||
DEVNET_OUTPUT_DIR=$EIGEN_CONTRACTS_DIR/script/output/devnet | ||
# deployment overwrites this file, so we save it as backup, because we want that output in our local files, and not in the eigenlayer-contracts submodule files | ||
mv $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json.bak | ||
cd $EIGEN_CONTRACTS_DIR | ||
forge script script/deploy/devnet/M2_Deploy_From_Scratch.s.sol --rpc-url $ETH_HTTP_URL \ | ||
--private-key $DEPLOYER_PRIVATE_KEY --broadcast \ | ||
--sig "run(string memory configFileName)" -- M2_deploy_from_scratch.anvil.config.json | ||
mv $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json $root_dir/contracts/script/output/${CHAIN_ID:?}/eigenlayer_deployment_output.json | ||
mv $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json.bak $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json | ||
|
||
# DEPLOY MOCKAVS | ||
cd $root_dir/contracts | ||
forge script script/DeployMockAvs.s.sol --rpc-url $ETH_HTTP_URL --private-key $DEPLOYER_PRIVATE_KEY --broadcast | ||
|
||
# DEPLOY TOKENS AND STRATEGIES | ||
cd $root_dir/contracts | ||
# DO NOT REMOVE THE SLOW DIRECTIVE FROM THIS SCRIPT INVOCATION | ||
# slow ensures that the transaction reciept is successful and recieved before sending the next transaction | ||
# this should prevent the strategies deploying/registering in a flakey manner, | ||
forge script script/DeployTokensStrategiesCreateQuorums.s.sol --rpc-url $ETH_HTTP_URL --private-key $DEPLOYER_PRIVATE_KEY --broadcast --slow | ||
|
||
# REGISTER OPERATORS WITH EIGENLAYER | ||
cd $root_dir/contracts | ||
# DO NOT REMOVE THE SLOW DIRECTIVE FROM THIS SCRIPT INVOCATION | ||
# slow ensures that the transaction receipt is successful and recieved before sending the next transaction | ||
# this should prevent the operators registering in a flakey manner, the operators registered will change from run to run without this | ||
forge script script/RegisterOperatorsWithEigenlayer.s.sol --rpc-url $ETH_HTTP_URL --private-key $DEPLOYER_PRIVATE_KEY --broadcast --slow |
29 changes: 29 additions & 0 deletions
29
contracts/anvil/start-anvil-chain-with-el-and-avs-deployed.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,29 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o nounset -o pipefail | ||
|
||
# cd to the directory of this script so that this can be run from anywhere | ||
anvil_dir=$( | ||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
pwd -P | ||
) | ||
root_dir=$(realpath $anvil_dir/../..) | ||
|
||
set -a | ||
source $anvil_dir/utils.sh | ||
set +a | ||
|
||
# start an anvil instance in the background that has eigenlayer contracts deployed | ||
# we start anvil in the background so that we can run the below script | ||
start_anvil_docker $anvil_dir/contracts-deployed-anvil-state.json "" | ||
|
||
cd $root_dir/contracts | ||
# we need to restart the anvil chain at the correct block, otherwise the indexRegistry has a quorumUpdate at the block number | ||
# at which it was deployed (aka quorum was created/updated), but when we start anvil by loading state file it starts at block number 0 | ||
# so calling getOperatorListAtBlockNumber reverts because it thinks there are no quorums registered at block 0 | ||
# advancing chain manually like this is a current hack until https://github.com/foundry-rs/foundry/issues/6679 is merged | ||
cast rpc anvil_mine 200 --rpc-url http://localhost:8545 > /dev/null | ||
echo "Anvil is ready. Advanced chain to block-number:" $(cast block-number) | ||
|
||
|
||
docker attach anvil |
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,39 @@ | ||
#!/bin/bash | ||
|
||
set -e -o nounset | ||
|
||
parent_path=$( | ||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
pwd -P | ||
) | ||
|
||
FOUNDRY_IMAGE=ghcr.io/foundry-rs/foundry:nightly-5b7e4cb3c882b28f3c32ba580de27ce7381f415a | ||
|
||
clean_up() { | ||
# Check if the exit status is non-zero | ||
exit_status=$? | ||
if [ $exit_status -ne 0 ]; then | ||
echo "Script exited due to set -e on line $1 with command '$2'. Exit status: $exit_status" | ||
fi | ||
} | ||
# Use trap to call the clean_up function when the script exits | ||
trap 'clean_up $LINENO "$BASH_COMMAND"' ERR | ||
|
||
# start_anvil_docker $LOAD_STATE_FILE $DUMP_STATE_FILE | ||
start_anvil_docker() { | ||
LOAD_STATE_FILE=$1 | ||
DUMP_STATE_FILE=$2 | ||
LOAD_STATE_VOLUME_DOCKER_ARG=$([[ -z $LOAD_STATE_FILE ]] && echo "" || echo "-v $LOAD_STATE_FILE:/load-state.json") | ||
DUMP_STATE_VOLUME_DOCKER_ARG=$([[ -z $DUMP_STATE_FILE ]] && echo "" || echo "-v $DUMP_STATE_FILE:/dump-state.json") | ||
LOAD_STATE_ANVIL_ARG=$([[ -z $LOAD_STATE_FILE ]] && echo "" || echo "--load-state /load-state.json") | ||
DUMP_STATE_ANVIL_ARG=$([[ -z $DUMP_STATE_FILE ]] && echo "" || echo "--dump-state /dump-state.json") | ||
|
||
trap 'docker stop anvil 2>/dev/null || true' EXIT | ||
set -o xtrace | ||
docker run --rm -d --name anvil -p 8545:8545 $LOAD_STATE_VOLUME_DOCKER_ARG $DUMP_STATE_VOLUME_DOCKER_ARG \ | ||
--entrypoint anvil \ | ||
$FOUNDRY_IMAGE \ | ||
$LOAD_STATE_ANVIL_ARG $DUMP_STATE_ANVIL_ARG --host 0.0.0.0 | ||
set +o xtrace | ||
sleep 2 | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addresses are no longer hardcoded. We get them from the ContractsRegistry that is deployed as part of the integration test deployment.