Commit 85da1d4f authored by pengjun's avatar pengjun

fix rpc-test

parent 4d5579cb
#!/usr/bin/env bash #!/usr/bin/env bash
RAW_TX_HASH=""
echo_rst() { echo_rst() {
if [ "$2" == 0 ]; then if [ "$2" -eq 0 ]; then
echo -e "${GRE}$1 ok${NOC}" echo -e "${GRE}$1 ok${NOC}"
elif [ "$2" -eq 2 ]; then
echo -e "${GRE}$1 not support${NOC}"
else else
echo -e "${RED}$1 fail${NOC}" echo -e "${RED}$1 fail${NOC}"
CASE_ERR="FAIL"
fi fi
} }
function block_wait() { chain33_BlockWait() {
local req='"method":"Chain33.GetLastHeader","params":[]' local req='"method":"Chain33.GetLastHeader","params":[]'
cur_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height") cur_height=$(curl -ksd "{$req}" "${MAIN_HTTP}" | jq ".result.height")
expect=$((cur_height + ${1})) expect=$((cur_height + ${1}))
local count=0 local count=0
while true; do while true; do
new_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height") new_height=$(curl -ksd "{$req}" "${MAIN_HTTP}" | jq ".result.height")
if [ "${new_height}" -ge "${expect}" ]; then if [ "${new_height}" -ge "${expect}" ]; then
break break
fi fi
...@@ -26,89 +29,82 @@ function block_wait() { ...@@ -26,89 +29,82 @@ function block_wait() {
echo "wait new block $count s, cur height=$expect,old=$cur_height" echo "wait new block $count s, cur height=$expect,old=$cur_height"
} }
function query_tx() { chain33_QueryTx() {
block_wait 1 chain33_BlockWait 1
local txhash="$1" local txhash="$1"
local req='"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]' local req='"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]'
# echo "req=$req"
local times=10 local times=10
while true; do while true; do
ret=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result.tx.hash") ret=$(curl -ksd "{$req}" "${MAIN_HTTP}" | jq -r ".result.tx.hash")
echo "====query tx= ${1}, return=$ret "
if [ "${ret}" != "${1}" ]; then if [ "${ret}" != "${1}" ]; then
block_wait 1 chain33_BlockWait 1
times=$((times - 1)) times=$((times - 1))
if [ $times -le 0 ]; then if [ $times -le 0 ]; then
echo "====query tx=$1 failed" echo "====query tx=$1 failed"
echo "req=$req" curl -ksd "{$req}" "${MAIN_HTTP}"
curl -ksd "{$req}" ${MAIN_HTTP}
exit 1 exit 1
fi fi
else else
echo "====query tx=$1 success" RAW_TX_HASH=$txhash
echo "====query tx=$RAW_TX_HASH success"
break break
fi fi
done done
} }
sendTx() { chain33_SendTx() {
echo "send tx '$1' begin" local signedTx=$1
signedTx=$1
type=$2 req='"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'"$signedTx"'"}]'
local req='"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'"$signedTx"'"}]' resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
err=$(jq '(.error)' <<<"$resp") err=$(jq '(.error)' <<<"$resp")
txhash=$(jq -r ".result" <<<"$resp") txhash=$(jq -r ".result" <<<"$resp")
if [ "$err" == null ]; then if [ "$err" == null ]; then
query_tx "$txhash" chain33_QueryTx "$txhash"
if [ "$type" == "start" ]; then
GAME_ID=$txhash
fi
else else
echo "send tx error:$err" echo "send tx error:$err"
fi fi
echo "send tx '$1' end"
} }
Chain33_SendToAddress() { chain33_SendToAddress() {
echo "send '$3' from '$1' to '$2' begin"
local from="$1" local from="$1"
local to="$2" local to="$2"
local amount=$3 local amount=$3
local req='"method":"Chain33.SendToAddress", "params":[{"from":"'"$from"'","to":"'"$to"'", "amount":'"$amount"', "note":"test\n"}]' local req='"method":"Chain33.SendToAddress", "params":[{"from":"'"$from"'","to":"'"$to"'", "amount":'"$amount"', "note":"test\n"}]'
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
ok=$(jq '(.error|not) and (.result.hash|length==66)' <<<"$resp") ok=$(jq '(.error|not) and (.result.hash|length==66)' <<<"$resp")
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
hash=$(jq -r ".result.hash" <<<"$resp") hash=$(jq -r ".result.hash" <<<"$resp")
query_tx "$hash" chain33_QueryTx "$hash"
echo "send '$3' from '$1' to '$2' end"
} }
chain33_ImportPrivkey() { chain33_ImportPrivkey() {
local pri=$2 local pri="$1"
local acc=$3 local acc="$2"
local req='"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'"$pri"'", "label":"pokerbullimportkey1"}]' local label="$3"
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$1")
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result.label=="pokerbullimportkey1") and (.result.acc.addr == "'"$acc"'")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
local req='"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'"$pri"'", "label":"'"$label"'"}]'
resp=$(curl -ksd "{$req}" "$MAIN_HTTP")
ok=$(jq '(.error|not) and (.result.label=="'"$label"'") and (.result.acc.addr == "'"$acc"'")' <<<"$resp")
[ "$ok" == true ]
} }
signrawtx() { chain33_SignRawTx() {
echo "sign tx '$1' begin" local txHex="$1"
txHex="$1" local priKey="$2"
priKey="$2"
type="$3"
local req='"method":"Chain33.SignRawTx","params":[{"privkey":"'"$priKey"'","txHex":"'"$txHex"'","expire":"120s"}]' local req='"method":"Chain33.SignRawTx","params":[{"privkey":"'"$priKey"'","txHex":"'"$txHex"'","expire":"120s"}]'
signedTx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result") signedTx=$(curl -ksd "{$req}" "${MAIN_HTTP}" | jq -r ".result")
if [ "$signedTx" != null ]; then if [ "$signedTx" != null ]; then
sendTx "$signedTx" "$3" chain33_SendTx "$signedTx" "${MAIN_HTTP}"
else else
echo "signedTx null error" echo "signedTx null error"
fi fi
echo "sign tx '$1' end"
} }
\ No newline at end of file
...@@ -24,10 +24,10 @@ pokerbull_PlayRawTx() { ...@@ -24,10 +24,10 @@ pokerbull_PlayRawTx() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
signrawtx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "play" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "play"
echo "========== # pokerbull play tx end ==========" echo "========== # pokerbull play tx end =========="
block_wait 1 chain33_BlockWait 1
} }
pokerbull_QuitRawTx() { pokerbull_QuitRawTx() {
...@@ -40,10 +40,10 @@ pokerbull_QuitRawTx() { ...@@ -40,10 +40,10 @@ pokerbull_QuitRawTx() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
signrawtx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "quit" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "quit"
echo "========== # pokerbull quit tx end ==========" echo "========== # pokerbull quit tx end =========="
block_wait 1 chain33_BlockWait 1
} }
pokerbull_ContinueRawTx() { pokerbull_ContinueRawTx() {
...@@ -56,10 +56,10 @@ pokerbull_ContinueRawTx() { ...@@ -56,10 +56,10 @@ pokerbull_ContinueRawTx() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
signrawtx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" "continue" chain33_SignRawTx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" "continue"
echo "========== # pokerbull continue tx end ==========" echo "========== # pokerbull continue tx end =========="
block_wait 1 chain33_BlockWait 1
} }
pokerbull_StartRawTx() { pokerbull_StartRawTx() {
...@@ -72,16 +72,18 @@ pokerbull_StartRawTx() { ...@@ -72,16 +72,18 @@ pokerbull_StartRawTx() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
signrawtx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "start" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "start"
GAME_ID=$RAW_TX_HASH
echo "========== # pokerbull start tx end ==========" echo "========== # pokerbull start tx end =========="
block_wait 1 chain33_BlockWait 1
} }
pokerbull_QueryResult() { pokerbull_QueryResult() {
echo "========== # pokerbull query result begin ==========" echo "========== # pokerbull query result begin =========="
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result") local req='"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]'
ok=$(jq '(.game.gameId == "'$GAME_ID'")' <<<"$data") data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
ok=$(jq '(.game.gameId == "$GAME_ID")' <<<"$data")
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
...@@ -104,14 +106,13 @@ init() { ...@@ -104,14 +106,13 @@ init() {
else else
pokerbull_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"pokerbull"}]}' ${MAIN_HTTP} | jq -r ".result") pokerbull_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"pokerbull"}]}' ${MAIN_HTTP} | jq -r ".result")
fi fi
echo "pokerbulladdr=$pokerbull_addr"
from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo" local from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
Chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000 chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000
from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX" from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
Chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000 chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000
block_wait 1 chain33_BlockWait 1
} }
function run_test() { function run_test() {
......
...@@ -16,77 +16,77 @@ source ../dapp-test-common.sh ...@@ -16,77 +16,77 @@ source ../dapp-test-common.sh
retrieve_Backup() { retrieve_Backup() {
echo "========== # retrieve backup begin ==========" echo "========== # retrieve backup begin =========="
req='"method":"retrieve.CreateRawRetrieveBackupTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo","delayPeriod": 61}]' local req='"method":"retrieve.CreateRawRetrieveBackupTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo","delayPeriod": 61}]'
tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
reqDecode='"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]' local reqDecode='"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]'
data=$(curl -ksd "{$reqDecode}" ${MAIN_HTTP} | jq -r ".result.txs[0]") data=$(curl -ksd "{$reqDecode}" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data") ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
signrawtx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138"
echo "========== # retrieve backup end ==========" echo "========== # retrieve backup end =========="
block_wait 1 chain33_BlockWait 1
} }
retrieve_Prepare() { retrieve_Prepare() {
echo "========== # retrieve prepare begin ==========" echo "========== # retrieve prepare begin =========="
req='"method":"retrieve.CreateRawRetrievePrepareTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}]' local req='"method":"retrieve.CreateRawRetrievePrepareTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}]'
tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
reqDecode='"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]' local reqDecode='"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]'
data=$(curl -ksd "{$reqDecode}" ${MAIN_HTTP} | jq -r ".result.txs[0]") data=$(curl -ksd "{$reqDecode}" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data") ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
signrawtx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" chain33_SignRawTx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989"
echo "========== # retrieve prepare end ==========" echo "========== # retrieve prepare end =========="
block_wait 1 chain33_BlockWait 1
} }
retrieve_Perform() { retrieve_Perform() {
echo "========== # retrieve perform begin ==========" echo "========== # retrieve perform begin =========="
req='"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}]' local req='"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}]'
tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
reqDecode='"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]' local reqDecode='"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]'
data=$(curl -ksd "{$reqDecode}" ${MAIN_HTTP} | jq -r ".result.txs[0]") data=$(curl -ksd "{$reqDecode}" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data") ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
signrawtx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" chain33_SignRawTx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989"
echo "========== # retrieve perform end ==========" echo "========== # retrieve perform end =========="
block_wait 1 chain33_BlockWait 1
} }
retrieve_Cancel() { retrieve_Cancel() {
echo "========== # retrieve cancel begin ==========" echo "========== # retrieve cancel begin =========="
req='"method":"retrieve.CreateRawRetrieveCancelTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}]' local req='"method":"retrieve.CreateRawRetrieveCancelTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}]'
tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
reqDecode='"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]' local reqDecode='"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]'
data=$(curl -ksd "{$reqDecode}" ${MAIN_HTTP} | jq -r ".result.txs[0]") data=$(curl -ksd "{$reqDecode}" ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data") ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
signrawtx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138"
echo "========== # retrieve cancel end ==========" echo "========== # retrieve cancel end =========="
block_wait 1 chain33_BlockWait 1
} }
retrieve_QueryResult() { retrieve_QueryResult() {
...@@ -94,7 +94,7 @@ retrieve_QueryResult() { ...@@ -94,7 +94,7 @@ retrieve_QueryResult() {
local status=$1 local status=$1
req='"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX", "defaultAddress":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}}]' local req='"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX", "defaultAddress":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}}]'
data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result") data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
ok=$(jq '(.status == '"$status"')' <<<"$data") ok=$(jq '(.status == '"$status"')' <<<"$data")
...@@ -111,14 +111,13 @@ init() { ...@@ -111,14 +111,13 @@ init() {
else else
retrieve_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"retrieve"}]}' ${MAIN_HTTP} | jq -r ".result") retrieve_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"retrieve"}]}' ${MAIN_HTTP} | jq -r ".result")
fi fi
echo "retrieveaddr=$retrieve_addr"
from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo" local from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
Chain33_SendToAddress "$from" "$retrieve_addr" 1000000000 chain33_SendToAddress "$from" "$retrieve_addr" 1000000000
from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX" from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
Chain33_SendToAddress "$from" "$retrieve_addr" 1000000000 chain33_SendToAddress "$from" "$retrieve_addr" 1000000000
block_wait 1 chain33_BlockWait 1
} }
function run_test() { function run_test() {
......
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