Commit e6331519 authored by yingqiumin@126.com's avatar yingqiumin@126.com

优化rpc test,保存代码

parent f6de10f0
......@@ -3,6 +3,8 @@
RAW_TX_HASH=""
LAST_BLOCK_HASH=""
CASE_ERR=""
HTTP_RESP=""
RAW_RESP=""
#color
RED='\033[1;31m'
......@@ -16,11 +18,23 @@ echo_rst() {
echo -e "${GRE}$1 not support${NOC}"
else
echo -e "${RED}$1 fail${NOC}"
echo -e "${RED}$3 ${NOC}"
CASE_ERR="err"
echo $CASE_ERR
fi
}
http_req() {
# echo "#$4 request: $1"
HTTP_RESP=$(curl -ksd "$1" "$2")
RAW_RESP=$(jq -r "$5" <<<"$HTTP_RESP")
# echo "#response: $HTTP_RESP"
ok=$(echo "$HTTP_RESP" | jq -r "$3")
[ "$ok" == true ]
rst=$?
echo_rst "$4" "$rst" "$HTTP_RESP"
}
chain33_BlockWait() {
local MAIN_HTTP=$2
local req='"method":"Chain33.GetLastHeader","params":[]'
......
......@@ -31,32 +31,43 @@ init() {
chain33_NewAccount() {
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")
[ "$result" != "" ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
glAddr=$result
echo "$glAddr"
# 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")
# [ "$result" != "" ]
# rst=$?
# echo_rst "$FUNCNAME" "$rst"
# glAddr=$result
# echo "$glAddr"
req='{"method":"Chain33.NewAccount","params":[{"label":"'"$label"'"}]}'
http_req "$req" ${MAIN_HTTP} '(.result.acc.addr != "")' "$FUNCNAME"
}
chain33_SendTransaction() {
rawTx=$1
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})
ok=$(echo "${resp}" | jq -r ".error")
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
# 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})
# ok=$(echo "${resp}" | jq -r ".error")
# [ "$ok" == null ]
# rst=$?
# echo_rst "$FUNCNAME" "$rst"
req='{"method":"Chain33.SignRawTx","params":[{"addr":"'"$addr"'","txHex":"'"$rawTx"'","expire":"120s","fee":10000000,"index":0}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME"
# 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})
# ok=$(echo "${resp}" | jq -r ".error")
# [ "$ok" == null ]
# rst=$?
# echo_rst "$FUNCNAME" "$rst"
req='{"method":"Chain33.SendTransaction","params":[{"data":"'"$signTx"'"}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME"
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})
ok=$(echo "${resp}" | jq -r ".error")
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#返回交易
gResp=$(jq -r ".result" <<<"$resp")
gResp=$(jq -r ".result" <<<"$HTTP_RESP")
echo "tx hash is $gResp"
chain33_QueryTx "$gResp" "${MAIN_HTTP}"
}
......@@ -64,13 +75,17 @@ chain33_SendTransaction() {
blackwhite_BlackwhiteCreateTx() {
#创建交易
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})
ok=$(echo "${resp}" | jq -r ".error")
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
# 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})
# ok=$(echo "${resp}" | jq -r ".error")
# [ "$ok" == null ]
# rst=$?
# echo_rst "$FUNCNAME" "$rst"
req='{"method":"blackwhite.BlackwhiteCreateTx","params":[{"PlayAmount":100000000,"PlayerCount":3,"GameName":"hello","Timeout":600,"Fee":1000000}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result")
rawTx=$(echo "${HTTP_RESP}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${addr}"
gID="${gResp}"
echo "gameID $gID"
......
#!/usr/bin/env bash
# shellcheck disable=SC2128
set -e
# set -e
set -o pipefail
MAIN_HTTP=""
......@@ -15,27 +15,33 @@ source ../dapp-test-common.sh
function chain33_GetExecAddr() {
#获取GAME合约地址
local exector=$1
local req='"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'"${exector}"'"}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
req='{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'"$1"'"}]}'
resok='(.error|not)'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
# local exector=$1
# local req='"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'"${exector}"'"}]'
# echo "#request: $req"
# resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
# echo "#response: $resp"
# GAME_ADDR=$(echo "${res}" | jq -r ".result")
echo_rst "$FUNCNAME" "$?"
# echo_rst "$FUNCNAME" "$?"
}
function CreateGameTx() {
local amount=$1
local hash_value=$2
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"createGame", "payload":{"amount": '"${amount}"',"hashType":"sha256","hashValue":"'"${hash_value}"'"}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CreateGame createRawTx" 1
fi
local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"createGame", "payload":{"amount": '"${amount}"',"hashType":"sha256","hashValue":"'"${hash_value}"'"}}]}'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
# echo "#request: $req"
# resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
# echo "#response: $resp"
# rawTx=$(echo "${resp}" | jq -r ".result")
# if [ "$rawTx" == "null" ]; then
# echo_rst "CreateGame createRawTx" 1
# fi
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
GAME_ID=$RAW_TX_HASH
......@@ -45,16 +51,18 @@ function CreateGameTx() {
function MatchGameTx() {
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}}]}'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "MatchGame createRawTx"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "MatchGame createRawTx" 1
fi
# echo "#request: $req"
# resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
# echo "#response: $resp"
rawTx=$(echo "${HTTP_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" "$?"
......@@ -63,16 +71,18 @@ function MatchGameTx() {
function CloseGameTx() {
local gameId=$1
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"
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "CloseGame createRawTx"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CloseGame createRawTx" 1
fi
# echo "#request: $req"
# resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
# echo "#response: $resp"
rawTx=$(echo "${HTTP_RESP}" | jq -r ".result")
# if [ "$rawTx" == "null" ]; then
# echo_rst "CloseGame createRawTx" 1
# fi
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
echo_rst "CloseGame query_tx" "$?"
......@@ -80,16 +90,17 @@ function CloseGameTx() {
function CancleGameTx() {
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"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "CancleGame createRawTx"
# echo "#request: $req"
# resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
# echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CancleGame createRawTx" 1
fi
rawTx=$(echo "${HTTP_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" "$?"
......@@ -97,29 +108,33 @@ function CancleGameTx() {
function QueryGameByStatus() {
local status=$1
local req='"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameListByStatusAndAddr","payload":{"status":'"${status}"',"address":""}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
GAMES=$(echo "${resp}" | jq -r ".result.games")
echo "${GAMES}"
echo_rst "$FUNCNAME" "$?"
local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameListByStatusAndAddr","payload":{"status":'"${status}"',"address":""}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.games != "")' "$FUNCNAME"
# echo "#request: $req"
# resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
# echo "#response: $resp"
# GAMES=$(echo "${resp}" | jq -r ".result.games")
# echo "${GAMES}"
# echo_rst "$FUNCNAME" "$?"
}
function QueryGameByGameId() {
local gameId=$1
local status=$2
local req='"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameById","payload":{"gameId":"'"${gameId}"'"}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
STATUS=$(echo "${resp}" | jq -r ".result.game.status")
if [ "${STATUS}" -ne "${status}" ]; then
echo "status is not equal"
echo_rst "QueryGameByGameId" 1
return 0
fi
echo_rst "QueryGameByGameId" 0
local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameById","payload":{"gameId":"'"${gameId}"'"}}]}'
resok='(.error|not) and (.result.game.status = "'"${status}"'")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
# echo "#request: $req"
# resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
# echo "#response: $resp"
# STATUS=$(echo "${resp}" | jq -r ".result.game.status")
# if [ "${STATUS}" -ne "${status}" ]; then
# echo "status is not equal"
# echo_rst "QueryGameByGameId" 1
# return 0
# fi
# echo_rst "QueryGameByGameId" 0
}
function init() {
......@@ -212,9 +227,10 @@ function run_test() {
function main() {
local ip=$1
MAIN_HTTP=$ip
chain33_RpcTestBegin game
echo "main_ip=$MAIN_HTTP"
echo "main_ip=$MAIN_HTTP"
init
run_test "$MAIN_HTTP"
......@@ -222,3 +238,4 @@ function main() {
}
chain33_debug_function main "$1"
#main "$1"
......@@ -14,15 +14,19 @@ source ../dapp-test-common.sh
hashlock_lock() {
local secret=$1
echo "========== # hashlock lock tx begin =========="
# 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")
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
# 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" "$?"
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
resok='(.result.txs[0].execer != "")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
chain33_SignRawTx "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP}
#echo "txHash ${txhash}"
......@@ -38,11 +42,15 @@ hashlock_send() {
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockSend", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result")
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
# 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" "$?"
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
resok='(.result.txs[0].execer != "")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
chain33_SignRawTx "$tx" "0xb76a398c3901dfe5c7335525da88fda4df24c11ad11af4332f00c0953cc2910f" ${MAIN_HTTP}
#echo "txHash ${txhash}"
......@@ -57,11 +65,15 @@ hashlock_unlock() {
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockUnlock", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result")
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
# 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" "$?"
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
resok='(.result.txs[0].execer != "")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
chain33_SignRawTx "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP}
#echo "txHash ${txhash}"
......@@ -129,10 +141,8 @@ function run_test() {
hashlock_send "abc"
chain33_QueryBalance "$addr_B" "${MAIN_HTTP}"
hashlock_unlock "abc"
hashlock_lock "aef"
chain33_QueryBalance "$addr_A" "${MAIN_HTTP}"
sleep 5
hashlock_unlock "aef"
chain33_BlockWait 1 ${MAIN_HTTP}
......@@ -142,8 +152,8 @@ function run_test() {
function main() {
MAIN_HTTP="$1"
chain33_RpcTestBegin hashlock
echo "ip=$MAIN_HTTP"
echo "ip=$MAIN_HTTP"
init
run_test
......
......@@ -40,50 +40,69 @@ function init() {
}
function configJSCreator() {
req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${manager_name}'","actionName":"Modify","payload":{"key":"js-creator","op":"add", "value" : "'${beneficiary}'"}}]}'
echo "#request: $req"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${manager_name}'","actionName":"Modify","payload":{"key":"js-creator","op":"add", "value" : "'${beneficiary}'"}}]}'
# echo "#request: $req"
# 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")
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'${manager_name}'","actionName":"Modify","payload":{"key":"js-creator","op":"add", "value" : "'${beneficiary}'"}}]}'
resok='(.error|not) and (.result != "")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "${super_manager}" "${MAIN_HTTP}"
}
function createJSContract() {
req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${exec_name}'","actionName":"Create","payload":{"name":"'${game}'","code":"'${jsCode}'"}}]}'
echo "#request: $req"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${exec_name}'","actionName":"Create","payload":{"name":"'${game}'","code":"'${jsCode}'"}}]}'
# echo "#request: $req"
# 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")
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'${exec_name}'","actionName":"Create","payload":{"name":"'${game}'","code":"'${jsCode}'"}}]}'
resok='(.error|not) and (.result != "")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "${beneficiary_key}" "${MAIN_HTTP}"
}
function callJS() {
#the_exec=
req='{"jsonrpc": "2.0", "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" : "{}"}}]}'
# echo "#request: $req"
resp=$(curl -ksd "$req" "${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")
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'${user_game}'","actionName":"Call","payload":{"name":"'${game}'","funcname":"hello","args":"{}"}}]}'
resok='(.error|not) and (.result != "")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "${beneficiary_key}" "${MAIN_HTTP}"
}
function queryJS() {
req='{"jsonrpc": "2.0", "method" : "Chain33.Query" , "params":[{"execer":"'${user_game}'","funcName":"Query","payload":{"name":"'${game}'","funcname":"hello", "args" : "{}"}}]}'
# req='{"jsonrpc": "2.0", "method" : "Chain33.Query" , "params":[{"execer":"'${user_game}'","funcName":"Query","payload":{"name":"'${game}'","funcname":"hello", "args" : "{}"}}]}'
# echo "#request: $req"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.Query","params":[{"execer":"'${user_game}'","funcName":"Query","payload":{"name":"'${game}'","funcname":"hello","args":"{}"}}]}'
resok='(.error|not) and (.result != "")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
}
function run_testcases() {
......
This diff is collapsed.
......@@ -23,14 +23,18 @@ oracle_AddPublisher() {
}
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"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
# resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
# echo "#response: $resp"
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"EventPublish","payload":{"type":"football", "subType":"Premier League","time":1747814996,"content":"test","introduction":"test"}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
eventId="${txhash}"
echo "eventId $eventId"
......@@ -38,66 +42,77 @@ oracle_publish_transaction() {
oracle_prePublishResult_transaction() {
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"}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
#echo "#request: $req"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
# resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
# echo "#response: $resp"
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
}
oracle_eventAbort_transaction() {
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"'"}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
#echo "#request: $req"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
# resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
# echo "#response: $resp"
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
}
oracle_resultAbort_transaction() {
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"'"}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
#echo "#request: $req"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
# resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
# echo "#response: $resp"
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
}
oracle_publishResult_transaction() {
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"}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
#echo "#request: $req"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
# resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
# echo "#response: $resp"
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
}
oracle_QueryOraclesByID() {
event_id=$1
local req='"method":"Chain33.Query", "params":[{"execer":"oracle","funcName":"QueryOraclesByIDs","payload":{"eventID":["'"$event_id"'"]}}]'
# local req='"method":"Chain33.Query", "params":[{"execer":"oracle","funcName":"QueryOraclesByIDs","payload":{"eventID":["'"$event_id"'"]}}]'
#echo "#request: $req"
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"
# 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"
req='{"method":"Chain33.Query", "params":[{"execer":"oracle","funcName":"QueryOraclesByIDs","payload":{"eventID":["'"$event_id"'"]}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result.status[0] | [has("eventID", "status", "type", "subType", "source"),true] | unique | length == 1)' "$FUNCNAME"
}
function run_test() {
......
......@@ -201,30 +201,34 @@ function paracross_Transfer_Withdraw() {
}
function paracross_IsSync() {
local ok
# local ok
if [ "$IS_PARA" == "true" ]; then
ok=$(curl -ksd '{"method":"paracross.IsSync","params":[]}' ${UNIT_HTTP} | jq -r ".result")
req='{"method":"paracross.IsSync","params":[]}'
# ok=$(curl -ksd '{"method":"paracross.IsSync","params":[]}' ${UNIT_HTTP} | jq -r ".result")
else
ok=$(curl -ksd '{"method":"Chain33.IsSync","params":[]}' ${UNIT_HTTP} | jq -r ".result")
# ok=$(curl -ksd '{"method":"Chain33.IsSync","params":[]}' ${UNIT_HTTP} | jq -r ".result")
req='{"method":"Chain33.IsSync","params":[]}'
fi
http_req "$req" ${UNIT_HTTP} '.result' "$FUNCNAME"
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
# [ "$ok" == true ]
# local rst=$?
# echo_rst "$FUNCNAME" "$rst"
}
function paracross_ListTitles() {
local resp
local ok
# local resp
# local ok
local main_ip=${UNIT_HTTP//8901/8801}
resp=$(curl -ksd '{"method":"paracross.ListTitles","params":[]}' ${main_ip})
echo "$resp"
ok=$(jq '(.error|not) and (.result| [has("titles"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
# resp=$(curl -ksd '{"method":"paracross.ListTitles","params":[]}' ${main_ip})
# echo "$resp"
# ok=$(jq '(.error|not) and (.result| [has("titles"),true])' <<<"$resp")
# [ "$ok" == true ]
# local rst=$?
# echo_rst "$FUNCNAME" "$rst"
http_req '{"method":"paracross.ListTitles","params":[]}' ${main_ip} '(.error|not) and (.result| [has("titles"),true])' "$FUNCNAME"
}
function paracross_GetHeight() {
......@@ -232,61 +236,71 @@ function paracross_GetHeight() {
local ok
if [ "$IS_PARA" == "true" ]; then
resp=$(curl -ksd '{"method":"paracross.GetHeight","params":[]}' ${UNIT_HTTP})
# resp=$(curl -ksd '{"method":"paracross.GetHeight","params":[]}' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("consensHeight"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
# ok=$(jq '(.error|not) and (.result| [has("consensHeight"),true])' <<<"$resp")
# [ "$ok" == true ]
# local rst=$?
# echo_rst "$FUNCNAME" "$rst"
http_req '{"method":"paracross.GetHeight","params":[]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("consensHeight"),true])' "$FUNCNAME"
fi
}
function paracross_GetNodeGroupAddrs() {
local resp
local ok
# local resp
# local ok
resp=$(curl -ksd '{"method":"paracross.GetNodeGroupAddrs","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP})
# resp=$(curl -ksd '{"method":"paracross.GetNodeGroupAddrs","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("key","value"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
# ok=$(jq '(.error|not) and (.result| [has("key","value"),true])' <<<"$resp")
# [ "$ok" == true ]
# local rst=$?
# echo_rst "$FUNCNAME" "$rst"
http_req '{"method":"paracross.GetNodeGroupAddrs","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("key","value"),true])' "$FUNCNAME"
}
function paracross_GetNodeGroupStatus() {
local resp
local ok
# local resp
# local ok
resp=$(curl -ksd '{"method":"paracross.GetNodeGroupStatus","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP})
# resp=$(curl -ksd '{"method":"paracross.GetNodeGroupStatus","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
# ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
# [ "$ok" == true ]
# local rst=$?
# echo_rst "$FUNCNAME" "$rst"
http_req '{"method":"paracross.GetNodeGroupStatus","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME"
}
function paracross_ListNodeGroupStatus() {
local resp
local ok
# local resp
# local ok
resp=$(curl -ksd '{"method":"paracross.ListNodeGroupStatus","params":[{"title":"user.p.para.","status":2}]}' ${UNIT_HTTP})
# resp=$(curl -ksd '{"method":"paracross.ListNodeGroupStatus","params":[{"title":"user.p.para.","status":2}]}' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
# ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
# [ "$ok" == true ]
# local rst=$?
# echo_rst "$FUNCNAME" "$rst"
http_req '{"method":"paracross.ListNodeGroupStatus","params":[{"title":"user.p.para.","status":2}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME"
}
function paracross_ListNodeStatus() {
local resp
local ok
# local resp
# local ok
resp=$(curl -ksd '{"method":"paracross.ListNodeStatus","params":[{"title":"user.p.para.","status":4}]}' ${UNIT_HTTP})
# resp=$(curl -ksd '{"method":"paracross.ListNodeStatus","params":[{"title":"user.p.para.","status":4}]}' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
# ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
# [ "$ok" == true ]
# local rst=$?
# echo_rst "$FUNCNAME" "$rst"
http_req '{"method":"paracross.ListNodeStatus","params":[{"title":"user.p.para.","status":4}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME"
}
#main chain import pri key
......
......@@ -13,11 +13,14 @@ 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")
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
# 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" "$?"
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
http_req "$req" ${MAIN_HTTP} '(.result.txs[0].execer != "")' "$FUNCNAME"
chain33_SignRawTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
echo "========== # pokerbull play tx end =========="
......@@ -29,11 +32,13 @@ 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")
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
# 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" "$?"
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
http_req "$req" ${MAIN_HTTP} '(.result.txs[0].execer != "")' "$FUNCNAME"
chain33_SignRawTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
echo "========== # pokerbull quit tx end =========="
......@@ -45,11 +50,13 @@ 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")
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
# 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" "$?"
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
http_req "$req" ${MAIN_HTTP} '(.result.txs[0].execer != "")' "$FUNCNAME"
chain33_SignRawTx "$tx" "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" ${MAIN_HTTP}
echo "========== # pokerbull continue tx end =========="
......@@ -61,11 +68,14 @@ 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")
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
# 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" "$?"
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
http_req "$req" ${MAIN_HTTP} '(.result.txs[0].execer != "")' "$FUNCNAME"
chain33_SignRawTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
GAME_ID=$RAW_TX_HASH
......@@ -76,21 +86,32 @@ pokerbull_StartRawTx() {
pokerbull_QueryResult() {
echo "========== # pokerbull query result begin =========="
local req='"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]'
data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
# local req='"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]'
# data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
# ok=$(jq '(.game.gameId == "'"$GAME_ID"'")' <<<"$data")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
ok=$(jq '(.game.gameId == "'"$GAME_ID"'")' <<<"$data")
req='{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]}'
resok='(.result.game.gameId == "'"$GAME_ID"'")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4"}}]}' ${MAIN_HTTP} | jq -r ".result")
# [ "$data" != null ]
# echo_rst "$FUNCNAME" "$?"
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4"}}]}' ${MAIN_HTTP} | jq -r ".result")
[ "$data" != null ]
echo_rst "$FUNCNAME" "$?"
req='{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4"}}]}'
http_req "$req" ${MAIN_HTTP} '(.result != null)' "$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" "$?"
req='{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByStatus","payload":{"status":"3"}}]}'
http_req "$req" ${MAIN_HTTP} '(.result != null)' "$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 =========="
}
......@@ -155,7 +176,6 @@ function run_test() {
pokerbull_PlayRawTx
pokerbull_QueryResult
}
function main() {
......
......@@ -9,107 +9,52 @@ source ../dapp-test-common.sh
MAIN_HTTP=""
privacy_CreateRawTransaction() {
local ip=$1
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" "$?"
req='{"method":"privacy.CreateRawTransaction","params":[{"pubkeypair":"0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb", "assetExec":"coins", "tokenname":"BTY", "type":1, "amount":100000000}]}'
http_req "$req" ${MAIN_HTTP} '.error|not' "$FUNCNAME"
}
privacy_GetPrivacyTxByAddr() {
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" "$?"
http_req '{"method":"privacy.GetPrivacyTxByAddr","params":[{"tokenname":"BTY","sendRecvFlag":0,"from":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "direction":1, "count":1}]}' ${MAIN_HTTP} '.error|not' "$FUNCNAME"
}
privacy_ShowPrivacyKey() {
local ip=$1
req='"method":"privacy.ShowPrivacyKey", "params":[{"data":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"}]'
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" "$?"
req='{"method":"privacy.ShowPrivacyKey", "params":[{"data":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"}]}'
resok='(.error|not) and .result.showSuccessful and (.result.pubkeypair=="0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
}
privacy_ShowPrivacyAccountInfo() {
local ip=$1
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" "$?"
req='{"method":"privacy.ShowPrivacyAccountInfo", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY", "displaymode":1}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result|[has("utxos", "ftxos", "displaymode"), true] | unique | length == 1)' "$FUNCNAME"
}
privacy_ShowPrivacyAccountSpend() {
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" "$?"
http_req '{"method":"privacy.ShowPrivacyAccountSpend", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY"}]}' ${MAIN_HTTP} '(.error|not) and .result.utxoHaveTxHashs' "$FUNCNAME"
}
privacy_RescanUtxos() {
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" "$?"
http_req '{"method":"privacy.RescanUtxos", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"], "flag":0}]}' ${MAIN_HTTP} '(.error|not) and (.result|[has("flag", "repRescanResults"), true] | unique | length == 1)' "$FUNCNAME"
}
privacy_EnablePrivacy() {
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" "$?"
http_req '{"method":"privacy.EnablePrivacy", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"]}]}' ${MAIN_HTTP} '(.error|not) and .result.results[0].IsOK' "$FUNCNAME"
}
function run_test() {
local ip=$1
privacy_EnablePrivacy "$ip"
privacy_ShowPrivacyKey "$ip"
privacy_CreateRawTransaction "$ip"
privacy_ShowPrivacyAccountInfo "$ip"
privacy_ShowPrivacyAccountSpend "$ip"
privacy_RescanUtxos "$ip"
privacy_GetPrivacyTxByAddr "$ip"
privacy_EnablePrivacy
privacy_ShowPrivacyKey
privacy_CreateRawTransaction
privacy_ShowPrivacyAccountInfo
privacy_ShowPrivacyAccountSpend
privacy_RescanUtxos
privacy_GetPrivacyTxByAddr
}
function main() {
MAIN_HTTP="$1"
chain33_RpcTestBegin privacy
echo "ip=$MAIN_HTTP"
run_test "$MAIN_HTTP"
chain33_RpcTestBegin privacy
run_test
chain33_RpcTestRst privacy "$CASE_ERR"
}
......
This diff is collapsed.
......@@ -67,11 +67,13 @@ retrieve_Backup() {
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
http_req "$reqDecode" ${MAIN_HTTP} '(.result.txs[0].execer != "")' "$FUNCNAME"
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# 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 =========="
......@@ -86,11 +88,13 @@ retrieve_Prepare() {
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
http_req "$reqDecode" ${MAIN_HTTP} '(.result.txs[0].execer != "")' "$FUNCNAME"
# data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
# ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "$retrieve1_key" ${MAIN_HTTP}
echo "========== # retrieve prepare end =========="
......@@ -105,11 +109,13 @@ retrieve_Perform() {
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
http_req "$reqDecode" ${MAIN_HTTP} '(.result.txs[0].execer != "")' "$FUNCNAME"
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# 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 =========="
......@@ -124,11 +130,13 @@ retrieve_Perform_Token() {
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
http_req "$reqDecode" ${MAIN_HTTP} '(.result.txs[0].execer != "")' "$FUNCNAME"
# data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
# ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "$retrieve1_key" ${MAIN_HTTP}
echo "========== # retrieve perform end =========="
......@@ -143,11 +151,13 @@ retrieve_Cancel() {
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
local reqDecode='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd "$reqDecode" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
http_req "$reqDecode" ${MAIN_HTTP} '(.result.txs[0].execer != "")' "$FUNCNAME"
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# 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 =========="
......@@ -161,11 +171,13 @@ retrieve_QueryResult() {
local status=$1
local req='{"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"'$retrieve1'", "defaultAddress":"'$retrieve2'"}}]}'
data=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
ok=$(jq '(.status == '"$status"')' <<<"$data")
http_req "$req" ${MAIN_HTTP} '(.result.status == '"$status"')' "$FUNCNAME"
# data=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
# ok=$(jq '(.status == '"$status"')' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
echo "========== # retrieve query result end =========="
}
......@@ -175,11 +187,13 @@ retrieve_QueryAssetResult() {
local status=$1
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")
ok=$(jq '(.status == '"$status"')' <<<"$data")
http_req "$req" ${MAIN_HTTP} '(.result.status == '"$status"')' "$FUNCNAME"
# data=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
# ok=$(jq '(.status == '"$status"')' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
echo "========== # retrieve query result end =========="
}
......
This diff is collapsed.
......@@ -76,12 +76,15 @@ function init() {
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}}]}'
# echo "#request: $req"
resp=$(curl -ksd "$req" "${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")
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "$owner_key" "${MAIN_HTTP}"
query_unfreezeID
}
......@@ -89,47 +92,51 @@ function CreateRawUnfreezeCreate() {
function CreateRawUnfreezeWithdraw() {
sleep 10
req='{"method":"unfreeze.CreateRawUnfreezeWithdraw","params":[{"unfreezeID":"'${uid}'"}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
# echo "#request: $req"
resp=$(curl -ksd "$req" "${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")
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "${beneficiary_key}" "${MAIN_HTTP}"
}
function CreateRawUnfreezeTerminate() {
req='{"method":"unfreeze.CreateRawUnfreezeTerminate","params":[{"unfreezeID":"'${uid}'"}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
# echo "#request: $req"
resp=$(curl -ksd "$req" "${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")
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$HTTP_RESP")
chain33_SignRawTx "$rawtx" "$owner_key" "${MAIN_HTTP}"
chain33_BlockWait 2 "${MAIN_HTTP}"
}
function GetUnfreeze() {
req='{"method":"unfreeze.GetUnfreeze","params":[{"data":"'${uid}'"}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
# echo "#request: $req"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
}
function GetUnfreezeWithdraw() {
req='{"method":"unfreeze.GetUnfreezeWithdraw","params":[{"data":"'${uid}'"}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not) and (.result != "")' "$FUNCNAME"
# echo "#request: $req"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
# ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
}
function run_testcases() {
......
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