Commit 94b4b613 authored by harrylee's avatar harrylee Committed by vipwzw

remove test-rpc.sh

parent 7fe676d8
#!/usr/bin/env bash
# shellcheck disable=SC2128
set -e
set -o pipefail
MAIN_HTTP=""
TxHash=""
PASSWD="ABCD"
HASH_VALUE=$(echo -n "ABCD1" | sha256sum | awk '{print $1}')
CONENT=(1,2,3,4,5,6)
EXECTOR=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh
function chain33_GetExecAddr() {
#获取合约地址
local exector=$1
local req='"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'"${exector}"'"}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
# GAME_ADDR=$(echo "${res}" | jq -r ".result")
echo_rst "$FUNCNAME" "$?"
}
function CreateContentStorageTx() {
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"ContentStorage", "payload":{"content": '"${CONENT}"'}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CreateGame createRawTx" 1
fi
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
TxHash=$RAW_TX_HASH
echo_rst "CreateTransaction query_tx" "$?"
}
function QueryStorage() {
local status=$1
local req='"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameListByStatusAndAddr","payload":{"status":'"${status}"',"address":""}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
GAMES=$(echo "${resp}" | jq -r ".result.games")
echo "${GAMES}"
echo_rst "$FUNCNAME" "$?"
}
function QueryGameByGameId() {
local gameId=$1
local status=$2
local req='"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameById","payload":{"gameId":"'"${gameId}"'"}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
STATUS=$(echo "${resp}" | jq -r ".result.game.status")
if [ "${STATUS}" -ne "${status}" ]; then
echo "status is not equal"
echo_rst "QueryGameByGameId" 1
return 0
fi
echo_rst "QueryGameByGameId" 0
}
function init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara"
local game_addr=""
if [ "$ispara" == "true" ]; then
EXECTOR="user.p.para.storage"
game_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.storage"}]}' ${MAIN_HTTP} | jq -r ".result")
else
EXECTOR="storage"
game_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"storage"}]}' ${MAIN_HTTP} | jq -r ".result")
fi
echo "gameAddr=${game_addr}"
local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f
chain33_ImportPrivkey "0xfa21dc33a6144c546537580d28d894355d1e9af7292be175808b0f5737c30849" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "${main_ip}"
#16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc
chain33_ImportPrivkey "0x213286d352b01fd740b6eaeb78a4fd316d743dd51d2f12c6789977430a41e0c7" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$main_ip"
local ACCOUNT_A="16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f"
local ACCOUNT_B="16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc"
if [ "$ispara" == false ]; then
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
chain33_applyCoins "$ACCOUNT_B" 12000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_B}" "$main_ip"
else
# tx fee
chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
chain33_applyCoins "$ACCOUNT_B" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_B}" "$main_ip"
local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0xfa21dc33a6144c546537580d28d894355d1e9af7292be175808b0f5737c30849" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "$para_ip"
chain33_ImportPrivkey "0x213286d352b01fd740b6eaeb78a4fd316d743dd51d2f12c6789977430a41e0c7" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$para_ip"
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$para_ip"
chain33_applyCoins "$ACCOUNT_B" 12000000000 "${para_ip}"
chain33_QueryBalance "${ACCOUNT_B}" "$para_ip"
fi
chain33_SendToAddress "${ACCOUNT_B}" "$game_addr" 5000000000 "${MAIN_HTTP}"
chain33_QueryExecBalance "${ACCOUNT_B}" "game" "$MAIN_HTTP"
chain33_SendToAddress "${ACCOUNT_A}" "$game_addr" 5000000000 "${MAIN_HTTP}"
chain33_QueryExecBalance "${ACCOUNT_A}" "game" "$MAIN_HTTP"
chain33_BlockWait 1 "$MAIN_HTTP"
}
function run_test() {
local ip=$1
CreateGameTx 1000000000 "${HASH_VALUE}"
QueryGameByGameId "${GAME_ID}" 1
QueryGameByStatus 1
MatchGameTx "${GAME_ID}"
QueryGameByGameId "${GAME_ID}" 2
QueryGameByStatus 2
CloseGameTx "${GAME_ID}" "${PASSWD}"
QueryGameByGameId "${GAME_ID}" 4
QueryGameByStatus 4
CreateGameTx 500000000 "${HASH_VALUE}"
QueryGameByGameId "${GAME_ID}" 1
CancleGameTx "${GAME_ID}"
QueryGameByGameId "${GAME_ID}" 3
QueryGameByStatus 3
}
function main() {
local ip=$1
MAIN_HTTP=$ip
chain33_RpcTestBegin game
echo "main_ip=$MAIN_HTTP"
init
run_test "$MAIN_HTTP"
chain33_RpcTestRst game "$CASE_ERR"
}
chain33_debug_function main "$1"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment