Skip to content

Commit

Permalink
chore(scripts): use wait-tx utility instead of shell sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasvdam committed Jan 20, 2025
1 parent 390e6a0 commit fed7886
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions scripts/deploy_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ RPC_URL=http://127.0.0.1:26657
BIN=$(git rev-parse --show-toplevel)/build/sedad
CONTRACT_WASM=$(git rev-parse --show-toplevel)/testutil/testwasms/seda_contract.wasm
VOTING_PERIOD=30 # seconds
DEV_ACCOUNT=$($BIN keys show satoshi --keyring-backend test -a) # for sending wasm-storage txs
DEV_ACCOUNT=$($BIN keys show thomas --keyring-backend test -a) # for sending wasm-storage txs
VOTE_ACCOUNT=$($BIN keys show satoshi --keyring-backend test -a) # for sending vote txs


echo "Deploying core contract"

OUTPUT="$($BIN tx wasm store $CONTRACT_WASM --node $RPC_URL --from $DEV_ACCOUNT --keyring-backend test --gas-prices 100000000000aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)"
TXHASH=$(echo $OUTPUT | jq -r '.txhash')

sleep 10
OUTPUT="$(
$BIN tx wasm store $CONTRACT_WASM \
--node $RPC_URL \
--chain-id $CHAIN_ID \
--from $DEV_ACCOUNT \
--keyring-backend test \
--gas-prices 100000000000aseda \
--gas auto \
--gas-adjustment 1.3 \
-y --output json \
| $BIN query wait-tx --node $RPC_URL --output json\
)"

OUTPUT="$($BIN query tx $TXHASH --node $RPC_URL --output json)"
CORE_CODE_ID=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')

echo "Instantiating core contract on code id $CORE_CODE_ID"
Expand All @@ -29,19 +36,28 @@ OUTPUT=$($BIN tx wasm-storage submit-proposal instantiate-core-contract $CORE_CO
--admin $DEV_ACCOUNT \
--label core$CORE_CODE_ID \
--title 'Core Contract' --summary 'Instantiates and registers core contract' --deposit 10000000aseda \
--from $DEV_ACCOUNT --keyring-backend test \
--node $RPC_URL \
--gas-prices 100000000000aseda --gas auto --gas-adjustment 1.5 \
--output json --chain-id $CHAIN_ID -y)
TXHASH=$(echo "$OUTPUT" | jq -r '.txhash')
--chain-id $CHAIN_ID \
--from $DEV_ACCOUNT \
--keyring-backend test \
--gas-prices 100000000000aseda \
--gas auto \
--gas-adjustment 1.5 \
-y --output json \
| $BIN query wait-tx --node $RPC_URL --output json\
)

sleep 10

PROPOSAL_ID="$($BIN query tx $TXHASH --output json | jq '.events[] | select(.type == "submit_proposal") | .attributes[] | select(.key == "proposal_id") | .value' | sed 's/^"\(.*\)"$/\1/')"
PROPOSAL_ID="$(echo "$OUTPUT" | jq '.events[] | select(.type == "submit_proposal") | .attributes[] | select(.key == "proposal_id") | .value' | sed 's/^"\(.*\)"$/\1/')"
$BIN tx gov vote $PROPOSAL_ID yes \
--from $VOTE_ACCOUNT --keyring-backend test \
--gas-prices 100000000000aseda --gas auto --gas-adjustment 1.6 \
--chain-id $CHAIN_ID -y
--node $RPC_URL \
--chain-id $CHAIN_ID \
--from $VOTE_ACCOUNT \
--keyring-backend test \
--gas-prices 100000000000aseda \
--gas auto \
--gas-adjustment 1.6 \
-y \
| $BIN query wait-tx --node $RPC_URL --output json

sleep $VOTING_PERIOD

Expand Down

0 comments on commit fed7886

Please sign in to comment.