Skip to content

Commit

Permalink
Add txn sending after upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Nikitin <[email protected]>
  • Loading branch information
Andrew Nikitin committed Feb 2, 2022
1 parent a310970 commit 2c5ae6d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
31 changes: 18 additions & 13 deletions tests/upgrade/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ DEPOSIT_AMOUNT=10000000
CHAIN_ID="cheqd"
CHEQD_USER="cheqd"
FNAME_TXHASHES="txs.hashes"
OP3_AMOUNT_BEFORE="19000000000000000"
AMOUNT_BEFORE="19000000000000000"
CHEQ_AMOUNT="1ncheq"
CHEQ_AMOUNT_NUMBER="1"
DID="did:cheqd:testnet:abcdef"
DID_1="did:cheqd:testnet:abcdef"
DID_2="did:cheqd:testnet:higklm"

# cheqd_noded docker wrapper

Expand Down Expand Up @@ -91,15 +92,16 @@ function get_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]}
OP3_ADDRESS=${addresses[3]}

send_res=$(local_client_tx tx \
bank \
send $OP0_ADDRESS $OP3_ADDRESS $CHEQ_AMOUNT \
send $OP0_ADDRESS $OP_ADDRESS_TO $CHEQ_AMOUNT \
--gas auto \
--gas-adjustment 1.2 \
--gas-prices "25ncheq" \
Expand All @@ -110,7 +112,9 @@ function send_tokens() {
}

# 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)"
Expand All @@ -119,9 +123,9 @@ function send_did () {
ALICE_VER_PUB_MULTIBASE_58=$(cheqd_noded_docker debug encoding base64-multibase58 "${ALICE_VER_PUB_BASE_64}")

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

MSG_CREATE_DID='{"id":"'${DID}'","verification_method":[{"id":"'${KEY_ID}'","type":"Ed25519VerificationKey2020","controller":"'${DID}'","public_key_multibase":"'${ALICE_VER_PUB_MULTIBASE_58}'"}],"authentication":["'${KEY_ID}'"]}'
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} \
Expand Down Expand Up @@ -162,11 +166,11 @@ function get_did () {
}

# Check that balance of operator3 increased to CHEQ_AMOUNT
# Input: Address to check
function check_balance () {
get_addresses
OP3_ADDRESS=${addresses[3]}
new_balance=$(get_balance $OP3_ADDRESS)
if [ $(echo $new_balance-$OP3_AMOUNT_BEFORE | bc) != $CHEQ_AMOUNT_NUMBER ];
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
Expand All @@ -175,10 +179,11 @@ function check_balance () {

# Check that $DID exists
function check_did () {
did_from=$(get_did $DID | jq ".did.id" | tr -d '"')
if [ $did_from != "$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 on server"
echo "There is no any $did_to_check on server"
exit 1
fi
}
16 changes: 10 additions & 6 deletions tests/upgrade/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ 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
send_tokens $OP2_ADDRESS

# Send DID transactions
send_did
# Send DID transaction
send_did $DID_1

# Check that token transaction exists
check_tx_hashes

# Check that $DID was written
check_did
check_did $DID_1

# Check balances after token sending
check_balance
# Check balance after token sending
check_balance $OP2_ADDRESS
28 changes: 23 additions & 5 deletions tests/upgrade/upgrade_and_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,32 @@ if [ $CURRENT_VERSION != $CHEQD_VERSION_TO ] ; then
exit 1
fi

# Check that token transaction exists after upgrade too
check_tx_hashes
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

# Check balances after token sending
check_balance
# 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
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 2c5ae6d

Please sign in to comment.