Skip to content

Commit

Permalink
Test for positive case of upgrade process (#268)
Browse files Browse the repository at this point in the history
* Change entrypoints for tests
* Adopt according to the lat changes in Docker compose files
* Fix env param exporting
* Change version_to parameter getting
* Fix version inserting
* Add gen_node_config script from merge commit
* Fix test.yml
* Fix node_configs generation after merging
* Add /bin/bash into common.sh
* Fix typo

Co-authored-by: @Eengineer1 @askolesov @ankurdotb
Signed-off-by: Andrew Nikitin <[email protected]>
  • Loading branch information
Andrew Nikitin committed Feb 25, 2022
1 parent 471500d commit 54ec64f
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 13 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,33 @@ jobs:
run: |
bash import_keys.sh
bash run_all.sh
run-upgrade-test-positive-case:
name: Run positive case for upgrade
runs-on: ubuntu-20.04
needs: build-node-image
steps:
- uses: actions/checkout@v2

- name: Download node image
uses: actions/download-artifact@v2
with:
name: cheqd-node-image.tar

- name: Load node image
run: docker load -i cheqd-node-image.tar

- name: Chown for current user
run: sudo chown $USER:$USER .

- name: Prepare nodes for checking upgrade
working-directory: ./tests/upgrade
run: bash prepare.sh

- name: Initiate the upgrade process
working-directory: ./tests/upgrade
run: bash initiate_upgrade.sh

- name: Make the upgrade and check results
working-directory: ./tests/upgrade
run: bash upgrade_and_check.sh
3 changes: 3 additions & 0 deletions tests/networks/docker-compose-localnet/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CHEQD_VERSION="latest"
CHEQD_IMAGE_NAME="cheqd-node"
MOUNT_POINT="."
43 changes: 31 additions & 12 deletions tests/networks/docker-compose-localnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,80 @@ version: '3.2'

services:
node0:
image: cheqd-node
image: "${CHEQD_IMAGE_NAME}"
ports:
- "26656:26656" # p2p
- "26657:26657" # rpc
volumes:
- ./node_configs/node0:/home/cheqd
- "${MOUNT_POINT}/node_configs/node0:/cheqd"
entrypoint: cheqd-noded
user: cheqd
environment:
- HOME=/cheqd
command: start --rpc.laddr tcp://0.0.0.0:26657

node1:
image: cheqd-node
image: "${CHEQD_IMAGE_NAME}"
ports:
- "26659:26656" # p2p
- "26660:26657" # rpc
volumes:
- ./node_configs/node1:/home/cheqd
- "${MOUNT_POINT}/node_configs/node1:/cheqd"
entrypoint: cheqd-noded
user: cheqd
environment:
- HOME=/cheqd
command: start --rpc.laddr tcp://0.0.0.0:26657 --p2p.persistent_peers "${NODE_0_ID}@node0:26656"

node2:
image: cheqd-node
image: "${CHEQD_IMAGE_NAME}"
ports:
- "26662:26656" # p2p
- "26663:26657" # rpc
volumes:
- ./node_configs/node2:/home/cheqd
- "${MOUNT_POINT}/node_configs/node2:/cheqd"
entrypoint: cheqd-noded
user: cheqd
environment:
- HOME=/cheqd
command: start --rpc.laddr tcp://0.0.0.0:26657 --p2p.persistent_peers "${NODE_0_ID}@node0:26656"

node3:
image: cheqd-node
image: "${CHEQD_IMAGE_NAME}"
ports:
- "26665:26656" # p2p
- "26666:26657" # rpc
volumes:
- ./node_configs/node3:/home/cheqd
- "${MOUNT_POINT}/node_configs/node3:/cheqd"
entrypoint: cheqd-noded
user: cheqd
environment:
- HOME=/cheqd
command: start --rpc.laddr tcp://0.0.0.0:26657 --p2p.persistent_peers "${NODE_0_ID}@node0:26656"

observer0:
image: cheqd-node
image: "${CHEQD_IMAGE_NAME}"
ports:
- "26668:26656" # p2p
- "26669:26657" # rpc
volumes:
- ./node_configs/observer0:/home/cheqd
- "${MOUNT_POINT}/node_configs/observer0:/cheqd"
entrypoint: cheqd-noded
user: cheqd
environment:
- HOME=/cheqd
command: start --rpc.laddr tcp://0.0.0.0:26657 --minimum-gas-prices "1cheq" --p2p.persistent_peers "${NODE_0_ID}@node0:26656"

observer1:
image: cheqd-node
image: "${CHEQD_IMAGE_NAME}"
ports:
- "26671:26656" # p2p
- "26672:26657" # rpc
volumes:
- ./node_configs/observer1:/home/cheqd
- "${MOUNT_POINT}/node_configs/observer1:/cheqd"
entrypoint: cheqd-noded
user: cheqd
environment:
- HOME=/cheqd
command: start --rpc.laddr tcp://0.0.0.0:26657 --minimum-gas-prices "1cheq" --p2p.persistent_peers "${NODE_0_ID}@node0:26656"

2 changes: 1 addition & 1 deletion tests/networks/docker-compose-localnet/gen-node-configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ do
popd
done

popd # node_configs
popd # node_configs
70 changes: 70 additions & 0 deletions tests/upgrade/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

set -euox pipefail

DOCKER_COMPOSE_DIR="../networks/docker-compose-localnet"
CHEQD_IMAGE_FROM="ghcr.io/cheqd/cheqd-node:0.4.0"
CHEQD_IMAGE_TO="cheqd-node"
CHEQD_VERSION_TO=`echo $(git describe --always --tag --match "v*") | sed 's/^v//'`
git describe --debug
UPGRADE_NAME="v0.4"
VOTING_PERIOD=30
EXPECTED_BLOCK_SECOND=5
EXTRA_BLOCKS=5
UPGRADE_HEIGHT=$(echo $VOTING_PERIOD/$EXPECTED_BLOCK_SECOND+$EXTRA_BLOCKS | bc)
DEPOSIT_AMOUNT=10000000
CHAIN_ID="cheqd"
CHEQD_USER="cheqd"

# cheqd_noded docker wrapper

cheqd_noded_docker() {
docker run --rm \
-v "$(pwd)":"/cheqd" \
--network host \
-u root \
-e HOME=/cheqd \
${CHEQD_IMAGE_FROM} "$@"
}

# Parameters
# $1 - Name of container to run command inside
# $2 - The full command to run
function docker_exec () {
NODE_CONTAINER="$1"

docker exec -u $CHEQD_USER $NODE_CONTAINER "${@:2}"
}

# Parameters
# $1 - Version of base image
# $2 - Root path for making directories for volumes
function docker_compose_up () {
CURR_DIR=$(pwd)
MOUNT_POINT="$2"
pushd "node_configs/node0"
export NODE_0_ID=$(cheqd_noded_docker tendermint show-node-id | sed 's/\r//g')
export CHEQD_IMAGE_NAME="$1"
export MOUNT_POINT=$MOUNT_POINT
docker-compose -f ../../$DOCKER_COMPOSE_DIR/docker-compose.yml --env-file ../../$DOCKER_COMPOSE_DIR/.env up -d
pushd $CURR_DIR
}

# Stop docker-compose
function docker_compose_down () {
docker-compose -f $DOCKER_COMPOSE_DIR/docker-compose.yml --env-file $DOCKER_COMPOSE_DIR/.env down
}

# Clean environment
function clean_env () {
rm -rf node_configs
}

# Run command using local generated keys from node_configs/client
function local_client_exec () {
cheqd_noded_docker "$@" --home node_configs/client/.cheqdnode/ --keyring-backend test
}

function make_777 () {
sudo chmod -R 777 node_configs
}
159 changes: 159 additions & 0 deletions tests/upgrade/gen_node_configs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/bin/bash

# Generates configurations for 4 nodes.

set -euox pipefail

. common.sh

# sed in macos requires extra argument

sed_extension=''
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sed_extension=''
elif [[ "$OSTYPE" == "darwin"* ]]; then
sed_extension='.orig'
fi


# Parameters
# $1 - The full parameter name
# $2 - Value
# $3 - Path to genesis file
edit_genesis () {
PARAMETER_NAME=$1
VALUE=$2
GENESIS_PATH=$3
jq "${PARAMETER_NAME} = \"${VALUE}\"" $GENESIS_PATH > /tmp/1 && mv /tmp/1 $GENESIS_PATH
}

# We use local copy of this function because of using -u root for allowing files creation inside the
cheqd_noded_docker() {
docker run --rm \
-v "$(pwd)":"/cheqd" \
--network host \
--entrypoint "cheqd-noded" \
-u root \
${CHEQD_IMAGE_FROM} "$@" --home /cheqd/.cheqdnode
}

VALIDATORS_COUNT="4"
OBSERVERS_COUNT="2"

NODE_CONFIGS_DIR="node_configs"
rm -rf $NODE_CONFIGS_DIR
mkdir $NODE_CONFIGS_DIR
pushd $NODE_CONFIGS_DIR

echo "Generating validator keys..."

for ((i=0 ; i<$VALIDATORS_COUNT ; i++))
do
NODE_HOME="node$i"
mkdir $NODE_HOME
pushd $NODE_HOME

echo "[Validator $i] Generating key..."

cheqd_noded_docker init "node$i" --chain-id $CHAIN_ID
sudo chown -R $USER:$USER .
echo "$(cheqd_noded_docker tendermint show-node-id)" > node_id.txt
echo "$(cheqd_noded_docker tendermint show-validator)" > node_val_pubkey.txt

echo "Setting minimum fee price..."

sed -i $sed_extension 's/minimum-gas-prices = ""/minimum-gas-prices = "25ncheq"/g' .cheqdnode/config/app.toml

popd
done


OPERATORS_HOME="client"
mkdir $OPERATORS_HOME
pushd $OPERATORS_HOME

echo "Initializing genesis..."
cheqd_noded_docker init dummy_node --chain-id $CHAIN_ID
sudo chown -R $USER:$USER .
sed -i $sed_extension 's/"stake"/"ncheq"/' .cheqdnode/config/genesis.json

echo "Generating operator keys..."

for ((i=0 ; i<$VALIDATORS_COUNT ; i++))
do
cheqd_noded_docker keys add "operator$i" --keyring-backend "test"
sudo chown -R $USER:$USER .
done

echo "Creating genesis accounts..."

for ((i=0 ; i<$VALIDATORS_COUNT ; i++))
do
cheqd_noded_docker add-genesis-account "operator$i" 20000000000000000ncheq --keyring-backend "test"
done

echo "Creating genesis validators..."

for ((i=0 ; i<$VALIDATORS_COUNT ; i++))
do
NODE_HOME="../node$i"
pushd $NODE_HOME

NODE_ID=$(cheqd_noded_docker tendermint show-node-id)
NODE_VAL_PUBKEY=$(cheqd_noded_docker tendermint show-validator)

popd

cheqd_noded_docker gentx "operator$i" 1000000000000000ncheq --chain-id $CHAIN_ID --node-id $NODE_ID --pubkey $NODE_VAL_PUBKEY --keyring-backend "test"
done

echo "Collecting them..."

cheqd_noded_docker collect-gentxs
cheqd_noded_docker validate-genesis

echo "Propagating genesis to nodes..."

# Edit voting parameters
edit_genesis ".app_state.gov.deposit_params.max_deposit_period" "${VOTING_PERIOD}s" .cheqdnode/config/genesis.json
edit_genesis ".app_state.gov.voting_params.voting_period" "${VOTING_PERIOD}s" .cheqdnode/config/genesis.json

for ((i=0 ; i<$VALIDATORS_COUNT ; i++))
do
NODE_HOME="../node$i"

cp ".cheqdnode/config/genesis.json" "$NODE_HOME/.cheqdnode/config/"
done


popd # operators' home


echo "##### Setting up observers..."

for ((i=0 ; i<$OBSERVERS_COUNT ; i++))
do
NODE_HOME="observer$i"

mkdir $NODE_HOME
pushd $NODE_HOME

echo "##### [Observer $i] Generating keys..."
cheqd_noded_docker init "node$i" --chain-id $CHAIN_ID
sudo chown -R $USER:$USER .

echo "##### [Observer $i] Exporting public keys..."
echo "$(cheqd_noded_docker tendermint show-node-id)" > node_id.txt
echo "$(cheqd_noded_docker tendermint show-validator)" > node_val_pubkey.txt

echo "##### [Observer $i] Loading genesis..."
OPERATORS_HOME="../client"
cp "$OPERATORS_HOME/.cheqdnode/config/genesis.json" ".cheqdnode/config/"

echo "##### [Observer $i] Setting min gas prices..."
sed -i $sed_extension 's/minimum-gas-prices = ""/minimum-gas-prices = "25ncheq"/g' .cheqdnode/config/app.toml

popd
done

popd # node_configs
Loading

0 comments on commit 54ec64f

Please sign in to comment.