Commit 85da1d4f authored by pengjun's avatar pengjun

fix rpc-test

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