Skip to content

Commit

Permalink
eth: fix unbound variable errors in shell utilities (#4103)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
johnsaigle authored Oct 6, 2024
1 parent 818fda3 commit c9690c9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 3 additions & 2 deletions ethereum/anvil_fork
Original file line number Diff line number Diff line change
Expand Up @@ -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 <chain name>" >&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"
22 changes: 18 additions & 4 deletions ethereum/sh/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <network> <module> <chain name>" >&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

Expand Down Expand Up @@ -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
fi
2 changes: 1 addition & 1 deletion ethereum/sh/upgrade_all_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c9690c9

Please sign in to comment.