Skip to content

Commit

Permalink
Merge pull request #276 from cheqd/DEV-826
Browse files Browse the repository at this point in the history
[DEV-826] Additional txns before upgrade
  • Loading branch information
Toktar authored Feb 2, 2022
2 parents e21c1da + 2c5ae6d commit fe7c6ca
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ jobs:
needs: build-node-image
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # It's needed for getting the full version of package by `git describe`

- name: Download node image
uses: actions/download-artifact@v2
Expand Down
129 changes: 124 additions & 5 deletions tests/upgrade/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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
Expand All @@ -15,6 +14,12 @@ UPGRADE_HEIGHT=$(echo $VOTING_PERIOD/$EXPECTED_BLOCK_SECOND+$EXTRA_BLOCKS | bc)
DEPOSIT_AMOUNT=10000000
CHAIN_ID="cheqd"
CHEQD_USER="cheqd"
FNAME_TXHASHES="txs.hashes"
AMOUNT_BEFORE="19000000000000000"
CHEQ_AMOUNT="1ncheq"
CHEQ_AMOUNT_NUMBER="1"
DID_1="did:cheqd:testnet:abcdef"
DID_2="did:cheqd:testnet:higklm"

# cheqd_noded docker wrapper

Expand All @@ -24,7 +29,8 @@ cheqd_noded_docker() {
--network host \
-u root \
-e HOME=/cheqd \
${CHEQD_IMAGE_FROM} "$@"
--entrypoint "cheqd-noded" \
${CHEQD_IMAGE_FROM} $@
}

# Parameters
Expand Down Expand Up @@ -58,13 +64,126 @@ function docker_compose_down () {
# Clean environment
function clean_env () {
rm -rf node_configs
rm -f $FNAME_TXHASHES
}

# 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 local_client_tx () {
cheqd_noded_docker $@ --home node_configs/client/.cheqdnode/ --keyring-backend test
}

function make_777 () {
sudo chmod -R 777 node_configs
}
}



# Transaction related funcs

function random_string() {
echo $RANDOM | base64 | head -c 20
return 0
}

function get_addresses () {
all_keys=$(local_client_tx keys list)
addresses=( $(echo "$all_keys" | grep -o 'cheqd1.*') )
echo "${addresses[@]}"
}

# Send tokens from the first address in the list to another one
# Input: address to send to
function send_tokens() {
get_addresses

OP_ADDRESS_TO=$1
OP0_ADDRESS=${addresses[0]}

send_res=$(local_client_tx tx \
bank \
send $OP0_ADDRESS $OP_ADDRESS_TO $CHEQ_AMOUNT \
--gas auto \
--gas-adjustment 1.2 \
--gas-prices "25ncheq" \
--chain-id $CHAIN_ID \
-y)
txhash=$(echo $send_res | jq ".txhash" | tr -d '"')
echo $txhash >> $FNAME_TXHASHES
}

# Send DID
# input: DID to write
function send_did () {
did_to_write=$1

# Generate Alice identity key
ALICE_VER_KEY="$(cheqd_noded_docker debug ed25519 random)"
ALICE_VER_PUB_BASE_64=$(echo "${ALICE_VER_KEY}" | jq -r ".pub_key_base_64")
ALICE_VER_PRIV_BASE_64=$(echo "${ALICE_VER_KEY}" | jq -r ".priv_key_base_64")
ALICE_VER_PUB_MULTIBASE_58=$(cheqd_noded_docker debug encoding base64-multibase58 "${ALICE_VER_PUB_BASE_64}")

# Build CreateDid message
KEY_ID="${did_to_write}#key1"

MSG_CREATE_DID='{"id":"'${did_to_write}'","verification_method":[{"id":"'${KEY_ID}'","type":"Ed25519VerificationKey2020","controller":"'${did_to_write}'","public_key_multibase":"'${ALICE_VER_PUB_MULTIBASE_58}'"}],"authentication":["'${KEY_ID}'"]}'

# Post the message
did=$(local_client_tx tx cheqd create-did ${MSG_CREATE_DID} ${KEY_ID} \
--ver-key "${ALICE_VER_PRIV_BASE_64}" \
--from operator0 \
--gas-prices "25ncheq" \
--chain-id $CHAIN_ID \
--output json \
-y)


txhash=$(echo $did | jq ".txhash" | tr -d '"')
echo $txhash >> $FNAME_TXHASHES
}

# Check transaction hashes
function check_tx_hashes () {
for txhash in $(cat $FNAME_TXHASHES);
do
txhash=$(echo ${txhash} | tr -d '"')
result=$(cheqd_noded_docker query tx ${txhash} --output json)
tx_exist=$(echo $result | jq ".code")
if [ $tx_exist != "0" ] ; then
echo "Error was in checking tx with hash: $txhash"
exit 1
fi
done
}

function get_balance () {
address=$1
echo $(cheqd_noded_docker query bank balances $address | grep amount | sed 's/[^0-9]//g')
}

function get_did () {
requested_did=$1
cheqd_noded_docker query cheqd did $requested_did --output json
}

# Check that balance of operator3 increased to CHEQ_AMOUNT
# Input: Address to check
function check_balance () {
address_to_check=$1
new_balance=$(get_balance $address_to_check)
if [ $(echo $new_balance-$AMOUNT_BEFORE | bc) != $CHEQ_AMOUNT_NUMBER ];
then
echo "Balance after token send is not expected"
exit 1
fi
}

# Check that $DID exists
function check_did () {
did_to_check=$1
did_from=$(get_did $did_to_check | jq ".did.id" | tr -d '"')
if [ $did_from != "$did_to_check" ];
then
echo "There is no any $did_to_check on server"
exit 1
fi
}
15 changes: 6 additions & 9 deletions tests/upgrade/initiate_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ set -euox pipefail

. common.sh

# Wait for start ordering, till height 2
bash ../networks/tools/wait-for-chain.sh 2

# Send proposal to pool
local_client_exec tx gov submit-proposal software-upgrade \
local_client_tx tx gov submit-proposal software-upgrade \
$UPGRADE_NAME \
--title "Upgrade to new version" \
--description "Description of upgrade to new version" \
--title "Upgrade-to-new-version" \
--description "Description-of-upgrade-to-new-version" \
--upgrade-height $UPGRADE_HEIGHT \
--from operator1 \
--gas auto \
Expand All @@ -21,7 +18,7 @@ local_client_exec tx gov submit-proposal software-upgrade \
-y

# Set the deposit from operator0
local_client_exec tx gov deposit 1 \
local_client_tx tx gov deposit 1 \
"${DEPOSIT_AMOUNT}ncheq" \
--from operator0 \
--gas auto \
Expand All @@ -31,7 +28,7 @@ local_client_exec tx gov deposit 1 \
-y

# Make a vote for operator0
local_client_exec tx gov vote 1 \
local_client_tx tx gov vote 1 \
yes \
--from operator0 \
--gas auto \
Expand All @@ -41,7 +38,7 @@ local_client_exec tx gov vote 1 \
-y

# Make a vote for operator1
local_client_exec tx gov vote 1 \
local_client_tx tx gov vote 1 \
yes \
--from operator1 \
--gas auto \
Expand Down
27 changes: 23 additions & 4 deletions tests/upgrade/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,27 @@ clean_env
# Generate config files
bash gen_node_configs.sh

# Make all the data accessable
make_777

# Start the network on version which will be upgraded from
docker_compose_up "${CHEQD_IMAGE_FROM}" $(pwd)
docker_compose_up "${CHEQD_IMAGE_FROM}" $(pwd)

# Wait for start ordering, till height 1
bash ../networks/tools/wait-for-chain.sh 1

# Get address of operator which will be used for sending tokens before upgrade
get_addresses
OP2_ADDRESS=${addresses[2]}

# Send tokens before upgrade
send_tokens $OP2_ADDRESS

# Send DID transaction
send_did $DID_1

# Check that token transaction exists
check_tx_hashes

# Check that $DID was written
check_did $DID_1

# Check balance after token sending
check_balance $OP2_ADDRESS
28 changes: 27 additions & 1 deletion tests/upgrade/upgrade_and_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,39 @@ docker_compose_up "$CHEQD_IMAGE_TO" $(pwd)
bash ../networks/tools/wait-for-chain.sh $(echo $UPGRADE_HEIGHT+2 | bc)

CURRENT_VERSION=$(docker run --entrypoint cheqd-noded cheqd-node version 2>&1)
# CURRENT_VERSION=$(curl -s http://localhost:26657/abci_info | jq '.result.response.version' | grep -Eo '[0-9]*\.[0-9]*\.[0-9]*')

if [ $CURRENT_VERSION != $CHEQD_VERSION_TO ] ; then
echo "Upgrade to version $CHEQD_VERSION_TO was not successful"
exit 1
fi

get_addresses
# "To" address was used for sending tokens before upgrade
OP_ADDRESS_BEFORE=${addresses[2]}
# "To" address was used for sending tokens after upgrade
OP_ADDRESS_AFTER=${addresses[3]}

# Check balances after tokens sending
check_balance $OP_ADDRESS_BEFORE

# Check that did written before upgrade stil exist
check_did $DID_1

# Send tokens for checking functionality after upgrade
send_tokens $OP_ADDRESS_AFTER

# Send DID after upgrade
send_did $DID_2

# Check balance after token sending
check_balance $OP_ADDRESS_AFTER

# Check that did written before upgrade stil exist
check_did $DID_2

# Check that token transaction exists after upgrade too
check_tx_hashes

# Stop docker compose
docker_compose_down

Expand Down

0 comments on commit fe7c6ca

Please sign in to comment.