Unverified Commit 06236086 authored by vipwzw's avatar vipwzw Committed by GitHub

Merge pull request #738 from YingQm/issue691_rpc_test_improve

rpc test 脚本改进
parents 88e98f0f 05ee2aa2
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
RAW_TX_HASH="" RAW_TX_HASH=""
LAST_BLOCK_HASH="" LAST_BLOCK_HASH=""
CASE_ERR="" CASE_ERR=""
RETURN_RESP=""
#color #color
RED='\033[1;31m' RED='\033[1;31m'
...@@ -16,11 +17,32 @@ echo_rst() { ...@@ -16,11 +17,32 @@ echo_rst() {
echo -e "${GRE}$1 not support${NOC}" echo -e "${GRE}$1 not support${NOC}"
else else
echo -e "${RED}$1 fail${NOC}" echo -e "${RED}$1 fail${NOC}"
echo -e "${RED}$3 ${NOC}"
CASE_ERR="err" CASE_ERR="err"
echo $CASE_ERR echo $CASE_ERR
fi fi
} }
chain33_Http() {
# echo "#$4 request: request="$1" MAIN_HTTP="$2" js="$3" FUNCNAME="$4" response="$5""
local body
body=$(curl -ksd "$1" "$2")
RETURN_RESP=$(echo "$body" | jq -r "$5")
echo "#response: $body" "$RETURN_RESP"
ok=$(echo "$body" | jq -r "$3")
[ "$ok" == true ]
rst=$?
echo_rst "$4" "$rst" "$body"
}
chain33_SignAndSendTxWait() {
# txHex="$1" priKey="$2" MAIN_HTTP="$3" FUNCNAME="$4"
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$1"'"}]}'
chain33_Http "$req" "$3" '(.result.txs[0].execer != "") and (.result.txs[0].execer != null)' "$4"
chain33_SignAndSendTx "$1" "$2" "$3"
chain33_BlockWait 1 "$3"
}
chain33_BlockWait() { chain33_BlockWait() {
local MAIN_HTTP=$2 local MAIN_HTTP=$2
local req='"method":"Chain33.GetLastHeader","params":[]' local req='"method":"Chain33.GetLastHeader","params":[]'
...@@ -112,7 +134,7 @@ chain33_ImportPrivkey() { ...@@ -112,7 +134,7 @@ chain33_ImportPrivkey() {
[ "$ok" == true ] [ "$ok" == true ]
} }
chain33_SignRawTx() { chain33_SignAndSendTx() {
local txHex="$1" local txHex="$1"
local priKey="$2" local priKey="$2"
local MAIN_HTTP=$3 local MAIN_HTTP=$3
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
#txhash=""
function run_testcases() { function run_testcases() {
echo "run_testcases" echo "run_testcases"
} }
function debug_function() {
set -x
eval "$@"
set +x
}
function rpc_test() { function rpc_test() {
chain33_RpcTestBegin autonomy chain33_RpcTestBegin autonomy
...@@ -30,4 +22,4 @@ function rpc_test() { ...@@ -30,4 +22,4 @@ function rpc_test() {
} }
debug_function rpc_test "$1" chain33_debug_function rpc_test "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set +e set +e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
gID="" gID=""
...@@ -31,49 +30,35 @@ init() { ...@@ -31,49 +30,35 @@ init() {
chain33_NewAccount() { chain33_NewAccount() {
label=$1 label=$1
result=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.NewAccount","params":[{"label":"'"$label"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.acc.addr") req='{"method":"Chain33.NewAccount","params":[{"label":"'"$label"'"}]}'
[ "$result" != "" ] chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.acc.addr|length > 0)' "$FUNCNAME" ".result.acc.addr"
rst=$? glAddr=$RETURN_RESP
echo_rst "$FUNCNAME" "$rst"
glAddr=$result
echo "$glAddr"
} }
chain33_SendTransaction() { chain33_SendTransaction() {
rawTx=$1 rawTx=$1
addr=$2 addr=$2
#签名交易 #签名交易
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.SignRawTx","params":[{"addr":"'"$addr"'","txHex":"'"$rawTx"'","expire":"120s","fee":10000000,"index":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"Chain33.SignRawTx","params":[{"addr":"'"$addr"'","txHex":"'"$rawTx"'","expire":"120s","fee":10000000,"index":0}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "Chain33.SignRawTx" ".result"
[ "$ok" == null ] signTx=$RETURN_RESP
rst=$?
echo_rst "$FUNCNAME" "$rst" req='{"method":"Chain33.SendTransaction","params":[{"data":"'"$signTx"'"}]}'
chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
signTx=$(echo "${resp}" | jq -r ".result")
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.SendTransaction","params":[{"data":"'"$signTx"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) gResp=$RETURN_RESP
ok=$(echo "${resp}" | jq -r ".error")
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#返回交易 #返回交易
gResp=$(jq -r ".result" <<<"$resp") chain33_QueryTx "$RETURN_RESP" "${MAIN_HTTP}"
echo "tx hash is $gResp"
chain33_QueryTx "$gResp" "${MAIN_HTTP}"
} }
blackwhite_BlackwhiteCreateTx() { blackwhite_BlackwhiteCreateTx() {
#创建交易 #创建交易
addr=$1 addr=$1
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"blackwhite.BlackwhiteCreateTx","params":[{"PlayAmount":100000000,"PlayerCount":3,"GameName":"hello","Timeout":600,"Fee":1000000}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"blackwhite.BlackwhiteCreateTx","params":[{"PlayAmount":100000000,"PlayerCount":3,"GameName":"hello","Timeout":600,"Fee":1000000}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") chain33_SendTransaction "$RETURN_RESP" "${addr}"
chain33_SendTransaction "${rawTx}" "${addr}"
gID="${gResp}" gID="${gResp}"
echo "gameID $gID"
} }
blackwhite_BlackwhitePlayTx() { blackwhite_BlackwhitePlayTx() {
...@@ -81,83 +66,54 @@ blackwhite_BlackwhitePlayTx() { ...@@ -81,83 +66,54 @@ blackwhite_BlackwhitePlayTx() {
round1=$2 round1=$2
round2=$3 round2=$3
round3=$4 round3=$4
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"blackwhite.BlackwhitePlayTx","params":[{"gameID":"'"$gID"'","amount":100000000,"Fee":1000000,"hashValues":["'"$round1"'","'"$round2"'","'"$round3"'"]}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"blackwhite.BlackwhitePlayTx","params":[{"gameID":"'"$gID"'","amount":100000000,"Fee":1000000,"hashValues":["'"$round1"'","'"$round2"'","'"$round3"'"]}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") chain33_SendTransaction "$RETURN_RESP" "${addr}"
chain33_SendTransaction "${rawTx}" "${addr}"
} }
blackwhite_BlackwhiteShowTx() { blackwhite_BlackwhiteShowTx() {
addr=$1 addr=$1
sec=$2 sec=$2
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"blackwhite.BlackwhiteShowTx","params":[{"gameID":"'"$gID"'","secret":"'"$sec"'","Fee":1000000}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"blackwhite.BlackwhiteShowTx","params":[{"gameID":"'"$gID"'","secret":"'"$sec"'","Fee":1000000}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
[ "$ok" == null ] chain33_SendTransaction "$RETURN_RESP" "${addr}"
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${addr}"
} }
blackwhite_BlackwhiteTimeoutDoneTx() { blackwhite_BlackwhiteTimeoutDoneTx() {
gameID=$1 gameID=$1
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"blackwhite.BlackwhiteTimeoutDoneTx","params":[{"gameID":"'"$gameID"'","Fee":1000000}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"blackwhite.BlackwhiteTimeoutDoneTx","params":[{"gameID":"'"$gameID"'","Fee":1000000}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME"
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
blackwhite_GetBlackwhiteRoundInfo() { blackwhite_GetBlackwhiteRoundInfo() {
gameID=$1 gameID=$1
execer="blackwhite" req='{"method":"Chain33.Query","params":[{"execer":"blackwhite","funcName":"GetBlackwhiteRoundInfo","payload":{"gameID":"'"$gameID"'"}}]}'
funcName="GetBlackwhiteRoundInfo" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.round | [has("gameID", "status", "playAmount", "playerCount", "curPlayerCount", "loop", "curShowCount", "timeout"),true] | unique | length == 1)' "$FUNCNAME"
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"gameID":"'"$gameID"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.round | [has("gameID", "status", "playAmount", "playerCount", "curPlayerCount", "loop", "curShowCount", "timeout"),true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
blackwhite_GetBlackwhiteByStatusAndAddr() { blackwhite_GetBlackwhiteByStatusAndAddr() {
gameID=$1 addr=$1
addr=$2 req='{"method":"Chain33.Query","params":[{"execer":"blackwhite","funcName":"GetBlackwhiteByStatusAndAddr","payload":{"status":5,"address":"'"$addr"'","count":1,"direction":0,"index":-1}}]}'
execer="blackwhite" resok='(.error|not) and (.result.round[0].createAddr == "'"$addr"'") and (.result.round[0].status == 5) and (.result.round[0] | [has("gameID", "status", "playAmount", "playerCount", "curPlayerCount", "loop", "curShowCount", "timeout", "winner"),true] | unique | length == 1)'
funcName="GetBlackwhiteByStatusAndAddr" chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"status":5,"address":"'"$addr"'","count":1,"direction":0,"index":-1}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.round[0].createAddr == "'"$addr"'") and (.result.round[0].status == 5) and (.result.round[0] | [has("gameID", "status", "playAmount", "playerCount", "curPlayerCount", "loop", "curShowCount", "timeout", "winner"),true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
blackwhite_GetBlackwhiteloopResult() { blackwhite_GetBlackwhiteloopResult() {
gameID=$1 gameID=$1
execer="blackwhite" req='{"method":"Chain33.Query","params":[{"execer":"blackwhite","funcName":"GetBlackwhiteloopResult","payload":{"gameID":"'"$gameID"'","loopSeq":0}}]}'
funcName="GetBlackwhiteloopResult" resok='(.error|not) and (.result.gameID == "'"$gameID"'") and (.result.results|length >= 1)'
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"gameID":"'"$gameID"'","loopSeq":0}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.gameID == "'"$gameID"'") and (.result.results|length >= 1)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function run_testcases() { function run_testcases() {
#密钥 #密钥
sect1="123" sect1="123"
#结果base64.StdEncoding.EncodeToString(common.Sha256([]byte("0"+secret+black)))
# black == "1" white := "0"
#black0="O3LD8NyaeeSCc8xDfvBoacTrQlrY91FHT9ceEOXgs18="
black1="6vm6gJ2wvEIxC8Yc6r/N6lIU5OZk633YMnIfwcZBD0o=" black1="6vm6gJ2wvEIxC8Yc6r/N6lIU5OZk633YMnIfwcZBD0o="
black2="6FXx5aeDSCaq1UrhLO8u0H31Hl8TpvzxuHrgGo9WeFk=" black2="6FXx5aeDSCaq1UrhLO8u0H31Hl8TpvzxuHrgGo9WeFk="
white0="DrNPzA68XiGimZE/igx70kTPJxnIJnVf8NCGnb7XoYU=" white0="DrNPzA68XiGimZE/igx70kTPJxnIJnVf8NCGnb7XoYU="
white1="SB5Pnf6Umf2Wba0dqyNOezq5FEqTd22WPVYAhSA6Lxs=" white1="SB5Pnf6Umf2Wba0dqyNOezq5FEqTd22WPVYAhSA6Lxs="
#white2="OiexKDzIlS1CKr3KBNWEY1k5uXzDI/ou6Dd+x0ByQCM="
#先创建账户地址 #先创建账户地址
chain33_NewAccount "label188" chain33_NewAccount "label188"
...@@ -201,9 +157,8 @@ function run_testcases() { ...@@ -201,9 +157,8 @@ function run_testcases() {
blackwhite_BlackwhiteTimeoutDoneTx "$gID" blackwhite_BlackwhiteTimeoutDoneTx "$gID"
#查询部分 #查询部分
blackwhite_GetBlackwhiteRoundInfo "$gID" blackwhite_GetBlackwhiteRoundInfo "$gID"
blackwhite_GetBlackwhiteByStatusAndAddr "$gID" "${gameAddr1}" blackwhite_GetBlackwhiteByStatusAndAddr "${gameAddr1}"
blackwhite_GetBlackwhiteloopResult "$gID" blackwhite_GetBlackwhiteloopResult "$gID"
} }
function main() { function main() {
...@@ -212,17 +167,8 @@ function main() { ...@@ -212,17 +167,8 @@ function main() {
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_testcases run_testcases
chain33_RpcTestRst blackwhite "$CASE_ERR" chain33_RpcTestRst blackwhite "$CASE_ERR"
}
function debug_function() {
set -x
eval "$@"
set +x
} }
debug_function main "$1" chain33_debug_function main "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
#eventId=""
#txhash=""
init() { init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")') ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
...@@ -30,8 +25,7 @@ function main() { ...@@ -30,8 +25,7 @@ function main() {
init init
run_test run_test
chain33_RpcTestRst dposvote "$CASE_ERR" chain33_RpcTestRst dposvote "$CASE_ERR"
} }
main "$1" chain33_debug_function main "$1"
This diff is collapsed.
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
set -e # shellcheck source=/dev/null
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
...@@ -8,36 +8,24 @@ GAME_ID="" ...@@ -8,36 +8,24 @@ GAME_ID=""
PASSWD="ABCD" PASSWD="ABCD"
HASH_VALUE=$(echo -n "ABCD1" | sha256sum | awk '{print $1}') HASH_VALUE=$(echo -n "ABCD1" | sha256sum | awk '{print $1}')
EXECTOR="" PRIVA_A="0xfa21dc33a6144c546537580d28d894355d1e9af7292be175808b0f5737c30849"
PRIVA_B="0x213286d352b01fd740b6eaeb78a4fd316d743dd51d2f12c6789977430a41e0c7"
# shellcheck source=/dev/null EXECTOR=""
source ../dapp-test-common.sh source ../dapp-test-common.sh
function chain33_GetExecAddr() { function chain33_GetExecAddr() {
#获取GAME合约地址 #获取GAME合约地址
local exector=$1 req='{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'"$1"'"}]}'
local req='"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'"${exector}"'"}]' chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
# GAME_ADDR=$(echo "${res}" | jq -r ".result")
echo_rst "$FUNCNAME" "$?"
} }
function CreateGameTx() { function CreateGameTx() {
local amount=$1 local amount=$1
local hash_value=$2 local hash_value=$2
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"createGame", "payload":{"amount": '"${amount}"',"hashType":"sha256","hashValue":"'"${hash_value}"'"}}]' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"createGame", "payload":{"amount": '"${amount}"',"hashType":"sha256","hashValue":"'"${hash_value}"'"}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${PRIVA_A}" "${MAIN_HTTP}"
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}"
GAME_ID=$RAW_TX_HASH GAME_ID=$RAW_TX_HASH
echo_rst "CreateGame query_tx" "$?" echo_rst "CreateGame query_tx" "$?"
...@@ -45,81 +33,43 @@ function CreateGameTx() { ...@@ -45,81 +33,43 @@ function CreateGameTx() {
function MatchGameTx() { function MatchGameTx() {
local gameId=$1 local gameId=$1
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"matchGame", "payload":{"gameId": "'"${gameId}"'","guess":2}}]' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"matchGame", "payload":{"gameId": "'"${gameId}"'","guess":2}}]}'
chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "MatchGame createRawTx" ".result"
echo "#request: $req" chain33_SignAndSendTx "${RETURN_RESP}" "${PRIVA_B}" "${MAIN_HTTP}"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "MatchGame createRawTx" 1
fi
chain33_SignRawTx "${rawTx}" "${PRIVA_B}" "${MAIN_HTTP}"
echo_rst "MatchGame query_tx" "$?" echo_rst "MatchGame query_tx" "$?"
} }
function CloseGameTx() { function CloseGameTx() {
local gameId=$1 local gameId=$1
local secret=$2 local secret=$2
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"closeGame", "payload":{"gameId": "'"${gameId}"'","secret":"'"${secret}"'","result":1}}]' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"closeGame", "payload":{"gameId": "'"${gameId}"'","secret":"'"${secret}"'","result":1}}]}'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CloseGame createRawTx" 1
fi
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "CloseGame createRawTx" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${PRIVA_A}" "${MAIN_HTTP}"
echo_rst "CloseGame query_tx" "$?" echo_rst "CloseGame query_tx" "$?"
} }
function CancleGameTx() { function CancleGameTx() {
local gameId=$1 local gameId=$1
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"cancelGame", "payload":{"gameId": "'"${gameId}"'"}}]' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"cancelGame", "payload":{"gameId": "'"${gameId}"'"}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "CancleGame createRawTx" ".result"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_SignAndSendTx "${RETURN_RESP}" "${PRIVA_A}" "${MAIN_HTTP}"
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CancleGame createRawTx" 1
fi
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
echo_rst "CancleGame query_tx" "$?" echo_rst "CancleGame query_tx" "$?"
} }
function QueryGameByStatus() { function QueryGameByStatus() {
local status=$1 local status=$1
local req='"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameListByStatusAndAddr","payload":{"status":'"${status}"',"address":""}}]' local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameListByStatusAndAddr","payload":{"status":'"${status}"',"address":""}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result.games"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
GAMES=$(echo "${resp}" | jq -r ".result.games")
echo "${GAMES}"
echo_rst "$FUNCNAME" "$?"
} }
function QueryGameByGameId() { function QueryGameByGameId() {
local gameId=$1 local gameId=$1
local status=$2 local status=$2
local req='"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameById","payload":{"gameId":"'"${gameId}"'"}}]' local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameById","payload":{"gameId":"'"${gameId}"'"}}]}'
echo "#request: $req" resok='(.error|not) and (.result.game.status = "'"${status}"'")'
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
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() { function init() {
...@@ -138,10 +88,8 @@ function init() { ...@@ -138,10 +88,8 @@ function init() {
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key #main chain import pri key
#16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f chain33_ImportPrivkey "$PRIVA_A" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "${main_ip}"
chain33_ImportPrivkey "0xfa21dc33a6144c546537580d28d894355d1e9af7292be175808b0f5737c30849" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "${main_ip}" chain33_ImportPrivkey "$PRIVA_B" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$main_ip"
#16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc
chain33_ImportPrivkey "0x213286d352b01fd740b6eaeb78a4fd316d743dd51d2f12c6789977430a41e0c7" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$main_ip"
local ACCOUNT_A="16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" local ACCOUNT_A="16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f"
local ACCOUNT_B="16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" local ACCOUNT_B="16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc"
...@@ -153,16 +101,14 @@ function init() { ...@@ -153,16 +101,14 @@ function init() {
chain33_applyCoins "$ACCOUNT_B" 12000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_B" 12000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_B}" "$main_ip" chain33_QueryBalance "${ACCOUNT_B}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip" chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
chain33_applyCoins "$ACCOUNT_B" 1000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_B" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_B}" "$main_ip" chain33_QueryBalance "${ACCOUNT_B}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key chain33_ImportPrivkey "$PRIVA_A" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "$para_ip"
chain33_ImportPrivkey "0xfa21dc33a6144c546537580d28d894355d1e9af7292be175808b0f5737c30849" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "$para_ip" chain33_ImportPrivkey "$PRIVA_B" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$para_ip"
chain33_ImportPrivkey "0x213286d352b01fd740b6eaeb78a4fd316d743dd51d2f12c6789977430a41e0c7" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$para_ip"
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}" chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$para_ip" chain33_QueryBalance "${ACCOUNT_A}" "$para_ip"
...@@ -181,43 +127,28 @@ function init() { ...@@ -181,43 +127,28 @@ function init() {
function run_test() { function run_test() {
local ip=$1 local ip=$1
CreateGameTx 1000000000 "${HASH_VALUE}" CreateGameTx 1000000000 "${HASH_VALUE}"
QueryGameByGameId "${GAME_ID}" 1 QueryGameByGameId "${GAME_ID}" 1
QueryGameByStatus 1 QueryGameByStatus 1
MatchGameTx "${GAME_ID}" MatchGameTx "${GAME_ID}"
QueryGameByGameId "${GAME_ID}" 2 QueryGameByGameId "${GAME_ID}" 2
QueryGameByStatus 2 QueryGameByStatus 2
CloseGameTx "${GAME_ID}" "${PASSWD}" CloseGameTx "${GAME_ID}" "${PASSWD}"
QueryGameByGameId "${GAME_ID}" 4 QueryGameByGameId "${GAME_ID}" 4
QueryGameByStatus 4 QueryGameByStatus 4
CreateGameTx 500000000 "${HASH_VALUE}" CreateGameTx 500000000 "${HASH_VALUE}"
QueryGameByGameId "${GAME_ID}" 1 QueryGameByGameId "${GAME_ID}" 1
CancleGameTx "${GAME_ID}" CancleGameTx "${GAME_ID}"
QueryGameByGameId "${GAME_ID}" 3 QueryGameByGameId "${GAME_ID}" 3
QueryGameByStatus 3 QueryGameByStatus 3
} }
function main() { function main() {
chain33_RpcTestBegin game
local ip=$1 local ip=$1
MAIN_HTTP=$ip MAIN_HTTP=$ip
chain33_RpcTestBegin game
echo "main_ip=$MAIN_HTTP"
init init
run_test "$MAIN_HTTP" run_test "$MAIN_HTTP"
chain33_RpcTestRst game "$CASE_ERR" chain33_RpcTestRst game "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
guess_admin_addr=12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv guess_admin_addr=12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
guess_user1_addr=1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM guess_user1_addr=1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM
guess_user2_addr=17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN guess_user2_addr=17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN
...@@ -20,103 +18,38 @@ eventId="" ...@@ -20,103 +18,38 @@ eventId=""
txhash="" txhash=""
guess_game_start() { guess_game_start() {
echo "========== # guess start tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Start", "payload":{"topic":"WorldCup Final","options":"A:France;B:Claodia","category":"football","maxBetsOneTime":10000000000,"maxBetsNumber":100000000000,"devFeeFactor":5,"devFeeAddr":"1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7","platFeeFactor":5,"platFeeAddr":"1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Start", "payload":{"topic":"WorldCup Final","options":"A:France;B:Claodia","category":"football","maxBetsOneTime":10000000000,"maxBetsNumber":100000000000,"devFeeFactor":5,"devFeeAddr":"1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7","platFeeFactor":5,"platFeeAddr":"1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
eventId="${txhash}" eventId="${txhash}"
echo "eventId $eventId"
echo "========== # guess start tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_game_bet() { guess_game_bet() {
local priv=$1 local priv=$1
local opt=$2 local opt=$2
echo "========== # guess bet tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Bet", "payload":{"gameID":"'"${eventId}"'","option":"'"${opt}"'", "betsNum":500000000}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Bet", "payload":{"gameID":"'"${eventId}"'","option":"'"${opt}"'", "betsNum":500000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "${priv}" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "${priv}" ${MAIN_HTTP}
echo "========== # guess bet tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_game_stop() { guess_game_stop() {
echo "========== # guess stop tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"StopBet", "payload":{"gameID":"'"${eventId}"'"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"StopBet", "payload":{"gameID":"'"${eventId}"'"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
echo "========== # guess stop tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_game_publish() { guess_game_publish() {
echo "========== # guess publish tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Publish", "payload":{"gameID":"'"${eventId}"'","result":"A"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Publish", "payload":{"gameID":"'"${eventId}"'","result":"A"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
echo "========== # guess publish tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_game_abort() { guess_game_abort() {
echo "========== # guess abort tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Abort", "payload":{"gameID":"'"${eventId}"'"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Abort", "payload":{"gameID":"'"${eventId}"'"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
echo "========== # guess abort tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_QueryGameByID() { guess_QueryGameByID() {
local event_id=$1 local event_id=$1
local status=$2 local status=$2
echo "========== # guess QueryGameByID begin ==========" local req='{"method":"Chain33.Query", "params":[{"execer":"guess","funcName":"QueryGameByID","payload":{"gameID":"'"$event_id"'"}}]}'
local req='"method":"Chain33.Query", "params":[{"execer":"guess","funcName":"QueryGameByID","payload":{"gameID":"'"$event_id"'"}}]' chain33_Http "$req" ${MAIN_HTTP} '(.result|has("game")) and (.result.game.status == '"$status"')' "$FUNCNAME"
#echo "#request: $req"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.result|has("game")) and (.result.game.status == '"$status"')' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
echo "========== # guess QueryGameByID end =========="
} }
init() { init() {
...@@ -132,10 +65,7 @@ init() { ...@@ -132,10 +65,7 @@ init() {
echo "guess_addr=$guess_addr" echo "guess_addr=$guess_addr"
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM
chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "guess11" "${main_ip}" chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "guess11" "${main_ip}"
#17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN
chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "guess22" "$main_ip" chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "guess22" "$main_ip"
local guess1="1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" local guess1="1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM"
...@@ -148,14 +78,12 @@ init() { ...@@ -148,14 +78,12 @@ init() {
chain33_applyCoins "$guess2" 12000000000 "${main_ip}" chain33_applyCoins "$guess2" 12000000000 "${main_ip}"
chain33_QueryBalance "${guess2}" "$main_ip" chain33_QueryBalance "${guess2}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$guess1" 1000000000 "${main_ip}" chain33_applyCoins "$guess1" 1000000000 "${main_ip}"
chain33_QueryBalance "${guess1}" "$main_ip" chain33_QueryBalance "${guess1}" "$main_ip"
chain33_applyCoins "$guess2" 1000000000 "${main_ip}" chain33_applyCoins "$guess2" 1000000000 "${main_ip}"
chain33_QueryBalance "${guess2}" "$main_ip" chain33_QueryBalance "${guess2}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "guess11" "$para_ip" chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "guess11" "$para_ip"
chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "guess22" "$para_ip" chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "guess22" "$para_ip"
...@@ -174,7 +102,6 @@ init() { ...@@ -174,7 +102,6 @@ init() {
} }
function run_test() { function run_test() {
#导入地址私钥 #导入地址私钥
chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "user1" "$MAIN_HTTP" chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "user1" "$MAIN_HTTP"
chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "user2" "$MAIN_HTTP" chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "user2" "$MAIN_HTTP"
...@@ -320,7 +247,6 @@ function main() { ...@@ -320,7 +247,6 @@ function main() {
init init
run_test run_test
chain33_RpcTestRst guess "$CASE_ERR" chain33_RpcTestRst guess "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
...@@ -7,67 +8,24 @@ MAIN_HTTP="" ...@@ -7,67 +8,24 @@ MAIN_HTTP=""
addr_A=19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3 addr_A=19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3
addr_B=1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD addr_B=1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
hashlock_lock() { hashlock_lock() {
local secret=$1 local secret=$1
echo "========== # hashlock lock tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockLock", "payload":{"secret":"'"${secret}"'","amount":1000000000, "time":75,"toAddr":"'"${addr_B}"'", "returnAddr":"'"${addr_A}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockLock", "payload":{"secret":"'"${secret}"'","amount":1000000000, "time":75,"toAddr":"'"${addr_B}"'", "returnAddr":"'"${addr_A}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP}
#echo "txHash ${txhash}"
echo "========== # hashlock lock tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
hashlock_send() { hashlock_send() {
local secret=$1 local secret=$1
echo "========== # hashlock send tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockSend", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockSend", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0xb76a398c3901dfe5c7335525da88fda4df24c11ad11af4332f00c0953cc2910f" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0xb76a398c3901dfe5c7335525da88fda4df24c11ad11af4332f00c0953cc2910f" ${MAIN_HTTP}
#echo "txHash ${txhash}"
echo "========== # hashlock send tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
hashlock_unlock() { hashlock_unlock() {
local secret=$1 local secret=$1
echo "========== # hashlock unlock tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockUnlock", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockUnlock", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP}
#echo "txHash ${txhash}"
echo "========== # hashlock unlock tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
init() { init() {
...@@ -80,10 +38,7 @@ init() { ...@@ -80,10 +38,7 @@ init() {
fi fi
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3
chain33_ImportPrivkey "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" "19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3" "hashlock1" "${main_ip}" chain33_ImportPrivkey "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" "19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3" "hashlock1" "${main_ip}"
#1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD
chain33_ImportPrivkey "0xb76a398c3901dfe5c7335525da88fda4df24c11ad11af4332f00c0953cc2910f" "1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD" "hashlock2" "$main_ip" chain33_ImportPrivkey "0xb76a398c3901dfe5c7335525da88fda4df24c11ad11af4332f00c0953cc2910f" "1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD" "hashlock2" "$main_ip"
local hashlock1="19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3" local hashlock1="19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3"
...@@ -129,10 +84,8 @@ function run_test() { ...@@ -129,10 +84,8 @@ function run_test() {
hashlock_send "abc" hashlock_send "abc"
chain33_QueryBalance "$addr_B" "${MAIN_HTTP}" chain33_QueryBalance "$addr_B" "${MAIN_HTTP}"
hashlock_unlock "abc" hashlock_unlock "abc"
hashlock_lock "aef" hashlock_lock "aef"
chain33_QueryBalance "$addr_A" "${MAIN_HTTP}" chain33_QueryBalance "$addr_A" "${MAIN_HTTP}"
sleep 5 sleep 5
hashlock_unlock "aef" hashlock_unlock "aef"
chain33_BlockWait 1 ${MAIN_HTTP} chain33_BlockWait 1 ${MAIN_HTTP}
...@@ -140,13 +93,12 @@ function run_test() { ...@@ -140,13 +93,12 @@ function run_test() {
} }
function main() { function main() {
MAIN_HTTP="$1"
chain33_RpcTestBegin hashlock chain33_RpcTestBegin hashlock
MAIN_HTTP="$1"
echo "ip=$MAIN_HTTP" echo "ip=$MAIN_HTTP"
init init
run_test run_test
chain33_RpcTestRst hashlock "$CASE_ERR" chain33_RpcTestRst hashlock "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
...@@ -12,11 +11,6 @@ function init() { ...@@ -12,11 +11,6 @@ function init() {
beneficiary_key=0xf146df80206194c81e0b3171db6aa40c7ad6182a24560698d4871d4dc75223ce beneficiary_key=0xf146df80206194c81e0b3171db6aa40c7ad6182a24560698d4871d4dc75223ce
beneficiary=1DwHQp8S7RS9krQTyrqePxRyvaLcuoQGks beneficiary=1DwHQp8S7RS9krQTyrqePxRyvaLcuoQGks
chain33_applyCoins "${beneficiary}" 10000000000 "${MAIN_HTTP}" chain33_applyCoins "${beneficiary}" 10000000000 "${MAIN_HTTP}"
#paracross_get_money 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
#//beneficiary=12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
#beneficiary_key=0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01
#owner=14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
#owner_key=CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944
echo "ipara=$ispara" echo "ipara=$ispara"
manager_name="manage" manager_name="manage"
exec_name="jsvm" exec_name="jsvm"
...@@ -40,55 +34,30 @@ function init() { ...@@ -40,55 +34,30 @@ function init() {
} }
function configJSCreator() { function configJSCreator() {
req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${manager_name}'","actionName":"Modify","payload":{"key":"js-creator","op":"add", "value" : "'${beneficiary}'"}}]}' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'${manager_name}'","actionName":"Modify","payload":{"key":"js-creator","op":"add","value":"'${beneficiary}'"}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "${super_manager}" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${super_manager}" "${MAIN_HTTP}"
} }
function createJSContract() { function createJSContract() {
req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${exec_name}'","actionName":"Create","payload":{"name":"'${game}'","code":"'${jsCode}'"}}]}' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'${exec_name}'","actionName":"Create","payload":{"name":"'${game}'","code":"'${jsCode}'"}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "${beneficiary_key}" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${beneficiary_key}" "${MAIN_HTTP}"
} }
function callJS() { function callJS() {
#the_exec= req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'${user_game}'","actionName":"Call","payload":{"name":"'${game}'","funcname":"hello","args":"{}"}}]}'
req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${user_game}'","actionName":"Call","payload":{"name":"'${game}'","funcname":"hello", "args" : "{}"}}]}' chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
# echo "#request: $req" chain33_SignAndSendTx "$RETURN_RESP" "${beneficiary_key}" "${MAIN_HTTP}"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${beneficiary_key}" "${MAIN_HTTP}"
} }
function queryJS() { function queryJS() {
req='{"jsonrpc": "2.0", "method" : "Chain33.Query" , "params":[{"execer":"'${user_game}'","funcName":"Query","payload":{"name":"'${game}'","funcname":"hello", "args" : "{}"}}]}' req='{"method":"Chain33.Query","params":[{"execer":"'${user_game}'","funcName":"Query","payload":{"name":"'${game}'","funcname":"hello","args":"{}"}}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function run_testcases() { function run_testcases() {
configJSCreator configJSCreator
createJSContract createJSContract
callJS callJS
queryJS queryJS
...@@ -96,13 +65,11 @@ function run_testcases() { ...@@ -96,13 +65,11 @@ function run_testcases() {
function rpc_test() { function rpc_test() {
chain33_RpcTestBegin js chain33_RpcTestBegin js
MAIN_HTTP="$1" MAIN_HTTP="$1"
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_testcases run_testcases
chain33_RpcTestRst js "$CASE_ERR" chain33_RpcTestRst js "$CASE_ERR"
} }
......
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
MAIN_HTTP="" MAIN_HTTP=""
oracle_addPublisher_unsignedTx="0a066d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630e6b685d696ee9394163a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32" oracle_addPublisher_unsignedTx="0a066d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630e6b685d696ee9394163a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32"
...@@ -8,7 +9,6 @@ oracle_publisher_key="4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C72 ...@@ -8,7 +9,6 @@ oracle_publisher_key="4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C72
eventId="" eventId=""
txhash="" txhash=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
oracle_AddPublisher() { oracle_AddPublisher() {
...@@ -16,88 +16,52 @@ oracle_AddPublisher() { ...@@ -16,88 +16,52 @@ oracle_AddPublisher() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")') ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ispara=$ispara" echo "ispara=$ispara"
if [ "$ispara" == true ]; then if [ "$ispara" == true ]; then
chain33_SignRawTx "${oracle_addPublisher_unsignedTx_para}" "${oracle_publisher_key}" "${MAIN_HTTP}" chain33_SignAndSendTx "${oracle_addPublisher_unsignedTx_para}" "${oracle_publisher_key}" "${MAIN_HTTP}"
else else
chain33_SignRawTx "${oracle_addPublisher_unsignedTx}" "${oracle_publisher_key}" "${MAIN_HTTP}" chain33_SignAndSendTx "${oracle_addPublisher_unsignedTx}" "${oracle_publisher_key}" "${MAIN_HTTP}"
fi fi
} }
oracle_publish_transaction() { oracle_publish_transaction() {
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"EventPublish","payload":{"type":"football", "subType":"Premier League","time":1747814996,"content":"test","introduction":"test"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"EventPublish","payload":{"type":"football", "subType":"Premier League","time":1747814996,"content":"test","introduction":"test"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
eventId="${txhash}" eventId="${txhash}"
echo "eventId $eventId" echo "eventId $eventId"
} }
oracle_prePublishResult_transaction() { oracle_prePublishResult_transaction() {
event_id=$1 event_id=$1
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultPrePublish","payload":{"eventID":"'"$event_id"'", "source":"sina sport","result":"0:1"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultPrePublish","payload":{"eventID":"'"$event_id"'", "source":"sina sport","result":"0:1"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_eventAbort_transaction() { oracle_eventAbort_transaction() {
event_id=$1 event_id=$1
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"EventAbort","payload":{"eventID":"'"$event_id"'"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"EventAbort","payload":{"eventID":"'"$event_id"'"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_resultAbort_transaction() { oracle_resultAbort_transaction() {
event_id=$1 event_id=$1
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultAbort","payload":{"eventID":"'"$event_id"'"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultAbort","payload":{"eventID":"'"$event_id"'"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_publishResult_transaction() { oracle_publishResult_transaction() {
event_id=$1 event_id=$1
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultPublish","payload":{"eventID":"'"$event_id"'", "source":"sina sport","result":"1:1"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultPublish","payload":{"eventID":"'"$event_id"'", "source":"sina sport","result":"1:1"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_QueryOraclesByID() { oracle_QueryOraclesByID() {
event_id=$1 event_id=$1
local req='"method":"Chain33.Query", "params":[{"execer":"oracle","funcName":"QueryOraclesByIDs","payload":{"eventID":["'"$event_id"'"]}}]' req='{"method":"Chain33.Query", "params":[{"execer":"oracle","funcName":"QueryOraclesByIDs","payload":{"eventID":["'"$event_id"'"]}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.status[0] | [has("eventID", "status", "type", "subType", "source"),true] | unique | length == 1)' "$FUNCNAME"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result.status[0] | [has("eventID", "status", "type", "subType", "source"),true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function run_test() { function run_test() {
...@@ -134,14 +98,12 @@ function run_test() { ...@@ -134,14 +98,12 @@ function run_test() {
} }
function main() { function main() {
chain33_RpcTestBegin oracle
MAIN_HTTP="$1" MAIN_HTTP="$1"
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
chain33_RpcTestBegin oracle
run_test run_test
chain33_RpcTestRst oracle "$CASE_ERR" chain33_RpcTestRst oracle "$CASE_ERR"
} }
main "$1" chain33_debug_function main "$1"
This diff is collapsed.
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
GAME_ID="" GAME_ID=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
pokerbull_PlayRawTx() { pokerbull_PlayRawTx() {
echo "========== # pokerbull play tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Play","payload":{"gameId":"pokerbull-abc", "value":"1000000000", "round":1}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Play","payload":{"gameId":"pokerbull-abc", "value":"1000000000", "round":1}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
echo "========== # pokerbull play tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
pokerbull_QuitRawTx() { pokerbull_QuitRawTx() {
echo "========== # pokerbull quit tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Quit","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Quit","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
echo "========== # pokerbull quit tx end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
pokerbull_ContinueRawTx() { pokerbull_ContinueRawTx() {
echo "========== # pokerbull continue tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Continue","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Continue","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" ${MAIN_HTTP}
echo "========== # pokerbull continue tx end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
pokerbull_StartRawTx() { pokerbull_StartRawTx() {
echo "========== # pokerbull start tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Start","payload":{"value":"1000000000", "playerNum":"2"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Start","payload":{"value":"1000000000", "playerNum":"2"}}]}' ${MAIN_HTTP} | jq -r ".result")
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]") chain33_Http "$req" ${MAIN_HTTP} '(.result.txs[0].execer != null)' "$FUNCNAME"
ok=$(jq '(.execer != "")' <<<"$data") chain33_SignAndSendTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
GAME_ID=$RAW_TX_HASH GAME_ID=$RAW_TX_HASH
echo "========== # pokerbull start tx end =========="
chain33_BlockWait 1 "${MAIN_HTTP}" chain33_BlockWait 1 "${MAIN_HTTP}"
} }
pokerbull_QueryResult() { pokerbull_QueryResult() {
echo "========== # pokerbull query result begin ==========" req='{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]}'
local req='"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]' resok='(.result.game.gameId == "'"$GAME_ID"'")'
data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.game.gameId == "'"$GAME_ID"'")' <<<"$data")
[ "$ok" == true ] req='{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4"}}]}'
echo_rst "$FUNCNAME" "$?" chain33_Http "$req" ${MAIN_HTTP} '(.result != null)' "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4"}}]}' ${MAIN_HTTP} | jq -r ".result") req='{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByStatus","payload":{"status":"3"}}]}'
[ "$data" != null ] chain33_Http "$req" ${MAIN_HTTP} '(.result != null)' "$FUNCNAME"
echo_rst "$FUNCNAME" "$?"
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByStatus","payload":{"status":"3"}}]}' ${MAIN_HTTP} | jq -r ".result")
[ "$data" != null ]
echo_rst "$FUNCNAME" "$?"
echo "========== # pokerbull query result end =========="
} }
init() { init() {
...@@ -104,10 +55,7 @@ init() { ...@@ -104,10 +55,7 @@ init() {
fi fi
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4
chain33_ImportPrivkey "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" "14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" "pokerbull1" "${main_ip}" chain33_ImportPrivkey "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" "14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" "pokerbull1" "${main_ip}"
#1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1
chain33_ImportPrivkey "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" "1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1" "pokerbull2" "$main_ip" chain33_ImportPrivkey "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" "1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1" "pokerbull2" "$main_ip"
local pokerbull1="14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" local pokerbull1="14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4"
...@@ -120,14 +68,12 @@ init() { ...@@ -120,14 +68,12 @@ init() {
chain33_applyCoins "$pokerbull2" 12000000000 "${main_ip}" chain33_applyCoins "$pokerbull2" 12000000000 "${main_ip}"
chain33_QueryBalance "${pokerbull2}" "$main_ip" chain33_QueryBalance "${pokerbull2}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$pokerbull1" 1000000000 "${main_ip}" chain33_applyCoins "$pokerbull1" 1000000000 "${main_ip}"
chain33_QueryBalance "${pokerbull1}" "$main_ip" chain33_QueryBalance "${pokerbull1}" "$main_ip"
chain33_applyCoins "$pokerbull2" 1000000000 "${main_ip}" chain33_applyCoins "$pokerbull2" 1000000000 "${main_ip}"
chain33_QueryBalance "${pokerbull2}" "$main_ip" chain33_QueryBalance "${pokerbull2}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" "14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" "pokerbull1" "$para_ip" chain33_ImportPrivkey "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" "14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" "pokerbull1" "$para_ip"
chain33_ImportPrivkey "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" "1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1" "pokerbull2" "$para_ip" chain33_ImportPrivkey "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" "1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1" "pokerbull2" "$para_ip"
...@@ -155,7 +101,6 @@ function run_test() { ...@@ -155,7 +101,6 @@ function run_test() {
pokerbull_PlayRawTx pokerbull_PlayRawTx
pokerbull_QueryResult pokerbull_QueryResult
} }
function main() { function main() {
...@@ -165,7 +110,6 @@ function main() { ...@@ -165,7 +110,6 @@ function main() {
init init
run_test run_test
chain33_RpcTestRst pokerbull "$CASE_ERR" chain33_RpcTestRst pokerbull "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
privacy_CreateRawTransaction() { privacy_CreateRawTransaction() {
req='{"method":"privacy.CreateRawTransaction","params":[{"pubkeypair":"0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb", "assetExec":"coins", "tokenname":"BTY", "type":1, "amount":100000000}]}'
local ip=$1 chain33_Http "$req" ${MAIN_HTTP} '.error|not' "$FUNCNAME"
req='"method":"privacy.CreateRawTransaction","params":[{"pubkeypair":"0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb", "assetExec":"coins", "tokenname":"BTY", "type":1, "amount":100000000}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '.error|not' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_GetPrivacyTxByAddr() { privacy_GetPrivacyTxByAddr() {
chain33_Http '{"method":"privacy.GetPrivacyTxByAddr","params":[{"tokenname":"BTY","sendRecvFlag":0,"from":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "direction":1, "count":1}]}' ${MAIN_HTTP} '.error|not' "$FUNCNAME"
local ip=$1
req='"method":"privacy.GetPrivacyTxByAddr","params":[{"tokenname":"BTY","sendRecvFlag":0,"from":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "direction":1, "count":1}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '.error|not' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_ShowPrivacyKey() { privacy_ShowPrivacyKey() {
req='{"method":"privacy.ShowPrivacyKey", "params":[{"data":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"}]}'
local ip=$1 resok='(.error|not) and .result.showSuccessful and (.result.pubkeypair=="0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb")'
req='"method":"privacy.ShowPrivacyKey", "params":[{"data":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"}]' chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and .result.showSuccessful and (.result.pubkeypair=="0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_ShowPrivacyAccountInfo() { privacy_ShowPrivacyAccountInfo() {
req='{"method":"privacy.ShowPrivacyAccountInfo", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY", "displaymode":1}]}'
local ip=$1 chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result|[has("utxos", "ftxos", "displaymode"), true] | unique | length == 1)' "$FUNCNAME"
req='"method":"privacy.ShowPrivacyAccountInfo", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY", "displaymode":1}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result|[has("utxos", "ftxos", "displaymode"), true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_ShowPrivacyAccountSpend() { privacy_ShowPrivacyAccountSpend() {
chain33_Http '{"method":"privacy.ShowPrivacyAccountSpend", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY"}]}' ${MAIN_HTTP} '(.error|not) and .result.utxoHaveTxHashs' "$FUNCNAME"
local ip=$1
req='"method":"privacy.ShowPrivacyAccountSpend", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY"}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and .result.utxoHaveTxHashs' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_RescanUtxos() { privacy_RescanUtxos() {
chain33_Http '{"method":"privacy.RescanUtxos", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"], "flag":0}]}' ${MAIN_HTTP} '(.error|not) and (.result|[has("flag", "repRescanResults"), true] | unique | length == 1)' "$FUNCNAME"
local ip=$1
req='"method":"privacy.RescanUtxos", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"], "flag":0}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result|[has("flag", "repRescanResults"), true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_EnablePrivacy() { privacy_EnablePrivacy() {
chain33_Http '{"method":"privacy.EnablePrivacy", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"]}]}' ${MAIN_HTTP} '(.error|not) and .result.results[0].IsOK' "$FUNCNAME"
local ip=$1
req='"method":"privacy.EnablePrivacy", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"]}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and .result.results[0].IsOK' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function run_test() { function run_test() {
local ip=$1 privacy_EnablePrivacy
privacy_EnablePrivacy "$ip" privacy_ShowPrivacyKey
privacy_ShowPrivacyKey "$ip" privacy_CreateRawTransaction
privacy_CreateRawTransaction "$ip" privacy_ShowPrivacyAccountInfo
privacy_ShowPrivacyAccountInfo "$ip" privacy_ShowPrivacyAccountSpend
privacy_ShowPrivacyAccountSpend "$ip" privacy_RescanUtxos
privacy_RescanUtxos "$ip" privacy_GetPrivacyTxByAddr
privacy_GetPrivacyTxByAddr "$ip"
} }
function main() { function main() {
MAIN_HTTP="$1"
chain33_RpcTestBegin privacy chain33_RpcTestBegin privacy
MAIN_HTTP="$1"
echo "ip=$MAIN_HTTP" echo "ip=$MAIN_HTTP"
run_test "$MAIN_HTTP" run_test
chain33_RpcTestRst privacy "$CASE_ERR" chain33_RpcTestRst privacy "$CASE_ERR"
} }
main "$1" chain33_debug_function main "$1"
This diff is collapsed.
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
# TODO # TODO
...@@ -19,7 +19,7 @@ function updateConfig() { ...@@ -19,7 +19,7 @@ function updateConfig() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}" chain33_SignAndSendTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
} }
function token_preCreate() { function token_preCreate() {
...@@ -29,7 +29,7 @@ function token_preCreate() { ...@@ -29,7 +29,7 @@ function token_preCreate() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}" chain33_SignAndSendTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
} }
function token_finish() { function token_finish() {
...@@ -39,7 +39,7 @@ function token_finish() { ...@@ -39,7 +39,7 @@ function token_finish() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}" chain33_SignAndSendTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
} }
function token_sendExec() { function token_sendExec() {
...@@ -49,7 +49,7 @@ function token_sendExec() { ...@@ -49,7 +49,7 @@ function token_sendExec() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "$3" "${MAIN_HTTP}" chain33_SignAndSendTx "${unsignedTx}" "$3" "${MAIN_HTTP}"
} }
function createToken() { function createToken() {
...@@ -61,126 +61,45 @@ function createToken() { ...@@ -61,126 +61,45 @@ function createToken() {
} }
retrieve_Backup() { retrieve_Backup() {
echo "========== # retrieve backup begin =========="
local req='{"method":"retrieve.CreateRawRetrieveBackupTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'","delayPeriod": 61}]}' local req='{"method":"retrieve.CreateRawRetrieveBackupTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'","delayPeriod": 61}]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve2_key" ${MAIN_HTTP} "$FUNCNAME"
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "$retrieve2_key" ${MAIN_HTTP}
echo "========== # retrieve backup end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_Prepare() { retrieve_Prepare() {
echo "========== # retrieve prepare begin =========="
local req='{"method":"retrieve.CreateRawRetrievePrepareTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}' local req='{"method":"retrieve.CreateRawRetrievePrepareTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve1_key" ${MAIN_HTTP} "$FUNCNAME"
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "$retrieve1_key" ${MAIN_HTTP}
echo "========== # retrieve prepare end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_Perform() { retrieve_Perform() {
echo "========== # retrieve perform begin =========="
local req='{"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}' local req='{"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve1_key" ${MAIN_HTTP} "$FUNCNAME"
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "$retrieve1_key" ${MAIN_HTTP}
echo "========== # retrieve perform end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_Perform_Token() { retrieve_Perform_Token() {
echo "========== # retrieve perform begin =========="
local req='{"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'","assets": [{"exec":"token","symbol":"'"$symbol"'"}] }]}' local req='{"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'","assets": [{"exec":"token","symbol":"'"$symbol"'"}] }]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve1_key" ${MAIN_HTTP} "$FUNCNAME"
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "$retrieve1_key" ${MAIN_HTTP}
echo "========== # retrieve perform end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_Cancel() { retrieve_Cancel() {
echo "========== # retrieve cancel begin =========="
local req='{"method":"retrieve.CreateRawRetrieveCancelTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}' local req='{"method":"retrieve.CreateRawRetrieveCancelTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve2_key" ${MAIN_HTTP} "$FUNCNAME"
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "$retrieve2_key" ${MAIN_HTTP}
echo "========== # retrieve cancel end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_QueryResult() { retrieve_QueryResult() {
echo "========== # retrieve query result begin =========="
local status=$1 local status=$1
local req='{"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"'$retrieve1'", "defaultAddress":"'$retrieve2'"}}]}' local req='{"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"'$retrieve1'", "defaultAddress":"'$retrieve2'"}}]}'
data=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") chain33_Http "$req" ${MAIN_HTTP} '(.result.status == '"$status"')' "$FUNCNAME"
ok=$(jq '(.status == '"$status"')' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
echo "========== # retrieve query result end =========="
} }
retrieve_QueryAssetResult() { retrieve_QueryAssetResult() {
echo "========== # retrieve query result begin =========="
local status=$1 local status=$1
local req='{"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"'$retrieve1'", "defaultAddress":"'$retrieve2'","assetExec":"token", "assetSymbol":"'"$symbol"'"}}]}' local req='{"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"'$retrieve1'", "defaultAddress":"'$retrieve2'","assetExec":"token", "assetSymbol":"'"$symbol"'"}}]}'
data=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") chain33_Http "$req" ${MAIN_HTTP} '(.result.status == '"$status"')' "$FUNCNAME"
ok=$(jq '(.status == '"$status"')' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
echo "========== # retrieve query result end =========="
} }
init() { init() {
...@@ -207,7 +126,6 @@ init() { ...@@ -207,7 +126,6 @@ init() {
chain33_applyCoins "${retrieve2}" 10000000000 "${MAIN_HTTP}" chain33_applyCoins "${retrieve2}" 10000000000 "${MAIN_HTTP}"
if [ "$ispara" == true ]; then if [ "$ispara" == true ]; then
# for fee
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
chain33_applyCoins "${retrieve1}" 1000000000 "${main_ip}" chain33_applyCoins "${retrieve1}" 1000000000 "${main_ip}"
chain33_applyCoins "${retrieve2}" 1000000000 "${main_ip}" chain33_applyCoins "${retrieve2}" 1000000000 "${main_ip}"
...@@ -244,15 +162,13 @@ function run_test() { ...@@ -244,15 +162,13 @@ function run_test() {
} }
function main() { function main() {
MAIN_HTTP="$1"
chain33_RpcTestBegin retrieve chain33_RpcTestBegin retrieve
MAIN_HTTP="$1"
echo "ip=$MAIN_HTTP" echo "ip=$MAIN_HTTP"
init init
run_test run_test
chain33_RpcTestRst retrieve "$CASE_ERR" chain33_RpcTestRst retrieve "$CASE_ERR"
} }
set -x
chain33_debug_function main "$1" chain33_debug_function main "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
ticketId="" ticketId=""
...@@ -17,107 +17,71 @@ ticket_CreateBindMiner() { ...@@ -17,107 +17,71 @@ ticket_CreateBindMiner() {
returnAddr=$2 returnAddr=$2
returnPriv=$3 returnPriv=$3
amount=$4 amount=$4
resp=$(curl -ksd '{"method":"ticket.CreateBindMiner","params":[{"bindAddr":"'"$minerAddr"'", "originAddr":"'"$returnAddr"'", "amount":'"$amount"', "checkBalance":true}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"ticket.CreateBindMiner","params":[{"bindAddr":"'"$minerAddr"'", "originAddr":"'"$returnAddr"'", "amount":'"$amount"', "checkBalance":true}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result.txHex"
[[ $ok == null ]] chain33_SignAndSendTx "$RETURN_RESP" "${returnPriv}" ${MAIN_HTTP}
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result.txHex")
chain33_SignRawTx "${rawTx}" "${returnPriv}" ${MAIN_HTTP}
} }
ticket_SetAutoMining() { ticket_SetAutoMining() {
flag=$1 flag=$1
resp=$(curl -ksd '{"method":"ticket.SetAutoMining","params":[{"flag":'"$flag"'}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"ticket.SetAutoMining","params":[{"flag":'"$flag"'}]}'
ok=$(jq '(.error|not) and (.result.isOK == true)' <<<"$resp") chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.isOK == true)' "$FUNCNAME"
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_GetTicketCount() { ticket_GetTicketCount() {
resp=$(curl -ksd '{"method":"ticket.GetTicketCount","params":[{}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http '{"method":"ticket.GetTicketCount","params":[{}]}' ${MAIN_HTTP} '(.error|not) and (.result > 0)' "$FUNCNAME"
ok=$(jq '(.error|not) and (.result > 0)' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_CloseTickets() { ticket_CloseTickets() {
addr=$1 addr=$1
resp=$(curl -ksd '{"method":"ticket.CloseTickets","params":[{"minerAddress":"'"$addr"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"ticket.CloseTickets","params":[{"minerAddress":"'"$addr"'"}]}'
ok=$(jq '(.error|not)' <<<"$resp") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME"
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_TicketInfos() { ticket_TicketInfos() {
tid=$1 tid=$1
minerAddr=$2 minerAddr=$2
returnAddr=$3 returnAddr=$3
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"TicketInfos","payload":{"ticketIds":["'"$tid"'"]}}]}'
funcName="TicketInfos" resok='(.error|not) and (.result.tickets | length > 0) and (.result.tickets[0].minerAddress == "'"$minerAddr"'") and (.result.tickets[0].returnAddress == "'"$returnAddr"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"ticketIds":["'"$tid"'"]}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.tickets | length > 0) and (.result.tickets[0].minerAddress == "'"$minerAddr"'") and (.result.tickets[0].returnAddress == "'"$returnAddr"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_TicketList() { ticket_TicketList() {
minerAddr=$1 minerAddr=$1
returnAddr=$2 returnAddr=$2
status=$3 status=$3
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"TicketList","payload":{"addr":"'"$minerAddr"'", "status":'"$status"'}}]}'
funcName="TicketList" resok='(.error|not) and (.result.tickets | length > 0) and (.result.tickets[0].minerAddress == "'"$minerAddr"'") and (.result.tickets[0].returnAddress == "'"$returnAddr"'") and (.result.tickets[0].status == '"$status"')'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"addr":"'"$minerAddr"'", "status":'"$status"'}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.tickets | length > 0) and (.result.tickets[0].minerAddress == "'"$minerAddr"'") and (.result.tickets[0].returnAddress == "'"$returnAddr"'") and (.result.tickets[0].status == '"$status"')' <<<"$resp")
[[ $ok == true ]] ticket0=$(echo "${RETURN_RESP}" | jq -r ".result.tickets[0]")
rst=$?
echo_rst "$FUNCNAME" "$rst"
ticket0=$(echo "${resp}" | jq -r ".result.tickets[0]")
echo -e "######\\n ticket[0] is $ticket0) \\n######" echo -e "######\\n ticket[0] is $ticket0) \\n######"
ticketId=$(echo "${resp}" | jq -r ".result.tickets[0].ticketId") ticketId=$(echo "${RETURN_RESP}" | jq -r ".result.tickets[0].ticketId")
echo -e "######\\n ticketId is $ticketId \\n######" echo -e "######\\n ticketId is $ticketId \\n######"
} }
ticket_MinerAddress() { ticket_MinerAddress() {
returnAddr=$1 returnAddr=$1
minerAddr=$2 minerAddr=$2
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"MinerAddress","payload":{"data":"'"$returnAddr"'"}}]}'
funcName="MinerAddress" resok='(.error|not) and (.result.data == "'"$minerAddr"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"data":"'"$returnAddr"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.data == "'"$minerAddr"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_MinerSourceList() { ticket_MinerSourceList() {
minerAddr=$1 minerAddr=$1
returnAddr=$2 returnAddr=$2
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"MinerSourceList","payload":{"data":"'"$minerAddr"'"}}]}'
funcName="MinerSourceList" resok='(.error|not) and (.result.datas | length > 0) and (.result.datas[0] == "'"$returnAddr"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"data":"'"$minerAddr"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.datas | length > 0) and (.result.datas[0] == "'"$returnAddr"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_RandNumHash() { ticket_RandNumHash() {
hash=$1 hash=$1
blockNum=$2 blockNum=$2
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"RandNumHash","payload":{"hash":"'"$hash"'", "blockNum":'"$blockNum"'}}]}'
funcName="RandNumHash" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.hash != null)' "$FUNCNAME"
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"hash":"'"$hash"'", "blockNum":'"$blockNum"'}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.hash != "")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function run_testcases() { function run_testcases() {
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
tokenAddr="1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK" tokenAddr="1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
recvAddr="1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" recvAddr="1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq"
superManager="0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc" superManager="0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc"
tokenSymbol="ABCDE" tokenSymbol="ABCDE"
token_addr="" token_addr=""
execName="token" execName="token"
txHash=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
# $2=0 means true, other false
function echo_rst() {
if [ "$2" -eq 0 ]; then
echo -e "${GRE}$1 ok${NOC}"
else
echo -e "${RED}$1 fail${NOC}"
CASE_ERR="FAIL"
fi
}
# 查询交易的执行结果 # 查询交易的执行结果
# 根据传入的规则,校验查询的结果 (参数1: 校验规则 参数2: 预期匹配结果) # 根据传入的规则,校验查询的结果 (参数1: 校验规则 参数2: 预期匹配结果)
function queryTransaction() { function queryTransaction() {
validator=$1 validator=$1
expectRes=$2 expectRes=$2
echo "txhash=${txHash}" # echo "txhash=${RAW_TX_HASH}"
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.QueryTransaction","params":[{"hash":"'"${txHash}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r "${validator}") res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.QueryTransaction","params":[{"hash":"'"${RAW_TX_HASH}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r "${validator}")
if [ "${res}" != "${expectRes}" ]; then if [ "${res}" != "${expectRes}" ]; then
return 1 return 1
else else
...@@ -43,14 +25,18 @@ function queryTransaction() { ...@@ -43,14 +25,18 @@ function queryTransaction() {
fi fi
} }
function signRawTxAndQuery() {
chain33_SignAndSendTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "$1 queryExecRes" "$?"
}
function init() { function init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")') ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara" echo "ipara=$ispara"
chain33_ImportPrivkey "${superManager}" "${tokenAddr}" "tokenAddr" "${MAIN_HTTP}" chain33_ImportPrivkey "${superManager}" "${tokenAddr}" "tokenAddr" "${MAIN_HTTP}"
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq
chain33_ImportPrivkey "0x882c963ce2afbedc2353cb417492aa9e889becd878a10f2529fc9e6c3b756128" "1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" "token1" "${main_ip}" chain33_ImportPrivkey "0x882c963ce2afbedc2353cb417492aa9e889becd878a10f2529fc9e6c3b756128" "1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" "token1" "${main_ip}"
local ACCOUNT_A="1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" local ACCOUNT_A="1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq"
...@@ -59,12 +45,10 @@ function init() { ...@@ -59,12 +45,10 @@ function init() {
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_A" 12000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip" chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip" chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0x882c963ce2afbedc2353cb417492aa9e889becd878a10f2529fc9e6c3b756128" "1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" "token1" "$para_ip" chain33_ImportPrivkey "0x882c963ce2afbedc2353cb417492aa9e889becd878a10f2529fc9e6c3b756128" "1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" "token1" "$para_ip"
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}" chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}"
...@@ -96,25 +80,16 @@ function updateConfig() { ...@@ -96,25 +80,16 @@ function updateConfig() {
echo_rst "update config create tx" 1 echo_rst "update config create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "update config queryExecRes" "$?"
} }
function token_preCreate() { function token_preCreate() {
unsignedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"token.CreateRawTokenPreCreateTx","params":[{"name": "yinhebib", "symbol": "'"${tokenSymbol}"'", "total": 100000000000, "price": 100, "category": 1,"owner":"'${tokenAddr}'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result") unsignedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"token.CreateRawTokenPreCreateTx","params":[{"name": "yinhebib", "symbol": "'"${tokenSymbol}"'", "total": 100000000000, "price": 100, "category": 1,"owner":"'${tokenAddr}'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
if [ "${unsignedTx}" == "" ]; then if [ "${unsignedTx}" == "" ]; then
echo_rst "token preCreate create tx" 1 echo_rst "token preCreate create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token preCreate queryExecRes" "$?"
} }
function token_getPreCreated() { function token_getPreCreated() {
...@@ -132,21 +107,12 @@ function token_finish() { ...@@ -132,21 +107,12 @@ function token_finish() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}" signRawTxAndQuery "$FUNCNAME"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token finish queryExecRes" "$?"
} }
function token_getFinishCreated() { function token_getFinishCreated() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"${execName}"'","funcName":"GetTokens","payload":{"queryAll":true,"status":1,"tokens":[],"symbolOnly":false}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.tokens" | grep "symbol") req='{"method":"Chain33.Query","params":[{"execer":"'"${execName}"'","funcName":"GetTokens","payload":{"queryAll":true,"status":1,"tokens":[],"symbolOnly":false}}]}'
chain33_Http "$req" ${MAIN_HTTP} "(.result.tokens[0].symbol != null)" "$FUNCNAME"
if [ "${res}" != "" ]; then
echo_rst "token get finishCreated create tx" 0
else
echo_rst "token get finishCreated create tx" 1
fi
} }
function token_assets() { function token_assets() {
...@@ -166,8 +132,8 @@ function token_assets() { ...@@ -166,8 +132,8 @@ function token_assets() {
else else
echo_rst "token get assets tx" 1 echo_rst "token get assets tx" 1
fi fi
} }
function token_balance() { function token_balance() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"token.GetTokenBalance","params":[{"addresses": ["'${tokenAddr}'"],"tokenSymbol":"'"${tokenSymbol}"'","execer": "'"${execName}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"token.GetTokenBalance","params":[{"addresses": ["'${tokenAddr}'"],"tokenSymbol":"'"${tokenSymbol}"'","execer": "'"${execName}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
...@@ -192,12 +158,7 @@ function token_burn() { ...@@ -192,12 +158,7 @@ function token_burn() {
echo_rst "token burn create tx" 1 echo_rst "token burn create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token burn queryExecRes" "$?"
} }
function token_mint() { function token_mint() {
...@@ -206,12 +167,7 @@ function token_mint() { ...@@ -206,12 +167,7 @@ function token_mint() {
echo_rst "token mint create tx" 1 echo_rst "token mint create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token mint queryExecRes" "$?"
} }
function token_transfer() { function token_transfer() {
unsignedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.CreateTransaction","params":[{"execer": "'"${execName}"'","actionName":"Transfer","payload": {"cointoken":"'"${tokenSymbol}"'", "amount": "1000000000", "note": "", "to": "'"${recvAddr}"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result") unsignedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.CreateTransaction","params":[{"execer": "'"${execName}"'","actionName":"Transfer","payload": {"cointoken":"'"${tokenSymbol}"'", "amount": "1000000000", "note": "", "to": "'"${recvAddr}"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
...@@ -219,12 +175,7 @@ function token_transfer() { ...@@ -219,12 +175,7 @@ function token_transfer() {
echo_rst "token transfer create tx" 1 echo_rst "token transfer create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token transfer queryExecRes" "$?"
} }
function token_sendExec() { function token_sendExec() {
...@@ -233,12 +184,7 @@ function token_sendExec() { ...@@ -233,12 +184,7 @@ function token_sendExec() {
echo_rst "token sendExec create tx" 1 echo_rst "token sendExec create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token sendExec queryExecRes" "$?"
} }
function token_withdraw() { function token_withdraw() {
...@@ -247,17 +193,11 @@ function token_withdraw() { ...@@ -247,17 +193,11 @@ function token_withdraw() {
echo_rst "token withdraw create tx" 1 echo_rst "token withdraw create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token withdraw queryExecRes" "$?"
} }
function run_test() { function run_test() {
local ip=$1 local ip=$1
set -x
token_preCreate token_preCreate
token_getPreCreated token_getPreCreated
...@@ -271,19 +211,16 @@ function run_test() { ...@@ -271,19 +211,16 @@ function run_test() {
token_sendExec token_sendExec
token_assets token_assets
token_withdraw token_withdraw
set +x
} }
function main() { function main() {
local ip=$1
chain33_RpcTestBegin token chain33_RpcTestBegin token
local ip=$1
MAIN_HTTP=$ip MAIN_HTTP=$ip
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_test "$ip" run_test "$ip"
chain33_RpcTestRst token "$CASE_ERR" chain33_RpcTestRst token "$CASE_ERR"
} }
......
This diff is collapsed.
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
...@@ -10,28 +9,26 @@ txhash="" ...@@ -10,28 +9,26 @@ txhash=""
function query_unfreezeID() { function query_unfreezeID() {
chain33_BlockWait 1 "$MAIN_HTTP" chain33_BlockWait 1 "$MAIN_HTTP"
# echo "req=$req"
local times=10 local times=10
while true; do while true; do
req='{"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]}' req='{"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]}'
ret=$(curl -ksd "$req" ${MAIN_HTTP}) ret=$(curl -ksd "$req" ${MAIN_HTTP})
tx=$(jq -r ".result.tx.hash" <<<"$ret") tx=$(jq -r ".result.tx.hash" <<<"$ret")
echo "====query tx= ${txhash}, return=$ret " # echo "====query tx= ${txhash}, return=$ret "
if [ "${tx}" != "${txhash}" ]; then if [ "${tx}" != "${txhash}" ]; then
chain33_BlockWait 1 "${MAIN_HTTP}" chain33_BlockWait 1 "${MAIN_HTTP}"
times=$((times - 1)) times=$((times - 1))
if [ $times -le 0 ]; then if [ $times -le 0 ]; then
echo "====query tx=$txhash failed" echo -e "${RED}====query tx=$txhash failed${NOC}"
echo "req=$req" echo "req=$req"
curl -ksd "$req" ${MAIN_HTTP} curl -ksd "$req" ${MAIN_HTTP}
exit 1 exit 1
fi fi
else else
unfreeze_id=$(jq '(.result.receipt.logs['"$uid_index"'].log.current.unfreezeID)' <<<"$ret") unfreeze_id=$(jq '(.result.receipt.logs['"$uid_index"'].log.current.unfreezeID)' <<<"$ret")
#echo "${unfreeze_id}"
unfreeze_id2=${unfreeze_id#\"mavl-unfreeze-} unfreeze_id2=${unfreeze_id#\"mavl-unfreeze-}
uid=${unfreeze_id2%\"} uid=${unfreeze_id2%\"}
echo "====query tx=$txhash success" echo -e "${GRE}====query tx=$txhash success${NOC}"
break break
fi fi
done done
...@@ -75,89 +72,51 @@ function init() { ...@@ -75,89 +72,51 @@ function init() {
function CreateRawUnfreezeCreate() { function CreateRawUnfreezeCreate() {
req='{"jsonrpc": "2.0", "method" : "unfreeze.CreateRawUnfreezeCreate" , "params":[{"startTime":10000,"assetExec":"coins","assetSymbol":"'$symbol'","totalCount":400000000,"beneficiary":"'$beneficiary'","means":"FixAmount","fixAmount": {"period":10,"amount":1000000}}]}' req='{"jsonrpc": "2.0", "method" : "unfreeze.CreateRawUnfreezeCreate" , "params":[{"startTime":10000,"assetExec":"coins","assetSymbol":"'$symbol'","totalCount":400000000,"beneficiary":"'$beneficiary'","means":"FixAmount","fixAmount": {"period":10,"amount":1000000}}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "$owner_key" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "$owner_key" "${MAIN_HTTP}"
query_unfreezeID query_unfreezeID
} }
function CreateRawUnfreezeWithdraw() { function CreateRawUnfreezeWithdraw() {
sleep 10 sleep 10
req='{"method":"unfreeze.CreateRawUnfreezeWithdraw","params":[{"unfreezeID":"'${uid}'"}]}' req='{"method":"unfreeze.CreateRawUnfreezeWithdraw","params":[{"unfreezeID":"'${uid}'"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "${beneficiary_key}" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${beneficiary_key}" "${MAIN_HTTP}"
} }
function CreateRawUnfreezeTerminate() { function CreateRawUnfreezeTerminate() {
req='{"method":"unfreeze.CreateRawUnfreezeTerminate","params":[{"unfreezeID":"'${uid}'"}]}' req='{"method":"unfreeze.CreateRawUnfreezeTerminate","params":[{"unfreezeID":"'${uid}'"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "$owner_key" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "$owner_key" "${MAIN_HTTP}"
chain33_BlockWait 2 "${MAIN_HTTP}" chain33_BlockWait 2 "${MAIN_HTTP}"
} }
function GetUnfreeze() { function GetUnfreeze() {
req='{"method":"unfreeze.GetUnfreeze","params":[{"data":"'${uid}'"}]}' req='{"method":"unfreeze.GetUnfreeze","params":[{"data":"'${uid}'"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function GetUnfreezeWithdraw() { function GetUnfreezeWithdraw() {
req='{"method":"unfreeze.GetUnfreezeWithdraw","params":[{"data":"'${uid}'"}]}' req='{"method":"unfreeze.GetUnfreezeWithdraw","params":[{"data":"'${uid}'"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function run_testcases() { function run_testcases() {
CreateRawUnfreezeCreate CreateRawUnfreezeCreate
CreateRawUnfreezeWithdraw CreateRawUnfreezeWithdraw
GetUnfreeze GetUnfreeze
GetUnfreezeWithdraw GetUnfreezeWithdraw
CreateRawUnfreezeTerminate CreateRawUnfreezeTerminate
} }
function debug_function() {
set -x
eval "$@"
set +x
}
function rpc_test() { function rpc_test() {
chain33_RpcTestBegin unfreeze chain33_RpcTestBegin unfreeze
MAIN_HTTP="$1" MAIN_HTTP="$1"
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_testcases run_testcases
chain33_RpcTestRst unfreeze "$CASE_ERR" chain33_RpcTestRst unfreeze "$CASE_ERR"
} }
debug_function rpc_test "$1" chain33_debug_function rpc_test "$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