github.com/Finschia/finschia-proxy/v2@v2.0.1/ci_test/queue_ci.sh (about) 1 #!/bin/bash 2 3 FROM_ACCOUNT='alice' 4 TOKEN_NAME='ST1' 5 6 FNSAD=${FNSAD:-fnsad-proxy} 7 CHAIN_DIR=${CHAIN_DIR:-~/.fnsap} 8 if [[ $# -gt 0 ]]; then 9 CHAIN_DIR=$1 10 fi 11 12 # This is a function that checks if executeMsg/quertMsg is successful. 13 check_run_info() { 14 local result="$1" 15 local msg="$2" 16 if [[ "$result" == *"failed"* ]]; then 17 echo -e "$msg\n$result" 18 exit 1 19 fi 20 } 21 22 # This is a function that checks if the result is as expected. 23 check_result() { 24 local result="$1" 25 local expected_result="$2" 26 if [[ "$result" != "$expected_result" ]]; then 27 echo -e "expected result is:\n$expected_result" 28 echo -e "query result is:\n$result" 29 exit 1 30 fi 31 } 32 33 # This is a function to execute and check a query message. 34 execute_and_check_query_msg() { 35 local query_msg="$1" 36 local expected_result="$2" 37 query_result=$(${FNSAD} query wasm contract-state smart "$CONTRACT_ADDRESS" "$query_msg") 38 check_run_info "$query_result" "$query_msg" 39 check_result "$query_result" "$expected_result" 40 } 41 42 # store `queue.wasm` 43 STORE_RES=$(${FNSAD} tx wasm store contracts/queue.wasm --from $FROM_ACCOUNT --home ${CHAIN_DIR} --keyring-backend test --chain-id finschia --gas 1500000 -b block -o json -y) 44 CODE_ID=$(echo "$STORE_RES" | jq '.logs[] | select(.msg_index == 0) | .events[] | select(.type == "store_code") | .attributes[] | select(.key == "code_id") | .value | tonumber') 45 46 # instantiate `queue.wasm` 47 INIT_MSG=$(jq -nc '{}') 48 INSTANTIATE_RES=$(${FNSAD} tx wasm instantiate "$CODE_ID" "$INIT_MSG" --label $TOKEN_NAME --admin "$(${FNSAD} keys show $FROM_ACCOUNT -a --home ${CHAIN_DIR} --keyring-backend test)" --from $FROM_ACCOUNT --home ${CHAIN_DIR} --keyring-backend test --chain-id finschia -b block -o json -y) 49 CONTRACT_ADDRESS=$(echo "$INSTANTIATE_RES" | jq '.logs[] | select(.msg_index == 0) | .events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address") | .value' | sed 's/"//g') 50 51 # check enqueue 52 # now: {100, 200, 300} 53 for value in 100 200 300; do 54 ENQUEUE_MSG=$(jq -nc --arg value $value '{enqueue:{value:($value | tonumber)}}') 55 RUN_INFO=$(${FNSAD} tx wasm execute "$CONTRACT_ADDRESS" "$ENQUEUE_MSG" --from $FROM_ACCOUNT --home ${CHAIN_DIR} --keyring-backend test --chain-id finschia -b block -y) 56 check_run_info "$RUN_INFO" "$ENQUEUE_MSG" 57 done 58 59 # check count 60 EXPECTED_RESULT='data: 61 count: 3' 62 COUNT_MSG=$(jq -nc '{count:{}}') 63 execute_and_check_query_msg "$COUNT_MSG" "$EXPECTED_RESULT" 64 65 # check dequeue 66 # now: {200, 300} 67 DEQUEUE_MSG=$(jq -nc '{dequeue:{}}') 68 RUN_INFO=$(${FNSAD} tx wasm execute "$CONTRACT_ADDRESS" "$DEQUEUE_MSG" --from $FROM_ACCOUNT --home=${CHAIN_DIR} --keyring-backend test --chain-id finschia -b block -y) 69 check_run_info "$RUN_INFO" "$ENQUEUE_MSG" 70 71 # check sum 72 EXPECTED_RESULT='data: 73 sum: 500' 74 SUM_MSG=$(jq -nc '{sum:{}}') 75 execute_and_check_query_msg "$SUM_MSG" "$EXPECTED_RESULT" 76 77 # check reducer 78 EXPECTED_RESULT='data: 79 counters: 80 - - 200 81 - 300 82 - - 300 83 - 0' 84 REDUCER_MSG=$(jq -nc '{reducer:{}}') 85 execute_and_check_query_msg "$REDUCER_MSG" "$EXPECTED_RESULT" 86 87 # check list 88 EXPECTED_RESULT='data: 89 early: 90 - 1 91 - 2 92 empty: [] 93 late: []' 94 LIST_MSG=$(jq -nc '{list:{}}') 95 execute_and_check_query_msg "$LIST_MSG" "$EXPECTED_RESULT" 96 97 # check open_iterators 98 EXPECTED_RESULT='data: {}' 99 OPENITERATORS_MSG=$(jq -nc '{open_iterators:{count:3}}') 100 execute_and_check_query_msg "$OPENITERATORS_MSG" "$EXPECTED_RESULT"