Skip to content

Commit

Permalink
Show helpful errors when deployment fails
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadalm committed Jul 28, 2023
1 parent 4e65689 commit 8556be8
Showing 1 changed file with 50 additions and 35 deletions.
85 changes: 50 additions & 35 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ shopt -s inherit_errexit

ADMIN="${1:-juno1zk4c4aamef42cgjexlmksypac8j5xw7n3s4wrd}"
KOMPLE_MINT_ADDR="${KOMPLE_MINT_ADDR:-juno17rth4jstxs7cmrusvyluwlnt34l80cxaz7nufpjfntts00pk79asjxelgs}"
NOIS_PROXY="${NOIS_PROXY:-juno17xgzprnr0j4cs72t7xfsr2lsmw8guwj640tr8e96nld524f0gmhq0hewqc}"

JUNOFARMS_PATH='../junofarms'

Expand All @@ -14,6 +15,21 @@ function update_contract_address {
sed -i "s/\(VITE_CONTRACT_ADDRESS=\).*/\1${new_address}/g" "${JUNOFARMS_PATH}/package/ui/.env"
}

function assert_response_success {
local response="${1}"
local msg="${2}"

local code
code="$(echo "${response}" | jq -r '.code')"
if [[ "${code}" -ne 0 ]]; then
echo "[ERROR] ${msg}:" >&2
echo "${response}" >&2
return 1
fi

return 0
}

function compile {
docker run --rm -v "$(pwd)":/code:Z \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
Expand All @@ -24,22 +40,19 @@ function compile {
function upload_code {
local response
response="$(junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 tx wasm store artifacts/juno_farm_hackathon_template.wasm --from "${ADMIN}" --gas-prices 0.075ujunox --gas auto --gas-adjustment 1.1 -o json -y)"
assert_response_success "${response}" "Uploading code failed"

local code
code="$(echo "${response}" | jq -r '.code')"
if [[ "${code}" -ne 0 ]]; then
echo "[ERROR] Uploading code failed:" >&2
echo "${response}" >&2
return 1
fi

echo "[DEBUG] Code uploaded: ${response}" >&2

local tx_hash
tx_hash="$(echo "${response}" | jq -r '.txhash')"

sleep 10
junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 query tx "${tx_hash}" -o json | jq '.logs[0].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value' -r
response="$(junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 query tx "${tx_hash}" -o json)"
assert_response_success "${response}" "Uploading code failed"

echo "${response}" | jq '.logs[0].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value' -r
}

function upload_noise_code {
Expand All @@ -55,51 +68,57 @@ function upload_noise_code {
--gas-prices 0.025ujunox \
--broadcast-mode=async \
--node=https://juno-testnet-rpc.polkachu.com:443 -o json -y)"
assert_response_success "${response}" "Uploading noise code failed"

local code
code="$(echo "${response}" | jq -r '.code')"
if [[ "${code}" -ne 0 ]]; then
echo "[ERROR] Uploading noise code failed:" >&2
echo "${response}" >&2
return 1
fi

echo "[DEBUG] Noise code uploaded: ${response}" >&2

local tx_hash
tx_hash="$(echo "${response}" | jq -r '.txhash')"

sleep 10
junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 query tx "${tx_hash}" -o json | jq '.logs[0].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value' -r
response="$(junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 query tx "${tx_hash}" -o json)"
assert_response_success "${response}" "Uploading noise code failed"

echo "${response}" | jq '.logs[0].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value' -r
}

function instantiate {
local code_id="${1}"

local instantiate_msg
instantiate_msg=$(cat <<-END
local msg
msg=$(cat <<END
{
"admin": "%s",
"komple_mint_addr": "%s"
"admin": "${ADMIN}",
"komple_mint_addr": "${KOMPLE_MINT_ADDR}"
}
END
)

local msg
msg="$(printf "${instantiate_msg}" "$ADMIN" "${KOMPLE_MINT_ADDR}")"
echo "[DEBUG] Instantiating with: ${msg}" >&2

local response
response=$(junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 tx wasm instantiate "${code_id}" "${msg}" --from "${ADMIN}" --admin "${ADMIN}" --gas-prices 0.075ujunox --gas auto --gas-adjustment 1.1 --label " " -o json -y)
assert_response_success "${response}" "Instantiating failed"

local tx_hash
tx_hash=$(junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 tx wasm instantiate "${code_id}" "${msg}" --from "${ADMIN}" --admin "${ADMIN}" --gas-prices 0.075ujunox --gas auto --gas-adjustment 1.1 --label " " -o json -y | jq '.txhash' -r)
tx_hash="$(echo "${response}" | jq -r '.txhash')"

sleep 10
response="$(junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 query tx "${tx_hash}" -o json)"
assert_response_success "${response}" "Instantiating failed"

junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 query tx "${tx_hash}" -o json | jq 'last(.logs[0].events[] | .attributes[] | select(.key=="_contract_address") | .value)' -r
echo "${response}" | jq 'last(.logs[0].events[] | .attributes[] | select(.key=="_contract_address") | .value)' -r
}

function migrate {
local code_id="${1}"
local contract_addr="${2}"

tx_hash=$(junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 --from "${ADMIN}" tx wasm migrate "${contract_addr}" "${code_id}" '{}' --gas-prices 0.075ujunox --gas auto --gas-adjustment 1.2 -o json -y | jq '.txhash' -r )
local response
response="$(junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 --from "${ADMIN}" tx wasm migrate "${contract_addr}" "${code_id}" '{}' --gas-prices 0.075ujunox --gas auto --gas-adjustment 1.2 -o json -y)"
assert_response_success "${response}" "Migration failed"

tx_hash=$(echo "${response}" | jq '.txhash' -r )
echo "Migration TX hash: ${tx_hash}"
}

Expand Down Expand Up @@ -139,22 +158,18 @@ EOF
--gas-prices 0.025ujunox \
--broadcast-mode=sync \
--node=https://juno-testnet-rpc.polkachu.com:443 -o json -y)"

local code
code="$(echo "${response}" | jq -r '.code')"
if [[ "${code}" -ne 0 ]]; then
echo "[ERROR] Instantiating noise failed:" >&2
echo "${response}" >&2
return 1
fi
assert_response_success "${response}" "Instantiating noise failed"

echo "[DEBUG] Noise code instantiated: ${response}" >&2

local tx_hash
tx_hash="$(echo "${response}" | jq -r '.txhash')"

sleep 10
junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 query tx "${tx_hash}" -o json | jq | jq '.logs[0].events[]|select(.type=="wasm").attributes[]|select(.key=="_contract_address").value' -r
response="$(junod --chain-id uni-6 --node https://juno-testnet-rpc.polkachu.com:443 query tx "${tx_hash}" -o json)"
assert_response_success "${response}" "Instantiating noise failed"

echo "${response}" | jq '.logs[0].events[]|select(.type=="wasm").attributes[]|select(.key=="_contract_address").value' -r
}

function deploy_new {
Expand Down

0 comments on commit 8556be8

Please sign in to comment.