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 astroport assembly contracts migration #313

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Vagrantfile

bin/
coverage.txt
scripts/
2 changes: 1 addition & 1 deletion scripts/upgrade-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
211 changes: 211 additions & 0 deletions scripts/wasm/astroport/assembly-deploy.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions scripts/wasm/astroport/test-interaction-after.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

BINARY=_build/new/terrad bash scripts/wasm/astroport/test-interaction.sh
150 changes: 150 additions & 0 deletions scripts/wasm/astroport/test-interaction.sh
Original file line number Diff line number Diff line change
@@ -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
Binary file added scripts/wasm/contracts/astro_assembly.wasm
Binary file not shown.
Binary file added scripts/wasm/contracts/builder_unlock.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added scripts/wasm/contracts/old_xastroc.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions scripts/wasm_command.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading