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

improve rpc test

parents 2555a509 f9df6fa2
...@@ -24,8 +24,6 @@ echo_rst() { ...@@ -24,8 +24,6 @@ echo_rst() {
} }
http_req() { http_req() {
# echo "request="$1" MAIN_HTTP="$2" js="$3" FUNCNAME="$4" response="$5""
# echo "#$4 request: $1"
local body=$(curl -ksd "$1" "$2") local body=$(curl -ksd "$1" "$2")
RETURN_RESP=$(jq -r "$5" <<<"$body") RETURN_RESP=$(jq -r "$5" <<<"$body")
echo "#response: $body" "$RETURN_RESP" echo "#response: $body" "$RETURN_RESP"
......
...@@ -24,4 +24,4 @@ function rpc_test() { ...@@ -24,4 +24,4 @@ function rpc_test() {
} }
chain33_debug_function rpc_test "$1" chain33_debug_function rpc_test "$1"
\ No newline at end of file
...@@ -176,4 +176,4 @@ function main() { ...@@ -176,4 +176,4 @@ function main() {
chain33_RpcTestRst blackwhite "$CASE_ERR" chain33_RpcTestRst blackwhite "$CASE_ERR"
} }
chain33_debug_function main "$1" chain33_debug_function main "$1"
\ No newline at end of file
...@@ -106,4 +106,4 @@ function main() { ...@@ -106,4 +106,4 @@ function main() {
chain33_RpcTestRst hashlock "$CASE_ERR" chain33_RpcTestRst hashlock "$CASE_ERR"
} }
chain33_debug_function main "$1" chain33_debug_function main "$1"
\ No newline at end of file
...@@ -62,8 +62,8 @@ function callJS() { ...@@ -62,8 +62,8 @@ function callJS() {
function queryJS() { function queryJS() {
req='{"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":"{}"}}]}'
resok='(.error|not) and (.result != null)' resok='(.error|not) and (.result != null)'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
} }
function run_testcases() { function run_testcases() {
......
...@@ -75,7 +75,7 @@ lottery_LotteryCreate() { ...@@ -75,7 +75,7 @@ lottery_LotteryCreate() {
#创建交易 #创建交易
priv=$1 priv=$1
req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryCreate","payload":{"purBlockNum":'"$purNum"',"drawBlockNum":'"$drawNum"', "opRewardRatio":'"$opRatio"',"devRewardRatio":'"$devRatio"',"fee":1000000}}]}' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryCreate","payload":{"purBlockNum":'"$purNum"',"drawBlockNum":'"$drawNum"', "opRewardRatio":'"$opRatio"',"devRewardRatio":'"$devRatio"',"fee":1000000}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result" http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
#发送交易 #发送交易
chain33_SignRawTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP} chain33_SignRawTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP}
...@@ -91,7 +91,7 @@ lottery_LotteryBuy() { ...@@ -91,7 +91,7 @@ lottery_LotteryBuy() {
number=$3 number=$3
way=$4 way=$4
req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryBuy","payload":{"lotteryId":"'"$gID"'","amount":'"$amount"',"number":'"$number"',"way":'"$way"',"fee":1000000}}]}' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryBuy","payload":{"lotteryId":"'"$gID"'","amount":'"$amount"',"number":'"$number"',"way":'"$way"',"fee":1000000}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result" http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
#发送交易 #发送交易
chain33_SignRawTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP} chain33_SignRawTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP}
...@@ -101,7 +101,7 @@ lottery_LotteryDraw() { ...@@ -101,7 +101,7 @@ lottery_LotteryDraw() {
#创建交易 #创建交易
priv=$1 priv=$1
req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryDraw","payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryDraw","payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result" http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
#发送交易 #发送交易
chain33_SignRawTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP} chain33_SignRawTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP}
} }
...@@ -110,7 +110,7 @@ lottery_LotteryClose() { ...@@ -110,7 +110,7 @@ lottery_LotteryClose() {
#创建交易 #创建交易
priv=$1 priv=$1
req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryClose","payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryClose","payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}'
http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result" http_req "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
#发送交易 #发送交易
chain33_SignRawTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP} chain33_SignRawTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP}
} }
...@@ -119,7 +119,7 @@ lottery_GetLotteryNormalInfo() { ...@@ -119,7 +119,7 @@ lottery_GetLotteryNormalInfo() {
gameID=$1 gameID=$1
addr=$2 addr=$2
req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryNormalInfo","payload":{"lotteryId":"'"$gameID"'"}}]}' req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryNormalInfo","payload":{"lotteryId":"'"$gameID"'"}}]}'
resok='(.error|not) and (.result.purBlockNum == "'"$purNum"'") and (.result.drawBlockNum == "'"$drawNum"'") and (.result.createAddr == "'"$addr"'") and (.result.opRewardRatio == "'"$opRatio"'") and (.result.devRewardRatio == "'"$devRatio"'") and (.result | [has("createHeight"), true] | unique | length == 1)' resok='(.error|not) and (.result.purBlockNum == "'"$purNum"'") and (.result.drawBlockNum == "'"$drawNum"'") and (.result.createAddr == "'"$addr"'") and (.result.opRewardRatio == "'"$opRatio"'") and (.result.devRewardRatio == "'"$devRatio"'") and (.result | [has("createHeight"), true] | unique | length == 1)'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
} }
...@@ -128,8 +128,8 @@ lottery_GetLotteryCurrentInfo() { ...@@ -128,8 +128,8 @@ lottery_GetLotteryCurrentInfo() {
status=$2 status=$2
amount=$3 amount=$3
req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryCurrentInfo","payload":{"lotteryId":"'"$gameID"'"}}]}' req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryCurrentInfo","payload":{"lotteryId":"'"$gameID"'"}}]}'
resok='(.error|not) and (.result.status == '"$status"') and (.result.buyAmount == "'"$amount"'") and (.result | [has("lastTransToPurState", "lastTransToDrawState", "totalPurchasedTxNum", "round", "luckyNumber", "lastTransToPurStateOnMain", "lastTransToDrawStateOnMain", "purBlockNum", "drawBlockNum", "missingRecords", "totalAddrNum"), true] | unique | length == 1)' resok='(.error|not) and (.result.status == '"$status"') and (.result.buyAmount == "'"$amount"'") and (.result | [has("lastTransToPurState", "lastTransToDrawState", "totalPurchasedTxNum", "round", "luckyNumber", "lastTransToPurStateOnMain", "lastTransToDrawStateOnMain", "purBlockNum", "drawBlockNum", "missingRecords", "totalAddrNum"), true] | unique | length == 1)'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" ".result.luckyNumber" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" ".result.luckyNumber"
if [[ $status == 3 ]]; then if [[ $status == 3 ]]; then
luckyNumber=$RETURN_RESP luckyNumber=$RETURN_RESP
...@@ -142,8 +142,8 @@ lottery_GetLotteryPurchaseAddr() { ...@@ -142,8 +142,8 @@ lottery_GetLotteryPurchaseAddr() {
gameID=$1 gameID=$1
count=$2 count=$2
req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryPurchaseAddr","payload":{"lotteryId":"'"$gameID"'"}}]}' req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryPurchaseAddr","payload":{"lotteryId":"'"$gameID"'"}}]}'
resok='(.error|not) and (.result.address | length == '"$count"')' resok='(.error|not) and (.result.address | length == '"$count"')'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
} }
lottery_GetLotteryHistoryLuckyNumber() { lottery_GetLotteryHistoryLuckyNumber() {
...@@ -151,8 +151,8 @@ lottery_GetLotteryHistoryLuckyNumber() { ...@@ -151,8 +151,8 @@ lottery_GetLotteryHistoryLuckyNumber() {
count=$2 count=$2
lucky=$3 lucky=$3
req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryHistoryLuckyNumber","payload":{"lotteryId":"'"$gameID"'"}}]}' req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryHistoryLuckyNumber","payload":{"lotteryId":"'"$gameID"'"}}]}'
resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$lucky"'")' resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$lucky"'")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
} }
lottery_GetLotteryRoundLuckyNumber() { lottery_GetLotteryRoundLuckyNumber() {
...@@ -160,8 +160,8 @@ lottery_GetLotteryRoundLuckyNumber() { ...@@ -160,8 +160,8 @@ lottery_GetLotteryRoundLuckyNumber() {
round=$2 round=$2
lucky=$3 lucky=$3
req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryRoundLuckyNumber","payload":{"lotteryId":"'"$gameID"'", "round":['"$round"']}}]}' req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryRoundLuckyNumber","payload":{"lotteryId":"'"$gameID"'", "round":['"$round"']}}]}'
resok='(.error|not) and (.result.records | length == 1) and (.result.records[0].number == "'"$lucky"'")' resok='(.error|not) and (.result.records | length == 1) and (.result.records[0].number == "'"$lucky"'")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
} }
lottery_GetLotteryHistoryBuyInfo() { lottery_GetLotteryHistoryBuyInfo() {
...@@ -170,8 +170,8 @@ lottery_GetLotteryHistoryBuyInfo() { ...@@ -170,8 +170,8 @@ lottery_GetLotteryHistoryBuyInfo() {
count=$3 count=$3
number=$4 number=$4
req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryHistoryBuyInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'"}}]}' req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryHistoryBuyInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'"}}]}'
resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$number"'")' resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$number"'")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
} }
lottery_GetLotteryBuyRoundInfo() { lottery_GetLotteryBuyRoundInfo() {
...@@ -181,8 +181,8 @@ lottery_GetLotteryBuyRoundInfo() { ...@@ -181,8 +181,8 @@ lottery_GetLotteryBuyRoundInfo() {
count=$4 count=$4
number=$5 number=$5
req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryBuyRoundInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'", "round":'"$round"'}}]}' req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryBuyRoundInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'", "round":'"$round"'}}]}'
resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$number"'")' resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$number"'")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
} }
lottery_GetLotteryHistoryGainInfo() { lottery_GetLotteryHistoryGainInfo() {
...@@ -191,8 +191,8 @@ lottery_GetLotteryHistoryGainInfo() { ...@@ -191,8 +191,8 @@ lottery_GetLotteryHistoryGainInfo() {
count=$3 count=$3
amount=$4 amount=$4
req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryHistoryGainInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'"}}]}' req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryHistoryGainInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'"}}]}'
resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].addr == "'"$addr"'") and (.result.records[0].buyAmount == "'"$amount"'")' resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].addr == "'"$addr"'") and (.result.records[0].buyAmount == "'"$amount"'")'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
} }
lottery_GetLotteryRoundGainInfo() { lottery_GetLotteryRoundGainInfo() {
...@@ -201,8 +201,8 @@ lottery_GetLotteryRoundGainInfo() { ...@@ -201,8 +201,8 @@ lottery_GetLotteryRoundGainInfo() {
round=$3 round=$3
amount=$4 amount=$4
req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryRoundGainInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'", "round":'"$round"'}}]}' req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryRoundGainInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'", "round":'"$round"'}}]}'
resok='(.error|not) and (.result.addr == "'"$addr"'") and (.result.round == "'"$round"'") and (.result.buyAmount == "'"$amount"'") and (.result | [has("fundAmount"), true] | unique | length == 1)' resok='(.error|not) and (.result.addr == "'"$addr"'") and (.result.round == "'"$round"'") and (.result.buyAmount == "'"$amount"'") and (.result | [has("fundAmount"), true] | unique | length == 1)'
http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" http_req "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
} }
function run_testcases() { function run_testcases() {
...@@ -268,4 +268,4 @@ function main() { ...@@ -268,4 +268,4 @@ function main() {
chain33_RpcTestRst lottery "$CASE_ERR" chain33_RpcTestRst lottery "$CASE_ERR"
} }
chain33_debug_function main "$1" chain33_debug_function main "$1"
\ No newline at end of file
...@@ -78,7 +78,7 @@ function multisig_AccCreateTx() { ...@@ -78,7 +78,7 @@ function multisig_AccCreateTx() {
#获取创建的多重签名地址 #获取创建的多重签名地址
multisigAccAddr=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccounts","payload":{"start":"0","end":"0"}}]}' ${MAIN_HTTP} | jq -r ".result.address[0]") multisigAccAddr=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccounts","payload":{"start":"0","end":"0"}}]}' ${MAIN_HTTP} | jq -r ".result.address[0]")
# echo "multisigAccAddr=$multisigAccAddr" # echo "multisigAccAddr=$multisigAccAddr"
#多重签名地址查询具体信息 #多重签名地址查询具体信息
req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccountInfo","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}' req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccountInfo","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}'
......
...@@ -118,4 +118,4 @@ function main() { ...@@ -118,4 +118,4 @@ function main() {
chain33_RpcTestRst pokerbull "$CASE_ERR" chain33_RpcTestRst pokerbull "$CASE_ERR"
} }
chain33_debug_function main "$1" chain33_debug_function main "$1"
\ No newline at end of file
...@@ -34,7 +34,7 @@ execName="token" ...@@ -34,7 +34,7 @@ execName="token"
function queryTransaction() { function queryTransaction() {
validator=$1 validator=$1
expectRes=$2 expectRes=$2
# echo "txhash=${RAW_TX_HASH}" # echo "txhash=${RAW_TX_HASH}"
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}") 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
...@@ -45,7 +45,7 @@ function queryTransaction() { ...@@ -45,7 +45,7 @@ function queryTransaction() {
function signRawTxAndQuery() { function signRawTxAndQuery() {
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}" chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
# txHash=$RAW_TX_HASH # txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true" queryTransaction ".error | not" "true"
echo_rst "$1 queryExecRes" "$?" echo_rst "$1 queryExecRes" "$?"
} }
...@@ -226,7 +226,7 @@ function token_withdraw() { ...@@ -226,7 +226,7 @@ function token_withdraw() {
function run_test() { function run_test() {
local ip=$1 local ip=$1
# set -x # set -x
token_preCreate token_preCreate
token_getPreCreated token_getPreCreated
...@@ -240,7 +240,7 @@ function run_test() { ...@@ -240,7 +240,7 @@ function run_test() {
token_sendExec token_sendExec
token_assets token_assets
token_withdraw token_withdraw
# set +x # set +x
} }
function main() { function main() {
......
...@@ -15,7 +15,7 @@ function query_unfreezeID() { ...@@ -15,7 +15,7 @@ function query_unfreezeID() {
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))
...@@ -121,4 +121,4 @@ function rpc_test() { ...@@ -121,4 +121,4 @@ function rpc_test() {
chain33_RpcTestRst unfreeze "$CASE_ERR" chain33_RpcTestRst unfreeze "$CASE_ERR"
} }
chain33_debug_function rpc_test "$1" chain33_debug_function rpc_test "$1"
\ No newline at end of file
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