Commit 02d27762 authored by liuyuhang's avatar liuyuhang

add rpc test

parent 39743d91
......@@ -29,6 +29,77 @@ chain33_unlock() {
echo_rst "$FUNCNAME" "$rst"
}
chain33_GetHexTxByHash() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetHexTxByHash","params":[{"hash":"","upgrade":false}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
[ "$result" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_QueryTransaction() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.QueryTransaction","params":[{"hash":"","upgrade":false}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
[ "$result" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_GetBlocks() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetBlocks","params":[{"start":0,"end":1}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error")
[ "$result" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_GetLastHeader() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetLastHeader","params":[{}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error")
[ "$result" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_GetTxByAddr() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetTxByAddr","params":[{"addr":"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt","flag":0,"count":1,"direction":0,"height":-1,"index":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error")
[ "$result" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_GetTxByHashes() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetTxByHashes","params":[{"hashes":["0x8040109d3859827d0f0c80ce91cc4ec80c496c45250f5e5755064b6da60842ab","0x501b910fd85d13d1ab7d776bce41a462f27c4bfeceb561dc47f0a11b10f452e4"]}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error")
[ "$result" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_GetMempool() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetMempool","params":[{}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error")
[ "$result" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_GetAccountsV2() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetAccountsV2","params":[{}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error")
[ "$result" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_GetAccounts() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetAccounts","params":[{}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error")
[ "$result" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_NewAccount() {
result=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.NewAccount","params":[{"label":"test111"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.label")
[ "$result" == "test111" ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function system_test_rpc() {
local ip=$1
MAIN_HTTP="http://$ip:8801"
......@@ -37,11 +108,20 @@ function system_test_rpc() {
chain33_lock
chain33_unlock
chain33_GetHexTxByHash
chain33_QueryTransaction
chain33_GetBlocks
chain33_GetLastHeader
chain33_GetTxByAddr
chain33_GetTxByHashes
chain33_GetMempool
chain33_GetAccountsV2
chain33_GetAccounts
chain33_NewAccount
if [ -n "$CASE_ERR" ]; then
echo "there some case error"
exit 1
fi
}
#system_rpc_test
......@@ -5,6 +5,7 @@ strcmd=${strpwd##*dapp/}
strapp=${strcmd%/cmd*}
OUT_DIR="${1}/$strapp"
OUT_TESTDIR="${1}/dapptest/$strapp"
PARACLI="${OUT_DIR}/chain33-para-cli"
PARANAME=para
......@@ -13,3 +14,6 @@ SRC_CLI=github.com/33cn/plugin/cli
go build -v -o "${PARACLI}" -ldflags "-X ${SRC_CLI}/buildflags.ParaName=user.p.${PARANAME}. -X ${SRC_CLI}/buildflags.RPCAddr=http://localhost:8901" "${SRC_CLI}"
# shellcheck disable=SC2086
cp ./build/* "${OUT_DIR}"
mkdir -p "${OUT_TESTDIR}"
cp ./test/* "${OUT_TESTDIR}"
......@@ -4,6 +4,7 @@
MAIN_HTTP=""
PARA_HTTP=""
CASE_ERR=""
UNIT_HTTP=""
# $2=0 means true, other false
echo_rst() {
......@@ -17,26 +18,41 @@ echo_rst() {
}
paracross_GetBlock2MainInfo() {
height=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.GetBlock2MainInfo","params":[{"start":1,"end":3}]}' -H 'content-type:text/plain;' ${PARA_HTTP} | jq -r ".result.items[1].height")
height=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"paracross.GetBlock2MainInfo","params":[{"start":1,"end":3}]}' -H 'content-type:text/plain;' ${UNIT_HTTP} | jq -r ".result.items[1].height")
[ "$height" -eq 2 ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_lock() {
ok=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Lock","params":[]}' -H 'content-type:text/plain;' ${PARA_HTTP} | jq -r ".result.isOK")
ok=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Lock","params":[]}' -H 'content-type:text/plain;' ${UNIT_HTTP} | jq -r ".result.isOK")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
chain33_unlock() {
ok=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.UnLock","params":[{"passwd":"1314fuzamei","timeout":0}]}' -H 'content-type:text/plain;' ${PARA_HTTP} | jq -r ".result.isOK")
ok=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.UnLock","params":[{"passwd":"1314fuzamei","timeout":0}]}' -H 'content-type:text/plain;' ${UNIT_HTTP} | jq -r ".result.isOK")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function run_main_testcases() {
chain33_lock
chain33_unlock
paracross_GetBlock2MainInfo
}
function run_para_testcases() {
chain33_lock
chain33_unlock
paracross_GetBlock2MainInfo
}
function dapp_rpc_test() {
local ip=$1
MAIN_HTTP="http://$ip:8801"
......@@ -44,9 +60,11 @@ function dapp_rpc_test() {
echo "=========== # paracross rpc test ============="
echo "main_ip=$MAIN_HTTP,para_ip=$PARA_HTTP"
chain33_lock
chain33_unlock
paracross_GetBlock2MainInfo
UNIT_HTTP=$MAIN_HTTP
run_main_testcases
UNIT_HTTP=$PARA_HTTP
run_para_testcases
if [ -n "$CASE_ERR" ]; then
echo "paracross there some case error"
......
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