diff --git a/.dockerignore b/.dockerignore index 059b8e17d..01b9b6f06 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ Vagrantfile bin/ coverage.txt +scripts/ \ No newline at end of file diff --git a/scripts/upgrade-test.sh b/scripts/upgrade-test.sh index 6f548a3bb..888ba715b 100755 --- a/scripts/upgrade-test.sh +++ b/scripts/upgrade-test.sh @@ -4,7 +4,7 @@ FORK=${FORK:-"false"} # $(curl --silent "https://api.github.com/repos/classic-terra/core/releases/latest" | jq -r '.tag_name') -OLD_VERSION=v2.1.2 +OLD_VERSION=v2.0.1 UPGRADE_WAIT=${UPGRADE_WAIT:-20} HOME=mytestnet ROOT=$(pwd) diff --git a/scripts/wasm/astroport/assembly-deploy.sh b/scripts/wasm/astroport/assembly-deploy.sh new file mode 100644 index 000000000..626ff643b --- /dev/null +++ b/scripts/wasm/astroport/assembly-deploy.sh @@ -0,0 +1,211 @@ +#!/bin/bash + +set -e + +# This script is used to deploy the contract to the network. +BINARY=_build/old/terrad +ASSEMBLY="scripts/wasm/contracts/old_astroport_assembly.wasm" +BUILDERUNLOCK="scripts/wasm/contracts/old_astroport_builder_unlock.wasm" +XASTROC="scripts/wasm/contracts/old_xastroc.wasm" +ASTROC="scripts/wasm/contracts/old_astroc_token.wasm" +KEYRING_BACKEND="test" +HOME=mytestnet +CHAIN_ID=localterra + +# CONTRACT ADDRESS array +# xastroc, astroc, builder unlock, assembly +CONTRACT_ADDRESS=() + +# ====== STORE OLD CONTRACTS ====== +echo "... stores builder unlock" +addr=$($BINARY keys show test0 -a --home $HOME --keyring-backend $KEYRING_BACKEND) +out=$($BINARY tx wasm store ${BUILDERUNLOCK} --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 100000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not store binary" >&2 + echo $out >&2 + exit $code +fi +sleep 10 +txhash=$(echo $out | jq -r '.txhash') +builder_unlock_id=$($BINARY q tx $txhash -o json | jq -r '.raw_log' | jq -r '.[0].events[1].attributes[1].value') +echo "BUILDERUNLOCK CODE = $builder_unlock_id" +echo "" + +echo "... stores assembly" +addr=$($BINARY keys show test0 -a --home $HOME --keyring-backend $KEYRING_BACKEND) +out=$($BINARY tx wasm store ${ASSEMBLY} --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 100000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not store binary" >&2 + echo $out >&2 + exit $code +fi +sleep 10 +txhash=$(echo $out | jq -r '.txhash') +assembly_id=$($BINARY q tx $txhash -o json | jq -r '.raw_log' | jq -r '.[0].events[1].attributes[1].value') +echo "ASSEMBLY CODE = $assembly_id" +echo "" + +echo "... stores xastroc" +addr=$($BINARY keys show test0 -a --home $HOME --keyring-backend $KEYRING_BACKEND) +out=$($BINARY tx wasm store ${XASTROC} --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 100000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not store binary" >&2 + echo $out >&2 + exit $code +fi +sleep 10 +txhash=$(echo $out | jq -r '.txhash') +xastroc_id=$($BINARY q tx $txhash -o json | jq -r '.raw_log' | jq -r '.[0].events[1].attributes[1].value') +echo "XASTROC CODE = $xastroc_id" +echo "" + +echo "... stores astroc" +addr=$($BINARY keys show test0 -a --home $HOME --keyring-backend $KEYRING_BACKEND) +out=$($BINARY tx wasm store ${ASTROC} --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 100000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not store binary" >&2 + echo $out >&2 + exit $code +fi +sleep 10 +txhash=$(echo $out | jq -r '.txhash') +astroc_id=$($BINARY q tx $txhash -o json | jq -r '.raw_log' | jq -r '.[0].events[1].attributes[1].value') +echo "ASTROC CODE = $astroc_id" +echo "" + +echo "... stores dummy" +addr=$($BINARY keys show test0 -a --home $HOME --keyring-backend $KEYRING_BACKEND) +out=$($BINARY tx wasm store ${XASTROC} --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 100000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not store binary" >&2 + echo $out >&2 + exit $code +fi +sleep 10 + +# ====== INSTATIATE OLD CONTRACTS ====== +echo "... instantiates xastroc" +addr1=$($BINARY keys show test1 -a --home $HOME --keyring-backend $KEYRING_BACKEND) +addr2=$($BINARY keys show test2 -a --home $HOME --keyring-backend $KEYRING_BACKEND) +msg=$(jq -n ' +{ + "name": "Staked Astroport", + "symbol": "xASTRO", + "decimals": 6, + "initial_balances": [ + { + "address": "'$addr'", + "amount": "1000000000000000" + }, + { + "address": "'$addr1'", + "amount": "1000000000000000" + }, + { + "address": "'$addr2'", + "amount": "1000000000000000" + } + ], +}') +echo $msg +out=$($BINARY tx wasm instantiate $xastroc_id "$msg" --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 20000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not instantiate contract" >&2 + echo $out >&2 + exit $code +fi +sleep 10 +txhash=$(echo $out | jq -r '.txhash') +XASTROC_ADDR=$($BINARY q tx $txhash -o json | jq -r '.raw_log' | jq -r '.[0].events[0].attributes[3].value') +CONTRACT_ADDRESS+=($XASTROC_ADDR) + +echo "... instantiates astroc" +msg=$(jq -n ' +{ + "name": "Astroport", + "symbol": "ASTRO", + "decimals": 6, + "initial_balances": [ + { + "address": "'$addr'", + "amount": "1000000000000000" + } + ] +}') +echo $msg +out=$($BINARY tx wasm instantiate $astroc_id "$msg" --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 20000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not instantiate contract" >&2 + echo $out >&2 + exit $code +fi +sleep 10 +txhash=$(echo $out | jq -r '.txhash') +ASTROC_ADDR=$($BINARY q tx $txhash -o json | jq -r '.raw_log' | jq -r '.[0].events[0].attributes[3].value') +CONTRACT_ADDRESS+=($ASTROC_ADDR) + +echo "... instantiates builder unlock" +msg=$(jq -n ' +{ + "owner": "'$addr'", + "max_allocations_amount": "100000000", + "astro_token": "'$ASTROC_ADDR'" +}') +echo $msg +out=$($BINARY tx wasm instantiate $builder_unlock_id "$msg" --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 20000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not instantiate contract" >&2 + echo $out >&2 + exit $code +fi +sleep 10 +txhash=$(echo $out | jq -r '.txhash') +BUILDER_UNLOCK_ADDR=$($BINARY q tx $txhash -o json | jq -r '.raw_log' | jq -r '.[0].events[0].attributes[3].value') +CONTRACT_ADDRESS+=($BUILDER_UNLOCK_ADDR) + +# 50 block voting period +# 13000 block effective delay +# 87000 block expiration period +# 1000xastroc required deposit +echo "... instantiates assembly" +msg=$(jq -n ' +{ + "xastro_token_addr": "'$XASTROC_ADDR'", + "builder_unlock_addr": "'$BUILDER_UNLOCK_ADDR'", + "proposal_voting_period": 20, + "proposal_effective_delay": 13000, + "proposal_expiration_period": 87000, + "proposal_required_deposit": "1000", + "proposal_required_quorum": "0.1", + "proposal_required_threshold": "0.50", + "whitelisted_links": [ + "https://forum.astroport.fi/", + "http://forum.astroport.fi/", + "https://astroport.fi/", + "http://astroport.fi/" + ] +}') +echo $msg +out=$($BINARY tx wasm instantiate $assembly_id "$msg" --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 20000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not instantiate contract" >&2 + echo $out >&2 + exit $code +fi +sleep 10 +txhash=$(echo $out | jq -r '.txhash') +ASSEMBLY_ADDR=$($BINARY q tx $txhash -o json | jq -r '.raw_log' | jq -r '.[0].events[0].attributes[3].value') +CONTRACT_ADDRESS+=($ASSEMBLY_ADDR) + +CONTRACT_ADDRESS_STRING="${CONTRACT_ADDRESS[*]}" +echo "CONTRACT_ADDRESS = $CONTRACT_ADDRESS_STRING" +export CONTRACT_ADDRESS_STRING \ No newline at end of file diff --git a/scripts/wasm/astroport/test-interaction-after.sh b/scripts/wasm/astroport/test-interaction-after.sh new file mode 100644 index 000000000..52b29c12d --- /dev/null +++ b/scripts/wasm/astroport/test-interaction-after.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +BINARY=_build/new/terrad bash scripts/wasm/astroport/test-interaction.sh \ No newline at end of file diff --git a/scripts/wasm/astroport/test-interaction.sh b/scripts/wasm/astroport/test-interaction.sh new file mode 100644 index 000000000..dcf6fa478 --- /dev/null +++ b/scripts/wasm/astroport/test-interaction.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +BINARY=${BINARY:-_build/old/terrad} +KEYRING_BACKEND="test" +HOME=mytestnet +CHAIN_ID=localterra + +if [ -z "$CONTRACT_ADDRESS_STRING" ]; then + echo "CONTRACT_ADDRESS_STRING is empty" + exit 1 +fi + +read -r -a CONTRACT_ADDRESS <<< ${CONTRACT_ADDRESS_STRING:-""} +echo "CONTRACT_ADDRESS = ${CONTRACT_ADDRESS[@]}" + +# specify query function to use +query_res="" +query_wasm_old() { + contract=$1 + query=$2 + res=$($BINARY query wasm contract-store $contract "$query" --chain-id $CHAIN_ID --home $HOME -o json | jq -r '.query_result') + query_res=$res +} + +query_wasm_new() { + contract=$1 + query=$2 + res=$($BINARY query wasm contract-state smart $contract "$query" --chain-id $CHAIN_ID --home $HOME -o json | jq -r '.data') + query_res=$res +} + +query_func=query_wasm_old +if [ "$BINARY" = "_build/new/terrad" ]; then + query_func=query_wasm_new +fi + +# submit proposal +echo "... submit proposal" +proposal=$(jq -n ' +{ + "submit_proposal": { + "title": "Proposal X", + "description": "This is proposal X" + } +}') + +base64_proposal=$(base64 <<< $proposal) + +echo $base64_proposal + +msg=$(jq -n ' +{ + "send": { + "amount": "2000", + "contract": "'${CONTRACT_ADDRESS[3]}'", + "msg": "'$base64_proposal'" + } +}') +echo $msg +out=$($BINARY tx wasm execute ${CONTRACT_ADDRESS[0]} "$msg" --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 100000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) +code=$(echo $out | jq -r '.code') +if [ "$code" != "0" ]; then + echo "... Could not execute contract" >&2 + echo $out >&2 + exit $code +fi +txhash=$(echo $out | jq -r ."txhash") +echo $txhash + +sleep 10 + +# vote proposal for test1 and test2 +query=$(jq -n ' +{ + "proposals": {} +}') + +$query_func ${CONTRACT_ADDRESS[3]} "$query" +proposal_count=$(echo $query_res | jq -r '.proposal_count') + +msg=$(jq -n ' +{ + "cast_vote": { + "proposal_id": '$((proposal_count))', + "vote": "For" + } +}') +echo $msg + +for i in $(seq 1 2); do + echo "... test$i vote proposal $proposal_count" + out=$($BINARY tx wasm execute ${CONTRACT_ADDRESS[3]} "$msg" --from test$i --output json --gas auto --gas-adjustment 2.3 --fees 100000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) + code=$(echo $out | jq -r '.code') + if [ "$code" != "0" ]; then + echo "... Could not execute contract" >&2 + echo $out >&2 + exit $code + fi + sleep 10 + txhash=$(echo $out | jq -r '.txhash') + echo $txhash +done + +# end proposal +query=$(jq -n ' +{ + "proposal": { + "proposal_id": '$((proposal_count))' + } +}') +$query_func ${CONTRACT_ADDRESS[3]} "$query" +end_block=$(echo $query_res | jq -r '.end_block') +while true; do + BLOCK_HEIGHT=$($BINARY status | jq '.SyncInfo.latest_block_height' -r) + echo "BLOCK HEIGHT = $BLOCK_HEIGHT" + # check if block height is greater than end_block + if (( $BLOCK_HEIGHT > $end_block )); then + # ending proposal + msg=$(jq -n ' + { + "end_proposal": { + "proposal_id": '$((proposal_count))' + } + }') + echo $msg + out=$($BINARY tx wasm execute ${CONTRACT_ADDRESS[3]} "$msg" --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 100000000uluna --chain-id $CHAIN_ID --home $HOME --keyring-backend $KEYRING_BACKEND -y) + code=$(echo $out | jq -r '.code') + if [ "$code" != "0" ]; then + echo "... Could not execute contract" >&2 + echo $out >&2 + exit $code + fi + break + fi + sleep 10 +done + +sleep 10 + +# check result of proposal +echo "... query proposals" +query=$(jq -n ' +{ + "proposal": { + "proposal_id": '$((proposal_count))' + } +}') +$query_func ${CONTRACT_ADDRESS[3]} "$query" +status=$(echo $query_res | jq -r '.status') +echo $status \ No newline at end of file diff --git a/scripts/wasm/contracts/astro_assembly.wasm b/scripts/wasm/contracts/astro_assembly.wasm new file mode 100644 index 000000000..7b5d16d74 Binary files /dev/null and b/scripts/wasm/contracts/astro_assembly.wasm differ diff --git a/scripts/wasm/contracts/builder_unlock.wasm b/scripts/wasm/contracts/builder_unlock.wasm new file mode 100644 index 000000000..132fb49c1 Binary files /dev/null and b/scripts/wasm/contracts/builder_unlock.wasm differ diff --git a/scripts/wasm/contracts/old_astroport_assembly.wasm b/scripts/wasm/contracts/old_astroport_assembly.wasm new file mode 100644 index 000000000..1ab29a6a9 Binary files /dev/null and b/scripts/wasm/contracts/old_astroport_assembly.wasm differ diff --git a/scripts/wasm/contracts/old_astroport_builder_unlock.wasm b/scripts/wasm/contracts/old_astroport_builder_unlock.wasm new file mode 100644 index 000000000..f2a650b10 Binary files /dev/null and b/scripts/wasm/contracts/old_astroport_builder_unlock.wasm differ diff --git a/scripts/wasm/contracts/old_xastroc.wasm b/scripts/wasm/contracts/old_xastroc.wasm new file mode 100644 index 000000000..72a811133 Binary files /dev/null and b/scripts/wasm/contracts/old_xastroc.wasm differ diff --git a/scripts/wasm_command.txt b/scripts/wasm_command.txt index c28120d35..3dc14545c 100644 --- a/scripts/wasm_command.txt +++ b/scripts/wasm_command.txt @@ -2,5 +2,7 @@ ADDITIONAL_PRE_SCRIPTS=scripts/wasm/wasm-deploy.sh bash scripts/upgrade-test.sh ADDITIONAL_PRE_SCRIPTS=scripts/wasm/token-migration.sh ADDITIONAL_AFTER_SCRIPTS=scripts/wasm/token-migration-after.sh bash scripts/upgrade-test.sh ADDITIONAL_PRE_SCRIPTS=scripts/wasm/wasm-deploy.sh ADDITIONAL_AFTER_SCRIPTS=scripts/wasm/wasm-tx-check.sh bash scripts/upgrade-test.sh FORK=true ADDITIONAL_AFTER_SCRIPTS=scripts/wasm/stargate-after-upgrade.sh bash scripts/upgrade-test.sh +ADDITIONAL_PRE_SCRIPTS=scripts/wasm/astroport/assembly-deploy.sh bash scripts/upgrade-test.sh +ADDITIONAL_PRE_SCRIPTS=scripts/wasm/astroport/assembly-deploy.sh,scripts/wasm/astroport/test-interaction.sh ADDITIONAL_AFTER_SCRIPTS=scripts/wasm/astroport/test-interaction-after.sh bash scripts/upgrade-test.sh ./_build/new/terrad tx wasm execute terra18vd8fpwxzck93qlwghaj6arh4p7c5n896xzem5 '{"mint":{"token_id":"'4'","owner":"'terra1p20jxrllewr5meecvhtmpddexr0kkz3tdename'"}}' --from test0 --output json --gas auto --gas-adjustment 2.3 --fees 20000000uluna --chain-id test --home mytestnet --keyring-backend test -y ./_build/new/terrad q wasm contract-state smart terra18vd8fpwxzck93qlwghaj6arh4p7c5n896xzem5 '{"all_tokens":{}}' --chain-id test --home mytestnet \ No newline at end of file