From c9690c9f858c3234857a3f8255d8a102df30bfe6 Mon Sep 17 00:00:00 2001 From: John Saigle <4022790+johnsaigle@users.noreply.github.com> Date: Sun, 6 Oct 2024 16:39:20 -0400 Subject: [PATCH] eth: fix unbound variable errors in shell utilities (#4103) The `set -u` options in these scripts caused them to fail with 'unbound variable' errors when CLI args or env variables were unset. This commit fixes the validation so that the scripts output usage info or helpful errors instead of exiting with unbound variable errors that the user must read the source to diagnose. for the script `ethereum/sh/upgrade_all_testnet.sh`, the commit updates a variable name that appears incorrect. --- ethereum/anvil_fork | 5 +++-- ethereum/sh/upgrade.sh | 22 ++++++++++++++++++---- ethereum/sh/upgrade_all_testnet.sh | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ethereum/anvil_fork b/ethereum/anvil_fork index 9d5044c181..ad9644782d 100755 --- a/ethereum/anvil_fork +++ b/ethereum/anvil_fork @@ -5,11 +5,12 @@ set -euo pipefail # This script forks a chain using anvil with the mnemonic that is used in the # testing environment. -if [ -z "$1" ]; then +CHAIN_NAME="${1:-}" + +if [ -z "$CHAIN_NAME" ]; then echo "Usage: $0 " >&2 exit 1 fi -CHAIN_NAME="$1" DOCKER_ARGS="-p 8545:8545" ./foundry anvil --host 0.0.0.0 --base-fee 0 --fork-url $(worm info rpc mainnet $CHAIN_NAME) --mnemonic "myth like bonus scare over problem client lizard pioneer submit female collect" diff --git a/ethereum/sh/upgrade.sh b/ethereum/sh/upgrade.sh index 42e8c87b90..947b166181 100755 --- a/ethereum/sh/upgrade.sh +++ b/ethereum/sh/upgrade.sh @@ -8,14 +8,28 @@ set -euo pipefail -network=$1 -module=$2 -chain=$3 +network="${1:-}" +module="${2:-}" +chain="${3:-}" + +if [ -z "$network" ] || [ -z "$module" ] || [ -z "$chain" ]; then + echo "Usage: MNEMONIC=... $0 " >&2 + exit 1 +fi + +if [ -z "${MNEMONIC:-}" ]; then + echo "MNEMONIC unset" + exit 1 +fi secret=$MNEMONIC guardian_secret="" if [ "$network" = testnet ]; then + if [ -z "${GUARDIAN_MNEMONIC:-}" ]; then + echo "GUARDIAN_MNEMONIC unset" + exit 1 + fi guardian_secret=$GUARDIAN_MNEMONIC fi @@ -114,4 +128,4 @@ if [ "$network" = testnet ]; then worm submit $(worm generate upgrade -c "$chain" -a "$new_implementation" -m "$module" -g "$guardian_secret") -n "$network" else echo "../scripts/contract-upgrade-governance.sh -c $chain -m $verify_module -a $new_implementation" -fi \ No newline at end of file +fi diff --git a/ethereum/sh/upgrade_all_testnet.sh b/ethereum/sh/upgrade_all_testnet.sh index de3c283023..334fcde598 100755 --- a/ethereum/sh/upgrade_all_testnet.sh +++ b/ethereum/sh/upgrade_all_testnet.sh @@ -21,7 +21,7 @@ set -uo pipefail network=testnet for module in ${MODULES[@]}; do - for chain in ${chains[@]}; do + for chain in ${CHAINS[@]}; do echo "Upgrading ${chain} ${module} ********************************************************************" ./sh/upgrade.sh "$network" "$module" "$chain" done