Commit 16c1e821 authored by pengjun's avatar pengjun

add main_http to dapp-test-common

parent 2ca56fdf
#!/usr/bin/env bash #!/usr/bin/env bash
RAW_TX_HASH="" RAW_TX_HASH=""
CASE_ERR=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
echo_rst() { echo_rst() {
if [ "$2" -eq 0 ]; then if [ "$2" -eq 0 ]; then
echo -e "${GRE}$1 ok${NOC}" echo -e "${GRE}$1 ok${NOC}"
elif [ "$2" -eq 2 ]; then elif [ "$2" -eq 2 ]; then
echo -e "${GRE}$1 not support${NOC}" echo -e "${GRE}$1 not support${NOC}"
CASE_ERR="err"
else else
echo -e "${RED}$1 fail${NOC}" echo -e "${RED}$1 fail${NOC}"
CASE_ERR="err"
fi fi
} }
chain33_BlockWait() { chain33_BlockWait() {
local MAIN_HTTP=$2
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}))
...@@ -30,7 +40,8 @@ chain33_BlockWait() { ...@@ -30,7 +40,8 @@ chain33_BlockWait() {
} }
chain33_QueryTx() { chain33_QueryTx() {
chain33_BlockWait 1 local MAIN_HTTP=$2
chain33_BlockWait 1 $MAIN_HTTP
local txhash="$1" local txhash="$1"
local req='"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]' local req='"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]'
...@@ -38,7 +49,7 @@ chain33_QueryTx() { ...@@ -38,7 +49,7 @@ chain33_QueryTx() {
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")
if [ "${ret}" != "${1}" ]; then if [ "${ret}" != "${1}" ]; then
chain33_BlockWait 1 chain33_BlockWait 1 $MAIN_HTTP
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"
...@@ -55,6 +66,7 @@ chain33_QueryTx() { ...@@ -55,6 +66,7 @@ chain33_QueryTx() {
chain33_SendTx() { chain33_SendTx() {
local signedTx=$1 local signedTx=$1
local MAIN_HTTP=$2
req='"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'"$signedTx"'"}]' req='"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'"$signedTx"'"}]'
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
...@@ -62,7 +74,7 @@ chain33_SendTx() { ...@@ -62,7 +74,7 @@ chain33_SendTx() {
txhash=$(jq -r ".result" <<<"$resp") txhash=$(jq -r ".result" <<<"$resp")
if [ "$err" == null ]; then if [ "$err" == null ]; then
chain33_QueryTx "$txhash" chain33_QueryTx "$txhash" "$MAIN_HTTP"
else else
echo "send tx error:$err" echo "send tx error:$err"
fi fi
...@@ -72,6 +84,7 @@ chain33_SendToAddress() { ...@@ -72,6 +84,7 @@ chain33_SendToAddress() {
local from="$1" local from="$1"
local to="$2" local to="$2"
local amount=$3 local amount=$3
local MAIN_HTTP=$4
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}")
...@@ -80,13 +93,14 @@ chain33_SendToAddress() { ...@@ -80,13 +93,14 @@ chain33_SendToAddress() {
[ "$ok" == true ] [ "$ok" == true ]
hash=$(jq -r ".result.hash" <<<"$resp") hash=$(jq -r ".result.hash" <<<"$resp")
chain33_QueryTx "$hash" chain33_QueryTx "$hash" "$MAIN_HTTP"
} }
chain33_ImportPrivkey() { chain33_ImportPrivkey() {
local pri="$1" local pri="$1"
local acc="$2" local acc="$2"
local label="$3" local label="$3"
local MAIN_HTTP=$4
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")
...@@ -98,6 +112,7 @@ chain33_ImportPrivkey() { ...@@ -98,6 +112,7 @@ chain33_ImportPrivkey() {
chain33_SignRawTx() { chain33_SignRawTx() {
local txHex="$1" local txHex="$1"
local priKey="$2" local priKey="$2"
local MAIN_HTTP=$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")
......
...@@ -4,14 +4,8 @@ set -e ...@@ -4,14 +4,8 @@ set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
GAME_ID="" GAME_ID=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
source ../dapp-test-common.sh source ../dapp-test-common.sh
pokerbull_PlayRawTx() { pokerbull_PlayRawTx() {
...@@ -24,10 +18,10 @@ pokerbull_PlayRawTx() { ...@@ -24,10 +18,10 @@ pokerbull_PlayRawTx() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "play" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
echo "========== # pokerbull play tx end ==========" echo "========== # pokerbull play tx end =========="
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
pokerbull_QuitRawTx() { pokerbull_QuitRawTx() {
...@@ -40,10 +34,10 @@ pokerbull_QuitRawTx() { ...@@ -40,10 +34,10 @@ pokerbull_QuitRawTx() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "quit" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
echo "========== # pokerbull quit tx end ==========" echo "========== # pokerbull quit tx end =========="
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
pokerbull_ContinueRawTx() { pokerbull_ContinueRawTx() {
...@@ -56,10 +50,10 @@ pokerbull_ContinueRawTx() { ...@@ -56,10 +50,10 @@ pokerbull_ContinueRawTx() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" "continue" chain33_SignRawTx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" ${MAIN_HTTP}
echo "========== # pokerbull continue tx end ==========" echo "========== # pokerbull continue tx end =========="
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
pokerbull_StartRawTx() { pokerbull_StartRawTx() {
...@@ -72,11 +66,11 @@ pokerbull_StartRawTx() { ...@@ -72,11 +66,11 @@ pokerbull_StartRawTx() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "start" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
GAME_ID=$RAW_TX_HASH GAME_ID=$RAW_TX_HASH
echo "========== # pokerbull start tx end ==========" echo "========== # pokerbull start tx end =========="
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
pokerbull_QueryResult() { pokerbull_QueryResult() {
...@@ -108,11 +102,11 @@ init() { ...@@ -108,11 +102,11 @@ init() {
fi fi
local from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo" local from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000 chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000 ${MAIN_HTTP}
from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX" from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000 chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000 ${MAIN_HTTP}
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
function run_test() { function run_test() {
......
...@@ -4,12 +4,6 @@ set -e ...@@ -4,12 +4,6 @@ set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
source ../dapp-test-common.sh source ../dapp-test-common.sh
...@@ -26,10 +20,10 @@ retrieve_Backup() { ...@@ -26,10 +20,10 @@ retrieve_Backup() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
echo "========== # retrieve backup end ==========" echo "========== # retrieve backup end =========="
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
retrieve_Prepare() { retrieve_Prepare() {
...@@ -45,10 +39,10 @@ retrieve_Prepare() { ...@@ -45,10 +39,10 @@ retrieve_Prepare() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" chain33_SignRawTx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" ${MAIN_HTTP}
echo "========== # retrieve prepare end ==========" echo "========== # retrieve prepare end =========="
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
retrieve_Perform() { retrieve_Perform() {
...@@ -64,10 +58,10 @@ retrieve_Perform() { ...@@ -64,10 +58,10 @@ retrieve_Perform() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" chain33_SignRawTx "$tx" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" ${MAIN_HTTP}
echo "========== # retrieve perform end ==========" echo "========== # retrieve perform end =========="
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
retrieve_Cancel() { retrieve_Cancel() {
...@@ -83,10 +77,10 @@ retrieve_Cancel() { ...@@ -83,10 +77,10 @@ retrieve_Cancel() {
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" chain33_SignRawTx "$tx" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
echo "========== # retrieve cancel end ==========" echo "========== # retrieve cancel end =========="
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
retrieve_QueryResult() { retrieve_QueryResult() {
...@@ -113,11 +107,11 @@ init() { ...@@ -113,11 +107,11 @@ init() {
fi fi
local from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo" local from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
chain33_SendToAddress "$from" "$retrieve_addr" 1000000000 chain33_SendToAddress "$from" "$retrieve_addr" 1000000000 ${MAIN_HTTP}
from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX" from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
chain33_SendToAddress "$from" "$retrieve_addr" 1000000000 chain33_SendToAddress "$from" "$retrieve_addr" 1000000000 ${MAIN_HTTP}
chain33_BlockWait 1 chain33_BlockWait 1 ${MAIN_HTTP}
} }
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