From 7c8ce527e22c747769fc13bb48477a8cdc4ab58d Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 13 Dec 2023 13:08:22 -0800 Subject: [PATCH] refactor: source upgrade-test-scripts from package --- .gitignore | 1 + upgrade-test-scripts/env_setup.sh | 209 --------------------------- upgrade-test-scripts/install_deps.sh | 22 --- upgrade-test-scripts/run_eval.sh | 18 --- upgrade-test-scripts/run_test.sh | 17 --- upgrade-test-scripts/run_use.sh | 34 ----- upgrade-test-scripts/start_ag0.sh | 94 ------------ upgrade-test-scripts/start_agd.sh | 13 -- upgrade-test-scripts/start_to_to.sh | 53 ------- 9 files changed, 1 insertion(+), 460 deletions(-) delete mode 100755 upgrade-test-scripts/env_setup.sh delete mode 100755 upgrade-test-scripts/install_deps.sh delete mode 100755 upgrade-test-scripts/run_eval.sh delete mode 100755 upgrade-test-scripts/run_test.sh delete mode 100755 upgrade-test-scripts/run_use.sh delete mode 100755 upgrade-test-scripts/start_ag0.sh delete mode 100755 upgrade-test-scripts/start_agd.sh delete mode 100755 upgrade-test-scripts/start_to_to.sh diff --git a/.gitignore b/.gitignore index 46941c6e..859c4320 100644 --- a/.gitignore +++ b/.gitignore @@ -135,3 +135,4 @@ dist # build in CI Dockerfile +upgrade-test-scripts diff --git a/upgrade-test-scripts/env_setup.sh b/upgrade-test-scripts/env_setup.sh deleted file mode 100755 index 3e784b26..00000000 --- a/upgrade-test-scripts/env_setup.sh +++ /dev/null @@ -1,209 +0,0 @@ -#!/bin/bash - -echo ENV_SETUP starting - -# FIXME not used anywhere; restore these debug flags -export DEBUG="SwingSet:ls,SwingSet:vat" - -export CHAINID=agoriclocal -shopt -s expand_aliases - -alias agops="/usr/src/agoric-sdk/node_modules/.bin/agops" -if test -f "$HOME/.agoric/envs"; then - source "$HOME/.agoric/envs" -fi - -export binary=ag0 -if [ -x "$(command -v "agd")" ]; then - export binary=agd -fi -export GOV1ADDR=$($binary keys show gov1 -a --keyring-backend="test") -export GOV2ADDR=$($binary keys show gov2 -a --keyring-backend="test") -export GOV3ADDR=$($binary keys show gov3 -a --keyring-backend="test") -export VALIDATORADDR=$($binary keys show validator -a --keyring-backend="test") -export USER1ADDR=$($binary keys show user1 -a --keyring-backend="test") - -if [[ "$binary" == "agd" ]]; then - configdir=/usr/src/agoric-sdk/packages/vm-config - test -d "$configdir" || configdir=/usr/src/agoric-sdk/packages/vats - # Support testnet addresses - sed -i "s/agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce/$GOV1ADDR/g" "$configdir"/*.json - sed -i "s/agoric140dmkrz2e42ergjj7gyvejhzmjzurvqeq82ang/$GOV2ADDR/g" "$configdir"/*.json - sed -i "s/agoric1w8wktaur4zf8qmmtn3n7x3r0jhsjkjntcm3u6h/$GOV3ADDR/g" "$configdir"/*.json - - # Support mainnet addresses - sed -i "s/agoric1gx9uu7y6c90rqruhesae2t7c2vlw4uyyxlqxrx/$GOV1ADDR/g" "$configdir"/*.json - sed -i "s/agoric1d4228cvelf8tj65f4h7n2td90sscavln2283h5/$GOV2ADDR/g" "$configdir"/*.json - sed -i "s/agoric1zayxg4e9vd0es9c9jlpt36qtth255txjp6a8yc/$GOV3ADDR/g" "$configdir"/*.json - sed -i '/agoric14543m33dr28x7qhwc558hzlj9szwhzwzpcmw6a/d' "$configdir"/*.json - sed -i '/agoric13p9adwk0na5npfq64g22l6xucvqdmu3xqe70wq/d' "$configdir"/*.json - sed -i '/agoric1el6zqs8ggctj5vwyukyk4fh50wcpdpwgugd5l5/d' "$configdir"/*.json - - # change names to gov1/2/3 since order is significant for invitation sending - sed -i "s/Jason Potts/gov1/g" "$configdir"/*.json - sed -i "s/Chloe White/gov2/g" "$configdir"/*.json - sed -i "s/Joe Clark/gov3/g" "$configdir"/*.json - - # Oracle Addresses - sed -i "s/agoric1krunjcqfrf7la48zrvdfeeqtls5r00ep68mzkr/$GOV1ADDR/g" "$configdir"/*.json - sed -i "s/agoric1n4fcxsnkxe4gj6e24naec99hzmc4pjfdccy5nj/$GOV2ADDR/g" "$configdir"/*.json - sed -i '/agoric19uscwxdac6cf6z7d5e26e0jm0lgwstc47cpll8/d' "$configdir"/*.json - sed -i '/agoric144rrhh4m09mh7aaffhm6xy223ym76gve2x7y78/d' "$configdir"/*.json - sed -i '/agoric19d6gnr9fyp6hev4tlrg87zjrzsd5gzr5qlfq2p/d' "$configdir"/*.json - - # committeeSize - sed -i 's/committeeSize": 6/committeeSize": 3/g' "$configdir"/*.json - sed -i 's/minSubmissionCount": 3/minSubmissionCount": 1/g' "$configdir"/*.json -fi - -startAgd() { - agd start --log_level warn "$@" & - AGD_PID=$! - echo $AGD_PID >$HOME/.agoric/agd.pid - wait_for_bootstrap - waitForBlock 2 -} - -killAgd() { - AGD_PID=$(cat $HOME/.agoric/agd.pid) - kill $AGD_PID - rm $HOME/.agoric/agd.pid - wait $AGD_PID || true -} - -waitAgd() { - wait $(cat $HOME/.agoric/agd.pid) - rm $HOME/.agoric/agd.pid -} - -provisionSmartWallet() { - addr="$1" - amount="$2" - echo "funding $addr" - agd tx bank send "validator" "$addr" "$amount" -y --keyring-backend=test --chain-id="$CHAINID" - waitForBlock - echo "provisioning $addr" - agd tx swingset provision-one my-wallet "$addr" SMART_WALLET --keyring-backend=test --yes --chain-id="$CHAINID" --from="$addr" - echo "Waiting for wallet $addr to reach vstorage" - waitForBlock 5 - echo "Reading $addr from vstorage" - agoric wallet show --from "$addr" -} - -wait_for_bootstrap() { - echo "waiting for bootstrap..." - endpoint="localhost" - while true; do - if json=$(curl -s --fail -m 15 "$endpoint:26657/status"); then - if [[ "$(echo "$json" | jq -r .jsonrpc)" == "2.0" ]]; then - if last_height=$(echo "$json" | jq -r .result.sync_info.latest_block_height); then - if [[ "$last_height" != "1" ]]; then - echo "$last_height" - return - else - echo "$last_height" - fi - fi - fi - fi - sleep 2 - done - echo "done" -} - -waitForBlock() ( - echo "waiting for block..." - times=${1:-1} - echo "$times" - for ((i = 1; i <= times; i++)); do - b1=$(wait_for_bootstrap) - while true; do - b2=$(wait_for_bootstrap) - if [[ "$b1" != "$b2" ]]; then - echo "block produced" - break - fi - sleep 1 - done - done - echo "done" -) - -fail() { - echo "FAIL: $1" - exit 1 -} - -success() { - echo "SUCCESS: $1" -} - -test_val() { - want="$2" - got="$1" - testname="${3:-unnamedtest}" - if [[ "$want" != "$got" ]]; then - fail "TEST: $testname: wanted $want, got $got" - else - success "TEST: $testname: wanted $want, got $got" - fi -} - -test_not_val() { - want="$2" - got="$1" - testname="${3:-unnamedtest}" - if [[ "$want" == "$got" ]]; then - fail "TEST: $testname: $want is equal to $got" - else - success "TEST: $testname: $want is not equal to $got" - fi -} - -voteLatestProposalAndWait() { - waitForBlock - proposal=$($binary q gov proposals -o json | jq -r '.proposals[-1].proposal_id') - waitForBlock - $binary tx gov deposit $proposal 50000000ubld --from=validator --chain-id="$CHAINID" --yes --keyring-backend test - waitForBlock - $binary tx gov vote $proposal yes --from=validator --chain-id="$CHAINID" --yes --keyring-backend test - waitForBlock - - while true; do - status=$($binary q gov proposal $proposal -ojson | jq -r .status) - case $status in - PROPOSAL_STATUS_PASSED) - break - ;; - PROPOSAL_STATUS_REJECTED) - echo "Proposal rejected" - exit 1 - ;; - *) - echo "Waiting for proposal to pass (status=$status)" - sleep 1 - ;; - esac - done -} - -printKeys() { - echo "========== GOVERNANCE KEYS ==========" - echo "gov1: $GOV1ADDR" - cat ~/.agoric/gov1.key || true - echo "gov2: $GOV2ADDR" - cat ~/.agoric/gov2.key || true - echo "gov3: $GOV3ADDR" - cat ~/.agoric/gov3.key || true - echo "validator: $VALIDATORADDR" - cat ~/.agoric/validator.key || true - echo "user1: $USER1ADDR" - cat ~/.agoric/user1.key || true - echo "========== GOVERNANCE KEYS ==========" -} - -export USDC_DENOM="ibc/295548A78785A1007F232DE286149A6FF512F180AF5657780FC89C009E2C348F" -export ATOM_DENOM="ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA" -export PSM_PAIR="IST.USDC_axl" - -echo ENV_SETUP finished diff --git a/upgrade-test-scripts/install_deps.sh b/upgrade-test-scripts/install_deps.sh deleted file mode 100755 index e0e6b11b..00000000 --- a/upgrade-test-scripts/install_deps.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -set -e - -PROPOSAL_PATH=$1 - -# The base image is Node 16.9, which supports Corepack. -# Yarn v4 requires Node 18+ but so far it's working with 16.19. -export YARN_IGNORE_NODE=1 - -corepack enable -yarn --version - -# Run where this script is -cd "$(dirname "$(realpath -- "$0")")" - -# TODO consider yarn workspaces to install all in one command -if [ -n "$PROPOSAL_PATH" ]; then - cd "../proposals/$PROPOSAL_PATH" - # install only if the proposal has a yarn.lock - test -n "yarn.lock" && yarn install --immutable -fi diff --git a/upgrade-test-scripts/run_eval.sh b/upgrade-test-scripts/run_eval.sh deleted file mode 100755 index e9027f78..00000000 --- a/upgrade-test-scripts/run_eval.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# Starts agd in the background and runs eval.sh against it in the foreground -# Note that STDOUT mixes the two. TODO separate them cleanly with log output. - -set -e - -source ./env_setup.sh - -PROPOSAL_PATH=$1 - -startAgd - -echo "Agd started. Running eval.sh." -cd /usr/src/proposals/"$PROPOSAL_PATH/" || exit -./eval.sh - -echo "Eval completed. Running 10 blocks and exiting." -waitForBlock 10 diff --git a/upgrade-test-scripts/run_test.sh b/upgrade-test-scripts/run_test.sh deleted file mode 100755 index 2df0c46f..00000000 --- a/upgrade-test-scripts/run_test.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# Starts agd in the background and runs test.sh against it in the foreground -# Note that STDOUT mixes the two. TODO separate them cleanly with log output. - -set -e - -source ./env_setup.sh - -PROPOSAL_PATH=$1 - -startAgd - -echo "Agd started. Running test.sh." -cd /usr/src/proposals/"$PROPOSAL_PATH/" || exit -./test.sh - -echo "Testing completed." diff --git a/upgrade-test-scripts/run_use.sh b/upgrade-test-scripts/run_use.sh deleted file mode 100755 index 11948380..00000000 --- a/upgrade-test-scripts/run_use.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -# Starts agd in the background and runs action.sh against it in the foreground -# Note that STDOUT mixes the two. TODO separate them cleanly with log output. - -set -e - -ID=$1 -if [ -z "$ID" ]; then - echo "Must specify what proposal to use" - exit 1 -fi -PROPOSAL_PATH="/usr/src/proposals/$ID/" - -if [ ! -d "$PROPOSAL_PATH" ]; then - echo "Proposal $ID does not exist" - exit 1 -fi - -if [ ! -f "$PROPOSAL_PATH/use.sh" ]; then - echo "Proposal $ID does not have a use.sh. Skipping." - exit 0 -fi - -source ./env_setup.sh - -echo "Starting agd in the background." -startAgd - -echo "Agd started. Running use.sh." -cd "$PROPOSAL_PATH" -./use.sh - -echo "Actions completed. Running for a few blocks and exiting." -waitForBlock 5 diff --git a/upgrade-test-scripts/start_ag0.sh b/upgrade-test-scripts/start_ag0.sh deleted file mode 100755 index c94fdf75..00000000 --- a/upgrade-test-scripts/start_ag0.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash - -export CHAINID=agoriclocal -ag0 init localnet --chain-id "$CHAINID" - -allaccounts=("gov1" "gov2" "gov3" "user1" "validator") -for i in "${allaccounts[@]}"; do - ag0 keys add $i --keyring-backend=test 2>&1 | tee "$HOME/.agoric/$i.out" - cat "$HOME/.agoric/$i.out" | tail -n1 | tee "$HOME/.agoric/$i.key" -done - -source /usr/src/upgrade-test-scripts/env_setup.sh - -sed -i.bak "s/^timeout_commit =.*/timeout_commit = \"1s\"/" "$HOME/.agoric/config/config.toml" -sed -i.bak "s/^enabled-unsafe-cors =.*/enabled-unsafe-cors = true/" "$HOME/.agoric/config/app.toml" -sed -i.bak "s/^enable-unsafe-cors =.*/enable-unsafe-cors = true/" "$HOME/.agoric/config/app.toml" -sed -i.bak "s/127.0.0.1:26657/0.0.0.0:26657/" "$HOME/.agoric/config/config.toml" -sed -i.bak "s/cors_allowed_origins = \[\]/cors_allowed_origins = \[\"*\"\]/" "$HOME/.agoric/config/config.toml" -sed -i.bak '/^\[api]/,/^\[/{s/^enable[[:space:]]*=.*/enable = true/}' "$HOME/.agoric/config/app.toml" - -contents="$(jq ".app_state.crisis.constant_fee.denom = \"ubld\"" "$HOME/.agoric/config/genesis.json")" && echo -E "${contents}" >"$HOME/.agoric/config/genesis.json" -contents="$(jq ".app_state.mint.params.mint_denom = \"ubld\"" "$HOME/.agoric/config/genesis.json")" && echo -E "${contents}" >"$HOME/.agoric/config/genesis.json" -contents="$(jq ".app_state.gov.deposit_params.min_deposit[0].denom = \"ubld\"" "$HOME/.agoric/config/genesis.json")" && echo -E "${contents}" >"$HOME/.agoric/config/genesis.json" -contents="$(jq ".app_state.staking.params.bond_denom = \"ubld\"" "$HOME/.agoric/config/genesis.json")" && echo -E "${contents}" >"$HOME/.agoric/config/genesis.json" -contents="$(jq ".app_state.slashing.params.signed_blocks_window = \"20000\"" "$HOME/.agoric/config/genesis.json")" && echo -E "${contents}" >"$HOME/.agoric/config/genesis.json" -contents=$(jq '. * { app_state: { gov: { voting_params: { voting_period: "10s" } } } }' "$HOME/.agoric/config/genesis.json") && echo -E "${contents}" >"$HOME/.agoric/config/genesis.json" -export GENACCT=$(ag0 keys show validator -a --keyring-backend="test") -echo "Genesis Account $GENACCT" - -denoms=( - "ibc/toyusdc" #test_usdc - "ibc/06362C6F7F4FB702B94C13CD2E7C03DEC357683FD978936340B43FBFBC5351EB" #test_atom - "ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA" #main_ATOM - "ibc/295548A78785A1007F232DE286149A6FF512F180AF5657780FC89C009E2C348F" #main_usdc_axl - "ibc/6831292903487E58BF9A195FDDC8A2E626B3DF39B88F4E7F41C935CADBAF54AC" #main_usdc_grav - "ibc/F2331645B9683116188EF36FC04A809C28BD36B54555E8705A37146D0182F045" #main_usdt_axl - "ibc/386D09AE31DA7C0C93091BB45D08CB7A0730B1F697CD813F06A5446DCF02EEB2" #main_usdt_grv - "ibc/3914BDEF46F429A26917E4D8D434620EC4817DC6B6E68FB327E190902F1E9242" #main_dai_axl - "ibc/3D5291C23D776C3AA7A7ABB34C7B023193ECD2BC42EA19D3165B2CF9652117E7" #main_dai_grv - "provisionpass" #for swingset provisioning -) - -camount="1000000000000000000" -coins="${camount}ubld" -for i in "${denoms[@]}"; do - coins="${coins},${camount}${i}" -done - -ag0 add-genesis-account "$GENACCT" "$coins" - -ag0 gentx validator 5000000000ubld --keyring-backend="test" --chain-id "$CHAINID" -ag0 collect-gentxs -ag0 start --log_level warn & -ag0_PID=$! -wait_for_bootstrap -waitForBlock 2 - -voting_period_s=10 -latest_height=$(ag0 status | jq -r .SyncInfo.latest_block_height) -height=$(($latest_height + $voting_period_s + 10)) - -info=${UPGRADE_INFO-"{}"} -if echo "$info" | jq .; then - : -else - status=$? - echo "Upgrade info is not valid JSON: $info" - exit $status -fi -ag0 tx gov submit-proposal software-upgrade "$UPGRADE_TO" \ - --upgrade-height="$height" --upgrade-info="$info" \ - --title="Upgrade to ${UPGRADE_TO}" --description="upgrades" \ - --from=validator --chain-id="$CHAINID" \ - --yes --keyring-backend=test -waitForBlock - -voteLatestProposalAndWait - -echo "Chain in to-be-upgraded state for $UPGRADE_TO" - -while true; do - latest_height=$(ag0 status | jq -r .SyncInfo.latest_block_height) - if [ "$latest_height" != "$height" ]; then - echo "Waiting for upgrade height to be reached (need $height, have $latest_height)" - sleep 1 - else - echo "Upgrade height for $UPGRADE_TO reached. Killing ag0" - echo "(CONSENSUS FAILURE above for height $height is expected)" - break - fi -done - -kill $ag0_PID -echo "state directory $HOME/.agoric ready for upgrade to $UPGRADE_TO" diff --git a/upgrade-test-scripts/start_agd.sh b/upgrade-test-scripts/start_agd.sh deleted file mode 100755 index 8d541526..00000000 --- a/upgrade-test-scripts/start_agd.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# Start and leave agd running - -grep -qF 'env_setup.sh' /root/.bashrc || echo "source /usr/src/upgrade-test-scripts/env_setup.sh" >>/root/.bashrc -grep -qF 'printKeys' /root/.bashrc || echo "printKeys" >>/root/.bashrc - -source ./env_setup.sh - -# start_agd never builds an image so it's safe to include this multigigabyte logfile -export SLOGFILE=slog.slog - -# don't use startAgd() because that backgrounds -agd start --log_level warn "$@" diff --git a/upgrade-test-scripts/start_to_to.sh b/upgrade-test-scripts/start_to_to.sh deleted file mode 100755 index 974f617a..00000000 --- a/upgrade-test-scripts/start_to_to.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash -# Prepare or execute an upgrade - -grep -qF 'env_setup.sh' /root/.bashrc || echo "source /usr/src/upgrade-test-scripts/env_setup.sh" >>/root/.bashrc -grep -qF 'printKeys' /root/.bashrc || echo "printKeys" >>/root/.bashrc - -source ./env_setup.sh - -startAgd - -if [[ -z "${UPGRADE_TO}" ]]; then - echo "no upgrade set. running for a few blocks and exiting" - waitForBlock 5 - exit 0 -fi - -voting_period_s=10 -latest_height=$(agd status | jq -r .SyncInfo.latest_block_height) -height=$((latest_height + voting_period_s + 10)) -info=${UPGRADE_INFO-"{}"} -if echo "$info" | jq .; then - echo "upgrade-info: $info" -else - status=$? - echo "Upgrade info is not valid JSON: $info" - exit $status -fi -agd tx gov submit-proposal software-upgrade "$UPGRADE_TO" \ - --upgrade-height="$height" --upgrade-info="$info" \ - --title="Upgrade to ${UPGRADE_TO}" --description="upgrades" \ - --from=validator --chain-id="$CHAINID" \ - --yes --keyring-backend=test -waitForBlock - -voteLatestProposalAndWait - -echo "Chain in to-be-upgraded state for $UPGRADE_TO" - -while true; do - latest_height=$(agd status | jq -r .SyncInfo.latest_block_height) - if [ "$latest_height" != "$height" ]; then - echo "Waiting for upgrade height for $UPGRADE_TO to be reached (need $height, have $latest_height)" - sleep 1 - else - echo "Upgrade height for $UPGRADE_TO reached. Killing agd" - echo "(CONSENSUS FAILURE above for height $height is expected)" - break - fi -done - -sleep 2 -killAgd -echo "state directory $HOME/.agoric ready for upgrade to $UPGRADE_TO"