Commit 16c1e821 authored by pengjun's avatar pengjun

add main_http to dapp-test-common

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