github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/test/kontrol/scripts/make-summary-deployment.sh (about) 1 #!/bin/bash 2 set -euo pipefail 3 4 export FOUNDRY_PROFILE=kdeploy 5 6 SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 7 # shellcheck source=/dev/null 8 source "$SCRIPT_HOME/common.sh" 9 # Sanity check on arguments 10 if [ $# -gt 1 ]; then 11 echo "At most one argument can be provided. Instead $# were provided" 1>&2 12 exit 1 13 elif [ $# -eq 1 ]; then 14 if [ "$1" != "-h" ] && [ "$1" != "--help" ] && [ "$1" != "container" ] && [ "$1" != "local" ] && [ "$1" != "dev" ]; then 15 notif "Invalid argument. Must be \`container\`, \`local\`, \`dev\`, \`-h\` or \`--help\`" 16 exit 1 17 else 18 parse_first_arg "$@" 19 fi 20 fi 21 22 cleanup() { 23 # Restore the original script from the backup 24 if [ -f "$DEPLOY_SCRIPT.bak" ]; then 25 cp "$DEPLOY_SCRIPT.bak" "$DEPLOY_SCRIPT" 26 rm "$DEPLOY_SCRIPT.bak" 27 fi 28 29 if [ -f "snapshots/state-diff/Deploy.json" ]; then 30 rm "snapshots/state-diff/Deploy.json" 31 fi 32 33 if [ "$LOCAL" = false ]; then 34 clean_docker 35 fi 36 } 37 38 # Set trap to call cleanup function on exit 39 trap cleanup EXIT 40 41 # create deployments/hardhat/.deploy and snapshots/state-diff/Deploy.json if necessary 42 if [ ! -d "deployments/hardhat" ]; then 43 mkdir deployments/hardhat; 44 fi 45 if [ ! -f "deployments/hardhat/.deploy" ]; then 46 touch deployments/hardhat/.deploy; 47 fi 48 if [ ! -d "snapshots/state-diff" ]; then 49 mkdir snapshots/state-diff; 50 fi 51 if [ ! -f "snapshots/state-diff/Deploy.json" ]; then 52 touch snapshots/state-diff/Deploy.json; 53 fi 54 55 DEPLOY_SCRIPT="./scripts/Deploy.s.sol" 56 conditionally_start_docker 57 58 # Create a backup 59 cp $DEPLOY_SCRIPT $DEPLOY_SCRIPT.bak 60 61 # Replace mustGetAddress by getAddress in Deploy.s.sol 62 # This is needed because the Kontrol deployment is only a partial 63 # version of the full Optimism deployment. Since not all the components 64 # of the system are deployed, we'd get some reverts on the `mustGetAddress` functions 65 awk '{gsub(/mustGetAddress/, "getAddress")}1' $DEPLOY_SCRIPT > temp && mv temp $DEPLOY_SCRIPT 66 67 forge script -vvv test/kontrol/deployment/KontrolDeployment.sol:KontrolDeployment --sig 'runKontrolDeployment()' 68 echo "Created state diff json" 69 70 # Clean and store the state diff json in snapshots/state-diff/Kontrol-Deploy.json 71 JSON_SCRIPTS=test/kontrol/scripts/json 72 GENERATED_STATEDIFF=Deploy.json # Name of the statediff json produced by the deployment script 73 STATEDIFF=Kontrol-$GENERATED_STATEDIFF # Name of the Kontrol statediff 74 mv snapshots/state-diff/$GENERATED_STATEDIFF snapshots/state-diff/$STATEDIFF 75 python3 $JSON_SCRIPTS/clean_json.py snapshots/state-diff/$STATEDIFF 76 jq . snapshots/state-diff/$STATEDIFF > temp && mv temp snapshots/state-diff/$STATEDIFF # Prettify json 77 echo "Cleaned state diff json" 78 79 CONTRACT_NAMES=deployments/hardhat/.deploy 80 python3 $JSON_SCRIPTS/reverse_key_values.py $CONTRACT_NAMES ${CONTRACT_NAMES}Reversed 81 CONTRACT_NAMES=${CONTRACT_NAMES}Reversed 82 83 SUMMARY_DIR=test/kontrol/proofs/utils 84 SUMMARY_NAME=DeploymentSummary 85 LICENSE=MIT 86 87 copy_to_docker # Copy the newly generated files to the docker container 88 run kontrol load-state-diff $SUMMARY_NAME snapshots/state-diff/$STATEDIFF --contract-names $CONTRACT_NAMES --output-dir $SUMMARY_DIR --license $LICENSE 89 forge fmt $SUMMARY_DIR/$SUMMARY_NAME.sol 90 forge fmt $SUMMARY_DIR/${SUMMARY_NAME}Code.sol 91 echo "Added state updates to $SUMMARY_DIR/$SUMMARY_NAME.sol"