Commit 3c36f2a0 authored by 张振华's avatar 张振华

merge

parents 5d0cd437 586d3ebf
...@@ -106,7 +106,7 @@ chain33_ImportPrivkey() { ...@@ -106,7 +106,7 @@ chain33_ImportPrivkey() {
local req='"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'"$pri"'", "label":"'"$label"'"}]' local req='"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'"$pri"'", "label":"'"$label"'"}]'
resp=$(curl -ksd "{$req}" "$MAIN_HTTP") resp=$(curl -ksd "{$req}" "$MAIN_HTTP")
ok=$(jq '(.error|not) and (.result.label=="'"$label"'") and (.result.acc.addr == "'"$acc"'")' <<<"$resp") ok=$(jq '(((.error|not) and (.result.label=="'"$label"'") and (.result.acc.addr == "'"$acc"'")) or (.error=="ErrPrivkeyExist"))' <<<"$resp")
[ "$ok" == true ] [ "$ok" == true ]
} }
...@@ -138,3 +138,16 @@ chain33_QueryBalance() { ...@@ -138,3 +138,16 @@ chain33_QueryBalance() {
echo "$resp" | jq -r ".result" echo "$resp" | jq -r ".result"
} }
chain33_QueryExecBalance() {
local addr=$1
local exec=$2
local MAIN_HTTP=$3
req='{"method":"Chain33.GetBalance", "params":[{"addresses" : ["'"${addr}"'"], "execer" : "'"${exec}"'"}]}'
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result[0] | [has("balance", "frozen"), true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
}
...@@ -4,31 +4,20 @@ set -e ...@@ -4,31 +4,20 @@ set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
GAME_ID="" GAME_ID=""
PASSWD="ABCD" PASSWD="ABCD"
HASH_VALUE=$(echo -n "ABCD1" | sha256sum | awk '{print $1}') HASH_VALUE=$(echo -n "ABCD1" | sha256sum | awk '{print $1}')
signedTx=""
txHash="" ACCOUNT_A="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
ACCOUNT_A="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt" PRIVA_A="56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138"
# PRIVA_A="cc38546e9e659d15e6b4893f0ab32a06d103931a8230b0bde71459d2b27d6944"
ACCOUNT_B="19MJmA7GcE1NfMwdGqgLJioBjVbzQnVYvR" ACCOUNT_B="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
PRIVA_B="5072a3b6ed612845a7c00b88b38e4564093f57ce652212d6e26da9fded83e951" PRIVA_B="2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989"
EXECTOR="" EXECTOR=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
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
} # shellcheck source=/dev/null
source ../dapp-test-common.sh
function chain33_GetExecAddr() { function chain33_GetExecAddr() {
#获取GAME合约地址 #获取GAME合约地址
...@@ -44,41 +33,36 @@ function chain33_GetExecAddr() { ...@@ -44,41 +33,36 @@ function chain33_GetExecAddr() {
function CreateGameTx() { function CreateGameTx() {
local amount=$1 local amount=$1
local hash_value=$2 local hash_value=$2
local addr=$3
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" echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp" echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result") rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then if [ "$rawTx" == "null" ]; then
echo_rst "CreateGame createRawTx" 1 echo_rst "CreateGame createRawTx" 1
fi fi
signRawTx "${rawTx}" "${ACCOUNT_A}"
echo_rst "CreateGame signRawTx" "$?" chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
sendSignedTx GAME_ID=$RAW_TX_HASH
echo_rst "CreateGame sendSignedTx" "$?"
GAME_ID="${txHash}"
# create_txHash="${txHash}"
query_tx "${txHash}"
echo_rst "CreateGame query_tx" "$?" echo_rst "CreateGame query_tx" "$?"
} }
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}}]'
echo "#request: $req" echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp" echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result") rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then if [ "$rawTx" == "null" ]; then
echo_rst "MatchGame createRawTx" 1 echo_rst "MatchGame createRawTx" 1
fi fi
signRawTx "${rawTx}" "${ACCOUNT_B}"
echo_rst "MatchGame signRawTx" "$?" chain33_SignRawTx "${rawTx}" "${PRIVA_B}" "${MAIN_HTTP}"
sendSignedTx
echo_rst "MatchGame sendSignedTx" "$?"
# match_txHash="${txHash}"
query_tx "${txHash}"
echo_rst "MatchGame query_tx" "$?" echo_rst "MatchGame query_tx" "$?"
} }
...@@ -86,37 +70,34 @@ function CloseGameTx() { ...@@ -86,37 +70,34 @@ 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" echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp" echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result") rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then if [ "$rawTx" == "null" ]; then
echo_rst "CloseGame createRawTx" 1 echo_rst "CloseGame createRawTx" 1
fi fi
signRawTx "${rawTx}" "${ACCOUNT_A}"
echo_rst "CloseGame signRawTx" "$?" chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
sendSignedTx
echo_rst "CloseGame sendSignedTx" "$?"
query_tx "${txHash}"
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" echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp" echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result") rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then if [ "$rawTx" == "null" ]; then
echo_rst "CancleGame createRawTx" 1 echo_rst "CancleGame createRawTx" 1
fi fi
signRawTx "${rawTx}" "${ACCOUNT_A}"
echo_rst "CancleGame signRawTx" "$?" chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
sendSignedTx
echo_rst "CancleGame sendSignedTx" "$?"
# close_txHash="${txHash}"
query_tx "${txHash}"
echo_rst "CancleGame query_tx" "$?" echo_rst "CancleGame query_tx" "$?"
} }
...@@ -147,118 +128,12 @@ function QueryGameByGameId() { ...@@ -147,118 +128,12 @@ function QueryGameByGameId() {
echo_rst "QueryGameByGameId" 0 echo_rst "QueryGameByGameId" 0
} }
function chain33_ImportPrivkey() {
local pri=$2
#local acc=$3
local req='"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'"$pri"'", "label":"gameB"}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$1")
echo "#response: $resp"
# ok=$(jq '(.error|not) and (.result.label=="gameB") and (.result.acc.addr == "'"$acc"'")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
}
function Chain33_SendToAddress() {
from=$1
to=$2
amount=$3
http=$4
note="test"
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.SendToAddress","params":[{"from":"'"$from"'","to":"'"$to"'","amount":'"$amount"',"note":"'"$note"'"}]}' -H 'content-type:text/plain;' "${http}")
ok=$(jq '(.error|not)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function chain33_unlock() {
ok=$(curl -k -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.UnLock","params":[{"passwd":"1314fuzamei","timeout":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.isOK")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function block_wait() {
local req='"method":"Chain33.GetLastHeader","params":[]'
cur_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height")
expect=$((cur_height + ${1}))
local count=0
while true; do
new_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height")
if [ "${new_height}" -ge "${expect}" ]; then
break
fi
count=$((count + 1))
sleep 1
done
echo "wait new block $count s, cur height=$expect,old=$cur_height"
}
function signRawTx() {
unsignedTx=$1
addr=$2
signedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.SignRawTx","params":[{"addr":"'"${addr}"'","txHex":"'"${unsignedTx}"'","expire":"120s","fee":1000000}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
if [ "$signedTx" == "null" ]; then
return 1
else
return 0
fi
}
function sendSignedTx() {
txHash=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.SendTransaction","params":[{"token":"","data":"'"${signedTx}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
if [ "$txHash" == "null" ]; then
return 1
else
return 0
fi
}
function query_tx() {
block_wait 1
txhash="$1"
# echo "req=$req"
local times=10
while true; do
req='{"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]}'
ret=$(curl -ksd "$req" ${MAIN_HTTP})
tx=$(jq -r ".result.tx.hash" <<<"$ret")
echo "====query tx= ${1}, return=$ret "
if [ "${tx}" != "${1}" ]; then
block_wait 1
times=$((times - 1))
if [ $times -le 0 ]; then
echo "====query tx=$1 failed"
echo "req=$req"
curl -ksd "$req" ${MAIN_HTTP}
exit 1
fi
else
exec_err=$(jq '(.result.receipt.logs[0].tyName == "LogErr")' <<<"$ret")
[ "$exec_err" != true ]
echo "====query tx=$1 success"
break
fi
done
}
function init() { function init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")') ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara" echo "ipara=$ispara"
from="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
chain33_ImportPrivkey "${MAIN_HTTP}" "${PRIVA_B}" "${ACCOUNT_B}"
local game_addr="" local game_addr=""
if [ "$ispara" == "true" ]; then if [ "$ispara" == "true" ]; then
#主链中相应账户需要转帐
M_HTTP=${MAIN_HTTP//8901/8801}
Chain33_SendToAddress "${ACCOUNT_A}" "${ACCOUNT_B}" 20000000000 "${M_HTTP}"
block_wait 1
EXECTOR="user.p.para.game" EXECTOR="user.p.para.game"
game_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.game"}]}' ${MAIN_HTTP} | jq -r ".result") game_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.game"}]}' ${MAIN_HTTP} | jq -r ".result")
else else
...@@ -267,11 +142,11 @@ function init() { ...@@ -267,11 +142,11 @@ function init() {
fi fi
echo "gameAddr=${game_addr}" echo "gameAddr=${game_addr}"
Chain33_SendToAddress "${ACCOUNT_B}" "$game_addr" 5000000000 "${MAIN_HTTP}" chain33_SendToAddress "${ACCOUNT_B}" "$game_addr" 5000000000 "${MAIN_HTTP}"
Chain33_SendToAddress "${ACCOUNT_A}" "$game_addr" 5000000000 "${MAIN_HTTP}" chain33_SendToAddress "${ACCOUNT_A}" "$game_addr" 5000000000 "${MAIN_HTTP}"
block_wait 1 chain33_BlockWait 1 "$MAIN_HTTP"
} }
function run_test() { function run_test() {
...@@ -311,12 +186,7 @@ function main() { ...@@ -311,12 +186,7 @@ function main() {
echo "=========== # game rpc test =============" echo "=========== # game rpc test ============="
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
Chain33_SendToAddress "${ACCOUNT_A}" "${ACCOUNT_B}" 20000000000 "${MAIN_HTTP}"
block_wait 1
init init
run_test "$MAIN_HTTP" run_test "$MAIN_HTTP"
if [ -n "$CASE_ERR" ]; then if [ -n "$CASE_ERR" ]; then
......
all:
chmod +x ./build.sh
./build.sh $(OUT) $(FLAG)
\ No newline at end of file
#!/usr/bin/env bash
strpwd=$(pwd)
strcmd=${strpwd##*dapp/}
strapp=${strcmd%/cmd*}
OUT_DIR="${1}/$strapp"
#FLAG=$2
mkdir -p "${OUT_DIR}"
cp ./build/* "${OUT_DIR}"
OUT_TESTDIR="${1}/dapptest/$strapp"
mkdir -p "${OUT_TESTDIR}"
chmod +x ./build/test-rpc.sh
cp ./build/test-rpc.sh "${OUT_TESTDIR}"
#!/usr/bin/env bash
# shellcheck disable=SC2128
set -e
set -o pipefail
MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh
MAIN_HTTP=""
CASE_ERR=""
guess_admin_addr=12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
guess_user1_addr=1PUiGcbsccfxW3zuvHXZBJfznziph5miAo
guess_user2_addr=1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX
guess_addr=""
guess_exec=""
eventId=""
txhash=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
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")
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}"
echo "eventId $eventId"
echo "========== # guess start tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
}
guess_game_bet() {
local priv=$1
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")
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() {
echo "========== # guess stop tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"StopBet", "payload":{"gameID":"'"${eventId}"'"}}]}' ${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")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
echo "========== # guess stop tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
}
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")
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() {
echo "========== # guess abort tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Abort", "payload":{"gameID":"'"${eventId}"'"}}]}' ${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")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
echo "========== # guess abort tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
}
guess_QueryGameByID() {
local event_id=$1
local status=$2
echo "========== # guess QueryGameByID begin =========="
local req='"method":"Chain33.Query", "params":[{"execer":"guess","funcName":"QueryGameByID","payload":{"gameID":"'"$event_id"'"}}]'
#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() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara"
if [ "$ispara" == true ]; then
guess_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.guess"}]}' ${MAIN_HTTP} | jq -r ".result")
guess_exec="user.p.para.guess"
else
guess_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"guess"}]}' ${MAIN_HTTP} | jq -r ".result")
guess_exec="guess"
fi
echo "guess_addr=$guess_addr"
local from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
chain33_SendToAddress "$from" "$guess_addr" 10000000000 ${MAIN_HTTP}
from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
chain33_SendToAddress "$from" "$guess_addr" 10000000000 ${MAIN_HTTP}
chain33_BlockWait 1 "${MAIN_HTTP}"
}
function run_test() {
#导入地址私钥
chain33_ImportPrivkey "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "1PUiGcbsccfxW3zuvHXZBJfznziph5miAo" "user1" "$MAIN_HTTP"
chain33_ImportPrivkey "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" "1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX" "user2" "$MAIN_HTTP"
chain33_ImportPrivkey "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" "admin" "$MAIN_HTTP"
chain33_QueryBalance "${guess_admin_addr}" "$MAIN_HTTP"
chain33_QueryBalance "${guess_user1_addr}" "$MAIN_HTTP"
chain33_QueryBalance "${guess_user2_addr}" "$MAIN_HTTP"
chain33_QueryExecBalance "${guess_user1_addr}" "${guess_exec}" "$MAIN_HTTP"
chain33_QueryExecBalance "${guess_user2_addr}" "${guess_exec}" "$MAIN_HTTP"
#场景1:start -> bet -> bet -> stop -> publish
#管理员创建游戏
guess_game_start
#查询游戏状态
guess_QueryGameByID "$eventId" 11
#用户1下注
guess_game_bet "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "A"
#查询游戏状态
guess_QueryGameByID "$eventId" 12
#用户2下注
guess_game_bet "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" "B"
#查询游戏状态
guess_QueryGameByID "$eventId" 12
#管理员停止下注
guess_game_stop
#查询游戏状态
guess_QueryGameByID "$eventId" 13
#管理员发布结果
guess_game_publish
#查询游戏状态
guess_QueryGameByID "$eventId" 15
#查询余额
chain33_QueryExecBalance "${guess_user1_addr}" "${guess_exec}" "$MAIN_HTTP"
chain33_QueryExecBalance "${guess_user2_addr}" "${guess_exec}" "$MAIN_HTTP"
#场景2:start->stop->abort
guess_game_start
#查询游戏状态
guess_QueryGameByID "$eventId" 11
#管理员停止下注
guess_game_stop
#查询游戏状态
guess_QueryGameByID "$eventId" 13
#管理员发布结果
guess_game_abort
#查询游戏状态
guess_QueryGameByID "$eventId" 14
#场景3:start->abort
guess_game_start
#查询游戏状态
guess_QueryGameByID "$eventId" 11
#管理员发布结果
guess_game_abort
#查询游戏状态
guess_QueryGameByID "$eventId" 14
#场景4:start->bet->abort
#管理员创建游戏
guess_game_start
#查询游戏状态
guess_QueryGameByID "$eventId" 11
#用户1下注
guess_game_bet "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "A"
#查询游戏状态
guess_QueryGameByID "$eventId" 12
#用户2下注
guess_game_bet "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" "B"
#查询游戏状态
guess_QueryGameByID "$eventId" 12
#管理员发布结果
guess_game_abort
#查询游戏状态
guess_QueryGameByID "$eventId" 14
#场景5:start->bet->stop->abort
#管理员创建游戏
guess_game_start
#查询游戏状态
guess_QueryGameByID "$eventId" 11
#用户1下注
guess_game_bet "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "A"
#查询游戏状态
guess_QueryGameByID "$eventId" 12
#用户2下注
guess_game_bet "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" "B"
#查询游戏状态
guess_QueryGameByID "$eventId" 12
#管理员停止下注
guess_game_stop
#查询游戏状态
guess_QueryGameByID "$eventId" 13
#管理员发布结果
guess_game_abort
#查询游戏状态
guess_QueryGameByID "$eventId" 14
#查询余额
chain33_QueryExecBalance "${guess_user1_addr}" "${guess_exec}" "$MAIN_HTTP"
chain33_QueryExecBalance "${guess_user2_addr}" "${guess_exec}" "$MAIN_HTTP"
}
function main() {
MAIN_HTTP="$1"
echo "main_ip=$MAIN_HTTP"
init
echo "=========== # guess rpc test start============="
run_test
if [ -n "$CASE_ERR" ]; then
echo -e "${RED}=============Guess Rpc Test Fail=============${NOC}"
exit 1
else
echo -e "${GRE}=============Guess Rpc Test Pass==============${NOC}"
fi
echo "=========== # guess rpc test end============="
}
main "$1"
...@@ -47,6 +47,11 @@ func GetName() string { ...@@ -47,6 +47,11 @@ func GetName() string {
return newGuessGame().GetName() return newGuessGame().GetName()
} }
//ExecutorOrder Exec 的时候 同时执行 ExecLocal
func (g *Guess) ExecutorOrder() int64 {
return drivers.ExecLocalSameTime
}
//GetDriverName 获取Guess执行器的名称 //GetDriverName 获取Guess执行器的名称
func (g *Guess) GetDriverName() string { func (g *Guess) GetDriverName() string {
return gty.GuessX return gty.GuessX
......
...@@ -2,36 +2,23 @@ ...@@ -2,36 +2,23 @@
# shellcheck disable=SC2128 # shellcheck disable=SC2128
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
oracle_addPublisher_unsignedTx="0a066d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630e6b685d696ee9394163a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32" oracle_addPublisher_unsignedTx="0a066d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630e6b685d696ee9394163a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32"
oracle_addPublisher_unsignedTx_para="0a12757365722e702e706172612e6d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630a186de8894c9aa864d3a22314469484633317577783977356a6a733571514269474a6b4e686e71656564763157" oracle_addPublisher_unsignedTx_para="0a12757365722e702e706172612e6d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630a186de8894c9aa864d3a22314469484633317577783977356a6a733571514269474a6b4e686e71656564763157"
oracle_publisher_addr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" oracle_publisher_key="4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01"
eventId="" eventId=""
txhash="" txhash=""
#color # shellcheck source=/dev/null
RED='\033[1;31m' source ../dapp-test-common.sh
GRE='\033[1;32m'
NOC='\033[0m'
# $2=0 means true, other false
echo_rst() {
if [ "$2" -eq 0 ]; then
echo -e "${GRE}$1 ok${NOC}"
else
echo -e "${RED}$1 fail${NOC}"
CASE_ERR="err"
fi
}
oracle_AddPublisher() { oracle_AddPublisher() {
echo "=============== # Add publisher ===============" echo "=============== # Add publisher ==============="
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
signAndSendRawTx "${oracle_addPublisher_unsignedTx_para}" "${oracle_publisher_addr}" chain33_SignRawTx "${oracle_addPublisher_unsignedTx_para}" "${oracle_publisher_key}" "${MAIN_HTTP}"
else else
signAndSendRawTx "${oracle_addPublisher_unsignedTx}" "${oracle_publisher_addr}" chain33_SignRawTx "${oracle_addPublisher_unsignedTx}" "${oracle_publisher_key}" "${MAIN_HTTP}"
fi fi
} }
...@@ -44,7 +31,7 @@ oracle_publish_transaction() { ...@@ -44,7 +31,7 @@ oracle_publish_transaction() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp") rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}" chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
eventId="${txhash}" eventId="${txhash}"
echo "eventId $eventId" echo "eventId $eventId"
} }
...@@ -59,7 +46,7 @@ oracle_prePublishResult_transaction() { ...@@ -59,7 +46,7 @@ oracle_prePublishResult_transaction() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp") rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}" chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_eventAbort_transaction() { oracle_eventAbort_transaction() {
...@@ -72,7 +59,7 @@ oracle_eventAbort_transaction() { ...@@ -72,7 +59,7 @@ oracle_eventAbort_transaction() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp") rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}" chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_resultAbort_transaction() { oracle_resultAbort_transaction() {
...@@ -85,7 +72,7 @@ oracle_resultAbort_transaction() { ...@@ -85,7 +72,7 @@ oracle_resultAbort_transaction() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp") rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}" chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_publishResult_transaction() { oracle_publishResult_transaction() {
...@@ -98,32 +85,7 @@ oracle_publishResult_transaction() { ...@@ -98,32 +85,7 @@ oracle_publishResult_transaction() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp") rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}" chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
}
# 签名并发送
signAndSendRawTx() {
unsignedTx=$1
addr=$2
req='"method":"Chain33.SignRawTx","params":[{"addr":"'${addr}'","txHex":"'${unsignedTx}'","expire":"120s"}]'
signedTx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
if [ "$signedTx" == "null" ]; then
echo "An error occurred while signing"
else
sendSignedTx "$signedTx"
fi
}
sendSignedTx() {
signedTx=$1
local req='"method":"Chain33.SendTransaction","params":[{"token":"","data":"'"$signedTx"'"}]'
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
ok=$(echo "${resp}" | jq -r ".error")
[ "$ok" == null ]
rst=$?
#echo_rst "$FUNCNAME" "$rst"
txhash=$(echo "${resp}" | jq -r ".result")
echo "tx hash is $txhash"
} }
oracle_QueryOraclesByID() { oracle_QueryOraclesByID() {
...@@ -138,47 +100,6 @@ oracle_QueryOraclesByID() { ...@@ -138,47 +100,6 @@ oracle_QueryOraclesByID() {
echo_rst "$FUNCNAME" "$rst" echo_rst "$FUNCNAME" "$rst"
} }
function block_wait() {
local req='"method":"Chain33.GetLastHeader","params":[]'
cur_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height")
expect=$((cur_height + ${1}))
local count=0
while true; do
new_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height")
if [ "${new_height}" -ge "${expect}" ]; then
break
fi
count=$((count + 1))
sleep 1
done
echo "wait new block $count s, cur height=$expect,old=$cur_height"
}
function queryTransaction() {
block_wait 1
local txhash="$1"
local req='"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]'
local times=10
while true; do
ret=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result.tx.hash")
if [ "${ret}" != "${1}" ]; then
block_wait 1
times=$((times - 1))
if [ $times -le 0 ]; then
echo "====query tx=$1 failed"
echo "req=$req"
curl -ksd "{$req}" ${MAIN_HTTP}
return 1
exit 1
fi
else
echo "====query tx=$1 success"
return 0
break
fi
done
}
function run_test() { function run_test() {
# 增加发布人 # 增加发布人
oracle_AddPublisher oracle_AddPublisher
...@@ -189,7 +110,7 @@ function run_test() { ...@@ -189,7 +110,7 @@ function run_test() {
# 事件正式发布 # 事件正式发布
oracle_publishResult_transaction "$eventId" oracle_publishResult_transaction "$eventId"
# 根据ID查询事件 # 根据ID查询事件
block_wait 2 chain33_BlockWait 2 "${MAIN_HTTP}"
oracle_QueryOraclesByID "$eventId" oracle_QueryOraclesByID "$eventId"
# 生成发布事件的交易 # 生成发布事件的交易
...@@ -197,7 +118,7 @@ function run_test() { ...@@ -197,7 +118,7 @@ function run_test() {
# 取消事件发布 # 取消事件发布
oracle_eventAbort_transaction "$eventId" oracle_eventAbort_transaction "$eventId"
# 根据ID查询事件 # 根据ID查询事件
block_wait 2 chain33_BlockWait 2 "${MAIN_HTTP}"
oracle_QueryOraclesByID "$eventId" oracle_QueryOraclesByID "$eventId"
# 生成发布事件的交易 # 生成发布事件的交易
...@@ -207,7 +128,7 @@ function run_test() { ...@@ -207,7 +128,7 @@ function run_test() {
# 取消事件预发布 # 取消事件预发布
oracle_resultAbort_transaction "$eventId" oracle_resultAbort_transaction "$eventId"
# 根据ID查询事件 # 根据ID查询事件
block_wait 2 chain33_BlockWait 2 "${MAIN_HTTP}"
oracle_QueryOraclesByID "$eventId" oracle_QueryOraclesByID "$eventId"
} }
......
...@@ -78,7 +78,11 @@ pokerbull_QueryResult() { ...@@ -78,7 +78,11 @@ pokerbull_QueryResult() {
echo "========== # pokerbull query result begin ==========" echo "========== # pokerbull query result begin =========="
local 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'"}}]'
data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result") data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
<<<<<<< HEAD
ok=$(jq '(.game.gameId == "'"$GAME_ID"'")' <<<"$data") ok=$(jq '(.game.gameId == "'"$GAME_ID"'")' <<<"$data")
=======
ok=$(jq '(.game.gameId == '"$GAME_ID"')' <<<"$data")
>>>>>>> master
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
......
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