Skip to content

Commit

Permalink
Test: automate upgrade test in ci (#2692)
Browse files Browse the repository at this point in the history
* feat: automate upgrade test

* test: update upgrade workflow

* test: update upgrade workflow again

* test: update update upgrade scripts

* test: update binary copying

* test: update upgrade dir

* test: update upgrade dir path

* fix: binary copying

* fix: update dir path

* debug

* fix: upgrade version number

* fix: version comparision

* fix: version comparision in run_upgrade_commands.sh

* fix: use pre-release tag first, then use latest release tag for old binary version

* fix: continue-on-error

* checkout current pr branch

* remove checkout -

* release checkout

* typo

* move gaiad binary to GITHUB_WORKSPACE

* debug

* debug: update checkout verison

* fix test.yml

* debug: binary share between steps

* debug: checkout present pr branch before run scripts

* query proposals

* fix cosmovisor dir

* fix the upgrade version

* formatting

* formatting

* formatting

* debug yml format

* typo correction

* make old gaiad version hardcoded

* chore: add comments
  • Loading branch information
yaruwangway authored Aug 23, 2023
1 parent 97d0a13 commit 6cc159e
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 8 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,31 +146,33 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: 1.20.x
- name: Install GaiaV11
# the old gaiad binary version is hardcoded, need to be updated each major release.
- name: Install Old Gaiad
run: |
git checkout v11.0.0
git checkout v11.0.0
make build
cp ./build/gaiad ./build/gaiad11
cp ./build/gaiad ./build/gaiadold
go clean -modcache
if: env.GIT_DIFF
- name: Install GaiaV12
- name: Install New Gaiad
run: |
git checkout -
make build
cp ./build/gaiad ./build/gaiad12
cp ./build/gaiad ./build/gaiadnew
go clean -modcache
if: env.GIT_DIFF
- name: Install Cosmovisor
run: |
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest
if: env.GIT_DIFF
- name: Start GaiaV11
- name: Start Old Gaiad Binary
run: |
go env GOPATH
./contrib/scripts/upgrade_test_scripts/v12/run_gaia_v11.sh
./contrib/scripts/upgrade_test_scripts/run_gaia.sh
if: env.GIT_DIFF
- name: Submit Upgrade Commands
run: |
./contrib/scripts/upgrade_test_scripts/v12/run_upgrade_commands_v12.sh 15
./contrib/scripts/upgrade_test_scripts/run_upgrade_commands.sh 15
if: env.GIT_DIFF
- name: Check for successful upgrade
run: |
Expand Down
92 changes: 92 additions & 0 deletions contrib/scripts/upgrade_test_scripts/run_gaia.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/sh

set -o errexit -o nounset

# find the highest upgrade version number($UPGRADE_VERSION_NUMBER) within the 'app/upgrades' dir.
# the highest upgrade version is used to propose upgrade and create /cosmovisor/upgrades/$UPGRADE_VERSION/bin dir.
UPGRADES_DIR=$(realpath ./app/upgrades)
UPGRADE_VERSION_NUMBER=0

for dir in "$UPGRADES_DIR"/*; do
if [ -d "$dir" ]; then
DIR_NAME=$(basename "$dir")
VERSION_NUMBER="${DIR_NAME#v}"
if [ "$VERSION_NUMBER" -gt "$UPGRADE_VERSION_NUMBER" ]; then
UPGRADE_VERSION_NUMBER=$VERSION_NUMBER
fi
fi
done

if [ -n "$UPGRADE_VERSION_NUMBER" ]; then
echo "Upgrade to version: $UPGRADE_VERSION_NUMBER"
else
echo "No upgrade version found in app/upgrades."
fi

UPGRADE_VERSION=v$UPGRADE_VERSION_NUMBER
NODE_HOME=$(realpath ./build/.gaia)
echo "NODE_HOME = ${NODE_HOME}"
BINARY=$NODE_HOME/cosmovisor/genesis/bin/gaiad
echo "BINARY = ${BINARY}"
CHAINID=cosmoshub-4

USER_MNEMONIC="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art"

if ! test -f "./build/gaiadold"; then
echo "old gaiad binary does not exist"
exit
fi

rm -rf ./build/.gaia

mkdir -p "$NODE_HOME"/cosmovisor/genesis/bin
cp ./build/gaiadold "$NODE_HOME"/cosmovisor/genesis/bin/gaiad
$BINARY init upgrader --chain-id $CHAINID --home "$NODE_HOME"

if ! test -f "./build/gaiadnew"; then
echo "new gaiad binary does not exist"
exit
fi

mkdir -p "$NODE_HOME"/cosmovisor/upgrades/$UPGRADE_VERSION/bin
cp ./build/gaiadnew "$NODE_HOME"/cosmovisor/upgrades/$UPGRADE_VERSION/bin/gaiad

GOPATH=$(go env GOPATH)

export DAEMON_NAME=gaiad
export DAEMON_HOME=$NODE_HOME
COSMOVISOR=$GOPATH/bin/cosmovisor

$BINARY config chain-id $CHAINID --home $NODE_HOME
$BINARY config keyring-backend test --home $NODE_HOME
tmp=$(mktemp)

# add bank part of genesis
jq --argjson foo "$(jq -c '.' contrib/denom.json)" '.app_state.bank.denom_metadata = $foo' $NODE_HOME/config/genesis.json >"$tmp" && mv "$tmp" $NODE_HOME/config/genesis.json

# replace default stake token with uatom
sed -i -e 's/stake/uatom/g' $NODE_HOME/config/genesis.json
# min deposition amount (this one isn't working)
sed -i -e 's%"amount": "10000000",%"amount": "1",%g' $NODE_HOME/config/genesis.json
# min voting power that a proposal requires in order to be a valid proposal
sed -i -e 's%"quorum": "0.334000000000000000",%"quorum": "0.000000000000000001",%g' $NODE_HOME/config/genesis.json
# the minimum proportion of "yes" votes requires for the proposal to pass
sed -i -e 's%"threshold": "0.500000000000000000",%"threshold": "0.000000000000000001",%g' $NODE_HOME/config/genesis.json
# voting period to 30s
sed -i -e 's%"voting_period": "172800s"%"voting_period": "30s"%g' $NODE_HOME/config/genesis.json

echo $USER_MNEMONIC | $BINARY --home $NODE_HOME keys add val --recover --keyring-backend=test
$BINARY add-genesis-account val 10000000000000000000000000uatom --home $NODE_HOME --keyring-backend test
$BINARY gentx val 1000000000uatom --home $NODE_HOME --chain-id $CHAINID
$BINARY collect-gentxs --home $NODE_HOME

sed -i.bak'' 's/minimum-gas-prices = ""/minimum-gas-prices = "0uatom"/' $NODE_HOME/config/app.toml

perl -i~ -0777 -pe 's/# Enable defines if the API server should be enabled.
enable = false/# Enable defines if the API server should be enabled.
enable = true/g' $NODE_HOME/config/app.toml

pwd
ls $NODE_HOME

$COSMOVISOR run start --home $NODE_HOME --x-crisis-skip-assert-invariants >log.out 2>&1 &
96 changes: 96 additions & 0 deletions contrib/scripts/upgrade_test_scripts/run_upgrade_commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/sh

set -o errexit -o nounset

UPGRADES_DIR=$(realpath ./app/upgrades)
UPGRADE_VERSION_NUMBER=0

for dir in "$UPGRADES_DIR"/*; do
if [ -d "$dir" ]; then
DIR_NAME=$(basename "$dir")
VERSION_NUMBER="${DIR_NAME#v}"
if [ "$VERSION_NUMBER" -gt "$UPGRADE_VERSION_NUMBER" ]; then
UPGRADE_VERSION_NUMBER=$VERSION_NUMBER
fi
fi
done

if [ -n "$UPGRADE_VERSION_NUMBER" ]; then
echo "Upgrade to version: $UPGRADE_VERSION_NUMBER"
else
echo "No upgrade version found in app/upgrades."
fi

UPGRADE_VERSION=v$UPGRADE_VERSION_NUMBER
UPGRADE_HEIGHT=$1

if [ -z "$1" ]; then
echo "Need to add an upgrade height"
exit 1
fi

NODE_HOME=$(realpath ./build/.gaia)

echo "NODE_HOME = ${NODE_HOME}"

BINARY=$NODE_HOME/cosmovisor/genesis/bin/gaiad
echo "BINARY = ${BINARY}"

$BINARY version

USER_MNEMONIC="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art"
CHAINID=cosmoshub-4

if test -f "$BINARY"; then

echo "wait 10 seconds for blockchain to start"
sleep 10

$BINARY config chain-id $CHAINID --home $NODE_HOME
$BINARY config output json --home $NODE_HOME
$BINARY config keyring-backend test --home $NODE_HOME
$BINARY config --home $NODE_HOME

key=$($BINARY keys show val --home $NODE_HOME)
if [ -z "$key" ]; then
echo $USER_MNEMONIC | $BINARY --home $NODE_HOME keys add val --recover --keyring-backend=test
fi

echo "\n"
echo "Submitting proposal... \n"
$BINARY tx gov submit-proposal software-upgrade $UPGRADE_VERSION \
--title $UPGRADE_VERSION \
--deposit 10000000uatom \
--upgrade-height $UPGRADE_HEIGHT \
--upgrade-info "upgrade" \
--description "upgrade" \
--fees 400uatom \
--from val \
--keyring-backend test \
--chain-id $CHAINID \
--home $NODE_HOME \
--node tcp://localhost:26657 \
--yes
echo "Done \n"

sleep 6
echo "Casting vote... \n"

$BINARY tx gov vote 1 yes \
--from val \
--keyring-backend test \
--chain-id $CHAINID \
--home $NODE_HOME \
--fees 400uatom \
--node tcp://localhost:26657 \
--yes

echo "Done \n"

$BINARY q gov proposals \
--home $NODE_HOME \
--node tcp://localhost:26657

else
echo "Please build old gaia binary and move to ./build/gaiadold"
fi

0 comments on commit 6cc159e

Please sign in to comment.