Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: automate upgrade test in ci #2692

Merged
merged 38 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
30e19a3
feat: automate upgrade test
Aug 11, 2023
cead278
test: update upgrade workflow
Aug 11, 2023
32e3480
test: update upgrade workflow again
Aug 11, 2023
3f68759
test: update update upgrade scripts
Aug 11, 2023
101174f
test: update binary copying
Aug 11, 2023
01854db
test: update upgrade dir
Aug 11, 2023
a0a804c
test: update upgrade dir path
Aug 11, 2023
9691202
fix: binary copying
Aug 11, 2023
f15a211
fix: update dir path
Aug 11, 2023
261c632
debug
Aug 14, 2023
771ddb7
fix: upgrade version number
Aug 14, 2023
fdce9b8
fix: version comparision
Aug 14, 2023
1583e17
fix: version comparision in run_upgrade_commands.sh
Aug 14, 2023
ab4590b
fix: use pre-release tag first, then use latest release tag for old b…
Aug 14, 2023
c385062
fix: continue-on-error
Aug 14, 2023
81fc1ae
checkout current pr branch
Aug 14, 2023
b12d9d5
remove checkout -
Aug 14, 2023
f10c943
release checkout
Aug 14, 2023
f333b69
Merge branch 'main' into upgrade-test-automation
yaruwangway Aug 14, 2023
1185d45
typo
Aug 14, 2023
d30d32e
move gaiad binary to GITHUB_WORKSPACE
Aug 15, 2023
2ce1957
debug
Aug 15, 2023
c68801c
debug: update checkout verison
Aug 15, 2023
53e074d
fix test.yml
Aug 15, 2023
661acea
debug: binary share between steps
Aug 15, 2023
b5c2b0e
debug: checkout present pr branch before run scripts
Aug 15, 2023
9e0842d
query proposals
Aug 15, 2023
dc3e249
fix cosmovisor dir
Aug 15, 2023
7614b8e
fix the upgrade version
Aug 15, 2023
fa8c5f0
formatting
Aug 16, 2023
2635fff
formatting
Aug 17, 2023
4ff33c2
formatting
Aug 17, 2023
5bb6ce0
debug yml format
Aug 17, 2023
8ae2fa3
typo correction
Aug 17, 2023
b8ae848
Merge branch 'main' into upgrade-test-automation
yaruwangway Aug 17, 2023
4a81307
make old gaiad version hardcoded
Aug 18, 2023
bb996ac
Merge branch 'main' into upgrade-test-automation
yaruwangway Aug 21, 2023
ecf8f3d
chore: add comments
Aug 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions .github/workflows/test.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaruwangway Could you please fix the indentation to avoid having the entire file modified (hard to see the diff)?

Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,34 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: 1.20.x
- name: Install GaiaV11
- name: Install Old Gaiad
run: |
git checkout v11.0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the hardcoded v11.0.0 version imply we have to make a change in a new release?

Copy link
Contributor Author

@yaruwangway yaruwangway Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, here need to be changed every time when we release a new major release, I can add a comment here. presently this test only runs on PR trying to merge to main. This means the test is targeting at upgrading from last major release to present PR branch binary version. I also tried:

  1. config v11.0.0 by latest release or pre-release, it is messy depending on latest release is before or after pre-release.
  2. by using latest tag, somewhow this does not work in our repo, the latest tag is not the latest.

make build
cp ./build/gaiad ./build/gaiad11
cp ./build/gaiad ./build/gaiadold
go clean -modcache
if: env.GIT_DIFF
- name: Install GaiaV12
# if: env.GIT_DIFF
- name: Install New Gaiad
run: |
git checkout -
make build
cp ./build/gaiad ./build/gaiad12
if: env.GIT_DIFF
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
# if: env.GIT_DIFF
- name: Start Old Gaiad Binary
run: |
go env GOPATH
./contrib/scripts/upgrade_test_scripts/v12/run_gaia_v11.sh
if: env.GIT_DIFF
./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
if: env.GIT_DIFF
./contrib/scripts/upgrade_test_scripts/run_upgrade_commands.sh 15
# if: env.GIT_DIFF
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if: env.GIT_DIFF will bring back later when pr get approved.

- name: Check for successful upgrade
run: |
./contrib/scripts/upgrade_test_scripts/test_upgrade.sh 20 5 16 localhost
if: env.GIT_DIFF
# if: env.GIT_DIFF
90 changes: 90 additions & 0 deletions contrib/scripts/upgrade_test_scripts/run_gaia.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/sh

set -o errexit -o nounset
set -x
UPGRADES_DIR=$(realpath ./app/upgrades)
UPGRADE_VERSION_NUMBER=0

for dir in "$UPGRADES_DIR"/*; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth adding a comment in the script what this loop does

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here upgrade version is configured from the latest upgrade in app/upgrades.

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
set -x
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