Unverified Commit 06236086 authored by vipwzw's avatar vipwzw Committed by GitHub

Merge pull request #738 from YingQm/issue691_rpc_test_improve

rpc test 脚本改进
parents 88e98f0f 05ee2aa2
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
RAW_TX_HASH="" RAW_TX_HASH=""
LAST_BLOCK_HASH="" LAST_BLOCK_HASH=""
CASE_ERR="" CASE_ERR=""
RETURN_RESP=""
#color #color
RED='\033[1;31m' RED='\033[1;31m'
...@@ -16,11 +17,32 @@ echo_rst() { ...@@ -16,11 +17,32 @@ echo_rst() {
echo -e "${GRE}$1 not support${NOC}" echo -e "${GRE}$1 not support${NOC}"
else else
echo -e "${RED}$1 fail${NOC}" echo -e "${RED}$1 fail${NOC}"
echo -e "${RED}$3 ${NOC}"
CASE_ERR="err" CASE_ERR="err"
echo $CASE_ERR echo $CASE_ERR
fi fi
} }
chain33_Http() {
# echo "#$4 request: request="$1" MAIN_HTTP="$2" js="$3" FUNCNAME="$4" response="$5""
local body
body=$(curl -ksd "$1" "$2")
RETURN_RESP=$(echo "$body" | jq -r "$5")
echo "#response: $body" "$RETURN_RESP"
ok=$(echo "$body" | jq -r "$3")
[ "$ok" == true ]
rst=$?
echo_rst "$4" "$rst" "$body"
}
chain33_SignAndSendTxWait() {
# txHex="$1" priKey="$2" MAIN_HTTP="$3" FUNCNAME="$4"
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$1"'"}]}'
chain33_Http "$req" "$3" '(.result.txs[0].execer != "") and (.result.txs[0].execer != null)' "$4"
chain33_SignAndSendTx "$1" "$2" "$3"
chain33_BlockWait 1 "$3"
}
chain33_BlockWait() { chain33_BlockWait() {
local MAIN_HTTP=$2 local MAIN_HTTP=$2
local req='"method":"Chain33.GetLastHeader","params":[]' local req='"method":"Chain33.GetLastHeader","params":[]'
...@@ -112,7 +134,7 @@ chain33_ImportPrivkey() { ...@@ -112,7 +134,7 @@ chain33_ImportPrivkey() {
[ "$ok" == true ] [ "$ok" == true ]
} }
chain33_SignRawTx() { chain33_SignAndSendTx() {
local txHex="$1" local txHex="$1"
local priKey="$2" local priKey="$2"
local MAIN_HTTP=$3 local MAIN_HTTP=$3
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
#txhash=""
function run_testcases() { function run_testcases() {
echo "run_testcases" echo "run_testcases"
} }
function debug_function() {
set -x
eval "$@"
set +x
}
function rpc_test() { function rpc_test() {
chain33_RpcTestBegin autonomy chain33_RpcTestBegin autonomy
...@@ -30,4 +22,4 @@ function rpc_test() { ...@@ -30,4 +22,4 @@ function rpc_test() {
} }
debug_function rpc_test "$1" chain33_debug_function rpc_test "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set +e set +e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
gID="" gID=""
...@@ -31,49 +30,35 @@ init() { ...@@ -31,49 +30,35 @@ init() {
chain33_NewAccount() { chain33_NewAccount() {
label=$1 label=$1
result=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.NewAccount","params":[{"label":"'"$label"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.acc.addr") req='{"method":"Chain33.NewAccount","params":[{"label":"'"$label"'"}]}'
[ "$result" != "" ] chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.acc.addr|length > 0)' "$FUNCNAME" ".result.acc.addr"
rst=$? glAddr=$RETURN_RESP
echo_rst "$FUNCNAME" "$rst"
glAddr=$result
echo "$glAddr"
} }
chain33_SendTransaction() { chain33_SendTransaction() {
rawTx=$1 rawTx=$1
addr=$2 addr=$2
#签名交易 #签名交易
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.SignRawTx","params":[{"addr":"'"$addr"'","txHex":"'"$rawTx"'","expire":"120s","fee":10000000,"index":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"Chain33.SignRawTx","params":[{"addr":"'"$addr"'","txHex":"'"$rawTx"'","expire":"120s","fee":10000000,"index":0}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "Chain33.SignRawTx" ".result"
[ "$ok" == null ] signTx=$RETURN_RESP
rst=$?
echo_rst "$FUNCNAME" "$rst" req='{"method":"Chain33.SendTransaction","params":[{"data":"'"$signTx"'"}]}'
chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
signTx=$(echo "${resp}" | jq -r ".result")
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.SendTransaction","params":[{"data":"'"$signTx"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) gResp=$RETURN_RESP
ok=$(echo "${resp}" | jq -r ".error")
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#返回交易 #返回交易
gResp=$(jq -r ".result" <<<"$resp") chain33_QueryTx "$RETURN_RESP" "${MAIN_HTTP}"
echo "tx hash is $gResp"
chain33_QueryTx "$gResp" "${MAIN_HTTP}"
} }
blackwhite_BlackwhiteCreateTx() { blackwhite_BlackwhiteCreateTx() {
#创建交易 #创建交易
addr=$1 addr=$1
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"blackwhite.BlackwhiteCreateTx","params":[{"PlayAmount":100000000,"PlayerCount":3,"GameName":"hello","Timeout":600,"Fee":1000000}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"blackwhite.BlackwhiteCreateTx","params":[{"PlayAmount":100000000,"PlayerCount":3,"GameName":"hello","Timeout":600,"Fee":1000000}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") chain33_SendTransaction "$RETURN_RESP" "${addr}"
chain33_SendTransaction "${rawTx}" "${addr}"
gID="${gResp}" gID="${gResp}"
echo "gameID $gID"
} }
blackwhite_BlackwhitePlayTx() { blackwhite_BlackwhitePlayTx() {
...@@ -81,83 +66,54 @@ blackwhite_BlackwhitePlayTx() { ...@@ -81,83 +66,54 @@ blackwhite_BlackwhitePlayTx() {
round1=$2 round1=$2
round2=$3 round2=$3
round3=$4 round3=$4
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"blackwhite.BlackwhitePlayTx","params":[{"gameID":"'"$gID"'","amount":100000000,"Fee":1000000,"hashValues":["'"$round1"'","'"$round2"'","'"$round3"'"]}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"blackwhite.BlackwhitePlayTx","params":[{"gameID":"'"$gID"'","amount":100000000,"Fee":1000000,"hashValues":["'"$round1"'","'"$round2"'","'"$round3"'"]}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") chain33_SendTransaction "$RETURN_RESP" "${addr}"
chain33_SendTransaction "${rawTx}" "${addr}"
} }
blackwhite_BlackwhiteShowTx() { blackwhite_BlackwhiteShowTx() {
addr=$1 addr=$1
sec=$2 sec=$2
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"blackwhite.BlackwhiteShowTx","params":[{"gameID":"'"$gID"'","secret":"'"$sec"'","Fee":1000000}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"blackwhite.BlackwhiteShowTx","params":[{"gameID":"'"$gID"'","secret":"'"$sec"'","Fee":1000000}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
[ "$ok" == null ] chain33_SendTransaction "$RETURN_RESP" "${addr}"
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${addr}"
} }
blackwhite_BlackwhiteTimeoutDoneTx() { blackwhite_BlackwhiteTimeoutDoneTx() {
gameID=$1 gameID=$1
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"blackwhite.BlackwhiteTimeoutDoneTx","params":[{"gameID":"'"$gameID"'","Fee":1000000}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"blackwhite.BlackwhiteTimeoutDoneTx","params":[{"gameID":"'"$gameID"'","Fee":1000000}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME"
[ "$ok" == null ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
blackwhite_GetBlackwhiteRoundInfo() { blackwhite_GetBlackwhiteRoundInfo() {
gameID=$1 gameID=$1
execer="blackwhite" req='{"method":"Chain33.Query","params":[{"execer":"blackwhite","funcName":"GetBlackwhiteRoundInfo","payload":{"gameID":"'"$gameID"'"}}]}'
funcName="GetBlackwhiteRoundInfo" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.round | [has("gameID", "status", "playAmount", "playerCount", "curPlayerCount", "loop", "curShowCount", "timeout"),true] | unique | length == 1)' "$FUNCNAME"
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"gameID":"'"$gameID"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.round | [has("gameID", "status", "playAmount", "playerCount", "curPlayerCount", "loop", "curShowCount", "timeout"),true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
blackwhite_GetBlackwhiteByStatusAndAddr() { blackwhite_GetBlackwhiteByStatusAndAddr() {
gameID=$1 addr=$1
addr=$2 req='{"method":"Chain33.Query","params":[{"execer":"blackwhite","funcName":"GetBlackwhiteByStatusAndAddr","payload":{"status":5,"address":"'"$addr"'","count":1,"direction":0,"index":-1}}]}'
execer="blackwhite" resok='(.error|not) and (.result.round[0].createAddr == "'"$addr"'") and (.result.round[0].status == 5) and (.result.round[0] | [has("gameID", "status", "playAmount", "playerCount", "curPlayerCount", "loop", "curShowCount", "timeout", "winner"),true] | unique | length == 1)'
funcName="GetBlackwhiteByStatusAndAddr" chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"status":5,"address":"'"$addr"'","count":1,"direction":0,"index":-1}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.round[0].createAddr == "'"$addr"'") and (.result.round[0].status == 5) and (.result.round[0] | [has("gameID", "status", "playAmount", "playerCount", "curPlayerCount", "loop", "curShowCount", "timeout", "winner"),true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
blackwhite_GetBlackwhiteloopResult() { blackwhite_GetBlackwhiteloopResult() {
gameID=$1 gameID=$1
execer="blackwhite" req='{"method":"Chain33.Query","params":[{"execer":"blackwhite","funcName":"GetBlackwhiteloopResult","payload":{"gameID":"'"$gameID"'","loopSeq":0}}]}'
funcName="GetBlackwhiteloopResult" resok='(.error|not) and (.result.gameID == "'"$gameID"'") and (.result.results|length >= 1)'
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"gameID":"'"$gameID"'","loopSeq":0}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.gameID == "'"$gameID"'") and (.result.results|length >= 1)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function run_testcases() { function run_testcases() {
#密钥 #密钥
sect1="123" sect1="123"
#结果base64.StdEncoding.EncodeToString(common.Sha256([]byte("0"+secret+black)))
# black == "1" white := "0"
#black0="O3LD8NyaeeSCc8xDfvBoacTrQlrY91FHT9ceEOXgs18="
black1="6vm6gJ2wvEIxC8Yc6r/N6lIU5OZk633YMnIfwcZBD0o=" black1="6vm6gJ2wvEIxC8Yc6r/N6lIU5OZk633YMnIfwcZBD0o="
black2="6FXx5aeDSCaq1UrhLO8u0H31Hl8TpvzxuHrgGo9WeFk=" black2="6FXx5aeDSCaq1UrhLO8u0H31Hl8TpvzxuHrgGo9WeFk="
white0="DrNPzA68XiGimZE/igx70kTPJxnIJnVf8NCGnb7XoYU=" white0="DrNPzA68XiGimZE/igx70kTPJxnIJnVf8NCGnb7XoYU="
white1="SB5Pnf6Umf2Wba0dqyNOezq5FEqTd22WPVYAhSA6Lxs=" white1="SB5Pnf6Umf2Wba0dqyNOezq5FEqTd22WPVYAhSA6Lxs="
#white2="OiexKDzIlS1CKr3KBNWEY1k5uXzDI/ou6Dd+x0ByQCM="
#先创建账户地址 #先创建账户地址
chain33_NewAccount "label188" chain33_NewAccount "label188"
...@@ -201,9 +157,8 @@ function run_testcases() { ...@@ -201,9 +157,8 @@ function run_testcases() {
blackwhite_BlackwhiteTimeoutDoneTx "$gID" blackwhite_BlackwhiteTimeoutDoneTx "$gID"
#查询部分 #查询部分
blackwhite_GetBlackwhiteRoundInfo "$gID" blackwhite_GetBlackwhiteRoundInfo "$gID"
blackwhite_GetBlackwhiteByStatusAndAddr "$gID" "${gameAddr1}" blackwhite_GetBlackwhiteByStatusAndAddr "${gameAddr1}"
blackwhite_GetBlackwhiteloopResult "$gID" blackwhite_GetBlackwhiteloopResult "$gID"
} }
function main() { function main() {
...@@ -212,17 +167,8 @@ function main() { ...@@ -212,17 +167,8 @@ function main() {
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_testcases run_testcases
chain33_RpcTestRst blackwhite "$CASE_ERR" chain33_RpcTestRst blackwhite "$CASE_ERR"
}
function debug_function() {
set -x
eval "$@"
set +x
} }
debug_function main "$1" chain33_debug_function main "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
#eventId=""
#txhash=""
init() { init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")') ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
...@@ -30,8 +25,7 @@ function main() { ...@@ -30,8 +25,7 @@ function main() {
init init
run_test run_test
chain33_RpcTestRst dposvote "$CASE_ERR" chain33_RpcTestRst dposvote "$CASE_ERR"
} }
main "$1" chain33_debug_function main "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
evm_createContract_unsignedTx="0a0365766d129407228405608060405234801561001057600080fd5b50610264806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063b8e010de1461003b578063cc80f6f314610045575b600080fd5b6100436100c2565b005b61004d610109565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561008757818101518382015260200161006f565b50505050905090810190601f1680156100b45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051808201909152600d8082527f5468697320697320746573742e000000000000000000000000000000000000006020909201918252610106916000916101a0565b50565b60008054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156101955780601f1061016a57610100808354040283529160200191610195565b820191906000526020600020905b81548152906001019060200180831161017857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101e157805160ff191683800117855561020e565b8280016001018555821561020e579182015b8281111561020e5782518255916020019190600101906101f3565b5061021a92915061021e565b5090565b61019d91905b8082111561021a576000815560010161022456fea165627a7a72305820fec5dd5ca2cb47523ba08c04749bc5c14c435afee039f3047c2b7ea2faca737800293a8a025b7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b5d2c226e616d65223a22736574222c226f757470757473223a5b5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a2273686f77222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e227d5d20c0c7ee04309aedc4bcfba5beca5f3a223139746a5335316b6a7772436f535153313355336f7765376759424c6653666f466d" evm_createContract_unsignedTx="0a0365766d129407228405608060405234801561001057600080fd5b50610264806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063b8e010de1461003b578063cc80f6f314610045575b600080fd5b6100436100c2565b005b61004d610109565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561008757818101518382015260200161006f565b50505050905090810190601f1680156100b45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051808201909152600d8082527f5468697320697320746573742e000000000000000000000000000000000000006020909201918252610106916000916101a0565b50565b60008054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156101955780601f1061016a57610100808354040283529160200191610195565b820191906000526020600020905b81548152906001019060200180831161017857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101e157805160ff191683800117855561020e565b8280016001018555821561020e579182015b8281111561020e5782518255916020019190600101906101f3565b5061021a92915061021e565b5090565b61019d91905b8082111561021a576000815560010161022456fea165627a7a72305820fec5dd5ca2cb47523ba08c04749bc5c14c435afee039f3047c2b7ea2faca737800293a8a025b7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b5d2c226e616d65223a22736574222c226f757470757473223a5b5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a2273686f77222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e227d5d20c0c7ee04309aedc4bcfba5beca5f3a223139746a5335316b6a7772436f535153313355336f7765376759424c6653666f466d"
evm_createContract_para_unsignedTx="0a0f757365722e702e706172612e65766d129407228405608060405234801561001057600080fd5b50610264806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063b8e010de1461003b578063cc80f6f314610045575b600080fd5b6100436100c2565b005b61004d610109565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561008757818101518382015260200161006f565b50505050905090810190601f1680156100b45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051808201909152600d8082527f5468697320697320746573742e000000000000000000000000000000000000006020909201918252610106916000916101a0565b50565b60008054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156101955780601f1061016a57610100808354040283529160200191610195565b820191906000526020600020905b81548152906001019060200180831161017857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101e157805160ff191683800117855561020e565b8280016001018555821561020e579182015b8281111561020e5782518255916020019190600101906101f3565b5061021a92915061021e565b5090565b61019d91905b8082111561021a576000815560010161022456fea165627a7a7230582080ff1004de2195e6c08d0d0a65484b3d393c99c280e305cb383dbc89343cdd6a00293a8a025b7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b5d2c226e616d65223a22736574222c226f757470757473223a5b5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a2273686f77222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e227d5d20c0c7ee0430e1c7facdc1f199956c3a2231483969326a67464a594e5167573350695468694337796b7a5663653570764b7478" evm_createContract_para_unsignedTx="0a0f757365722e702e706172612e65766d129407228405608060405234801561001057600080fd5b50610264806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063b8e010de1461003b578063cc80f6f314610045575b600080fd5b6100436100c2565b005b61004d610109565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561008757818101518382015260200161006f565b50505050905090810190601f1680156100b45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051808201909152600d8082527f5468697320697320746573742e000000000000000000000000000000000000006020909201918252610106916000916101a0565b50565b60008054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156101955780601f1061016a57610100808354040283529160200191610195565b820191906000526020600020905b81548152906001019060200180831161017857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101e157805160ff191683800117855561020e565b8280016001018555821561020e579182015b8281111561020e5782518255916020019190600101906101f3565b5061021a92915061021e565b5090565b61019d91905b8082111561021a576000815560010161022456fea165627a7a7230582080ff1004de2195e6c08d0d0a65484b3d393c99c280e305cb383dbc89343cdd6a00293a8a025b7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b5d2c226e616d65223a22736574222c226f757470757473223a5b5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a2273686f77222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e227d5d20c0c7ee0430e1c7facdc1f199956c3a2231483969326a67464a594e5167573350695468694337796b7a5663653570764b7478"
evm_creatorAddr="1PTXh2EZ8aRUzpuoDRASV19K86Kx3qQiPt" evm_creatorAddr="1PTXh2EZ8aRUzpuoDRASV19K86Kx3qQiPt"
...@@ -14,29 +12,14 @@ evm_contractAddr="" ...@@ -14,29 +12,14 @@ evm_contractAddr=""
evm_addr="" evm_addr=""
txHash="" txHash=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
# $2=0 means true, other false
function echo_rst() {
if [ "$2" -eq 0 ]; then
echo -e "${GRE}$1 ok${NOC}"
else
echo -e "${RED}$1 fail${NOC}"
CASE_ERR="FAIL"
fi
}
function evm_createContract() { function evm_createContract() {
validator=$1 validator=$1
expectRes=$2 expectRes=$2
if [ "$ispara" == "true" ]; then if [ "$ispara" == "true" ]; then
paraName="user.p.para." paraName="user.p.para."
chain33_SignRawTx "${evm_createContract_para_unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP" chain33_SignAndSendTx "${evm_createContract_para_unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP"
else else
chain33_SignRawTx "${evm_createContract_unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP" chain33_SignAndSendTx "${evm_createContract_unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP"
fi fi
txHash=$RAW_TX_HASH txHash=$RAW_TX_HASH
queryTransaction "${validator}" "${expectRes}" queryTransaction "${validator}" "${expectRes}"
...@@ -47,16 +30,9 @@ function evm_createContract() { ...@@ -47,16 +30,9 @@ function evm_createContract() {
} }
function evm_addressCheck() { function evm_addressCheck() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"evm","funcName":"CheckAddrExists","payload":{"addr":"'${evm_contractAddr}'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"Chain33.Query","params":[{"execer":"evm","funcName":"CheckAddrExists","payload":{"addr":"'${evm_contractAddr}'"}}]}'
bContract=$(echo "${res}" | jq -r ".result.contract") resok='(.result.contract == true ) and (.result.contractAddr == "'"${evm_contractAddr}"'")'
contractAddr=$(echo "${res}" | jq -r ".result.contractAddr") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
if [ "${bContract}" == "true" ] && [ "${contractAddr}" == "${evm_contractAddr}" ]; then
echo_rst "evm address check" 0
else
echo_rst "evm address check" 1
fi
return
} }
function evm_callContract() { function evm_callContract() {
op=$1 op=$1
...@@ -72,7 +48,7 @@ function evm_callContract() { ...@@ -72,7 +48,7 @@ function evm_callContract() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP" chain33_SignAndSendTx "${unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP"
txHash=$RAW_TX_HASH txHash=$RAW_TX_HASH
queryTransaction "${validator}" "${expectRes}" queryTransaction "${validator}" "${expectRes}"
echo "CallContract queryExecRes end" echo "CallContract queryExecRes end"
...@@ -81,14 +57,8 @@ function evm_callContract() { ...@@ -81,14 +57,8 @@ function evm_callContract() {
} }
function evm_abiGet() { function evm_abiGet() {
abiInfo=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"evm","funcName":"QueryABI","payload":{"address":"'${evm_contractAddr}'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"Chain33.Query","params":[{"execer":"evm","funcName":"QueryABI","payload":{"address":"'${evm_contractAddr}'"}}]}'
res=$(echo "${abiInfo}" | jq -r ".result" | jq -r 'has("abi")') chain33_Http "$req" ${MAIN_HTTP} "(.result.abi != null)" "$FUNCNAME"
if [ "${res}" == "true" ]; then
echo_rst "CallContract queryExecRes" 0
else
echo_rst "CallContract queryExecRes" 1
fi
return
} }
function evm_transfer() { function evm_transfer() {
...@@ -101,7 +71,7 @@ function evm_transfer() { ...@@ -101,7 +71,7 @@ function evm_transfer() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP" chain33_SignAndSendTx "${unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP"
txHash=$RAW_TX_HASH txHash=$RAW_TX_HASH
queryTransaction "${validator}" "${expectRes}" queryTransaction "${validator}" "${expectRes}"
echo "evm transfer queryExecRes end" echo "evm transfer queryExecRes end"
...@@ -111,16 +81,9 @@ function evm_transfer() { ...@@ -111,16 +81,9 @@ function evm_transfer() {
function evm_getBalance() { function evm_getBalance() {
expectBalance=$1 expectBalance=$1
echo "This is evm get balance test." req='{"method":"Chain33.GetBalance","params":[{"addresses":["'${evm_creatorAddr}'"],"execer":"'${evm_addr}'", "paraName": "'${paraName}'"}]}'
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetBalance","params":[{"addresses":["'${evm_creatorAddr}'"],"execer":"'${evm_addr}'", "paraName": "'${paraName}'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) resok='(.result[0].balance == '$expectBalance') and (.result[0].addr == "'"$evm_creatorAddr"'")'
balance=$(echo "${res}" | jq -r ".result[0].balance") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
addr=$(echo "${res}" | jq -r ".result[0].addr")
if [ "${balance}" == "${expectBalance}" ] && [ "${addr}" == "${evm_creatorAddr}" ]; then
echo_rst "evm getBalance" 0
else
echo_rst "evm getBalance" 1
fi
} }
function evm_withDraw() { function evm_withDraw() {
...@@ -133,7 +96,7 @@ function evm_withDraw() { ...@@ -133,7 +96,7 @@ function evm_withDraw() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP" chain33_SignAndSendTx "${unsignedTx}" "${evm_creatorAddr_key}" "$MAIN_HTTP"
txHash=$RAW_TX_HASH txHash=$RAW_TX_HASH
queryTransaction "${validator}" "${expectRes}" queryTransaction "${validator}" "${expectRes}"
echo "evm withdraw queryExecRes end" echo "evm withdraw queryExecRes end"
...@@ -185,8 +148,6 @@ function init() { ...@@ -185,8 +148,6 @@ function init() {
echo "ipara=$ispara" echo "ipara=$ispara"
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#1PTXh2EZ8aRUzpuoDRASV19K86Kx3qQiPt
chain33_ImportPrivkey "0x4947ce3c4b845cfed59be2edf47320546116a3ff3af5715a7df094d116039b89" "1PTXh2EZ8aRUzpuoDRASV19K86Kx3qQiPt" "evm" "${main_ip}" chain33_ImportPrivkey "0x4947ce3c4b845cfed59be2edf47320546116a3ff3af5715a7df094d116039b89" "1PTXh2EZ8aRUzpuoDRASV19K86Kx3qQiPt" "evm" "${main_ip}"
local from="1PTXh2EZ8aRUzpuoDRASV19K86Kx3qQiPt" local from="1PTXh2EZ8aRUzpuoDRASV19K86Kx3qQiPt"
...@@ -195,12 +156,10 @@ function init() { ...@@ -195,12 +156,10 @@ function init() {
chain33_applyCoins "$from" 12000000000 "${main_ip}" chain33_applyCoins "$from" 12000000000 "${main_ip}"
chain33_QueryBalance "${from}" "$main_ip" chain33_QueryBalance "${from}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$from" 1000000000 "${main_ip}" chain33_applyCoins "$from" 1000000000 "${main_ip}"
chain33_QueryBalance "${from}" "$main_ip" chain33_QueryBalance "${from}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0x4947ce3c4b845cfed59be2edf47320546116a3ff3af5715a7df094d116039b89" "1PTXh2EZ8aRUzpuoDRASV19K86Kx3qQiPt" "evm" "$para_ip" chain33_ImportPrivkey "0x4947ce3c4b845cfed59be2edf47320546116a3ff3af5715a7df094d116039b89" "1PTXh2EZ8aRUzpuoDRASV19K86Kx3qQiPt" "evm" "$para_ip"
chain33_applyCoins "$from" 12000000000 "${para_ip}" chain33_applyCoins "$from" 12000000000 "${para_ip}"
...@@ -243,14 +202,12 @@ function run_test() { ...@@ -243,14 +202,12 @@ function run_test() {
function main() { function main() {
chain33_RpcTestBegin evm chain33_RpcTestBegin evm
local ip=$1 local ip=$1
MAIN_HTTP=$ip MAIN_HTTP=$ip
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_test "$MAIN_HTTP" run_test "$MAIN_HTTP"
chain33_RpcTestRst evm "$CASE_ERR" chain33_RpcTestRst evm "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
set -e # shellcheck source=/dev/null
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
...@@ -8,36 +8,24 @@ GAME_ID="" ...@@ -8,36 +8,24 @@ GAME_ID=""
PASSWD="ABCD" PASSWD="ABCD"
HASH_VALUE=$(echo -n "ABCD1" | sha256sum | awk '{print $1}') HASH_VALUE=$(echo -n "ABCD1" | sha256sum | awk '{print $1}')
EXECTOR="" PRIVA_A="0xfa21dc33a6144c546537580d28d894355d1e9af7292be175808b0f5737c30849"
PRIVA_B="0x213286d352b01fd740b6eaeb78a4fd316d743dd51d2f12c6789977430a41e0c7"
# shellcheck source=/dev/null EXECTOR=""
source ../dapp-test-common.sh source ../dapp-test-common.sh
function chain33_GetExecAddr() { function chain33_GetExecAddr() {
#获取GAME合约地址 #获取GAME合约地址
local exector=$1 req='{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'"$1"'"}]}'
local req='"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'"${exector}"'"}]' chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
# GAME_ADDR=$(echo "${res}" | jq -r ".result")
echo_rst "$FUNCNAME" "$?"
} }
function CreateGameTx() { function CreateGameTx() {
local amount=$1 local amount=$1
local hash_value=$2 local hash_value=$2
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"createGame", "payload":{"amount": '"${amount}"',"hashType":"sha256","hashValue":"'"${hash_value}"'"}}]' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"createGame", "payload":{"amount": '"${amount}"',"hashType":"sha256","hashValue":"'"${hash_value}"'"}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${PRIVA_A}" "${MAIN_HTTP}"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CreateGame createRawTx" 1
fi
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
GAME_ID=$RAW_TX_HASH GAME_ID=$RAW_TX_HASH
echo_rst "CreateGame query_tx" "$?" echo_rst "CreateGame query_tx" "$?"
...@@ -45,81 +33,43 @@ function CreateGameTx() { ...@@ -45,81 +33,43 @@ function CreateGameTx() {
function MatchGameTx() { function MatchGameTx() {
local gameId=$1 local gameId=$1
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"matchGame", "payload":{"gameId": "'"${gameId}"'","guess":2}}]' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"matchGame", "payload":{"gameId": "'"${gameId}"'","guess":2}}]}'
chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "MatchGame createRawTx" ".result"
echo "#request: $req" chain33_SignAndSendTx "${RETURN_RESP}" "${PRIVA_B}" "${MAIN_HTTP}"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "MatchGame createRawTx" 1
fi
chain33_SignRawTx "${rawTx}" "${PRIVA_B}" "${MAIN_HTTP}"
echo_rst "MatchGame query_tx" "$?" echo_rst "MatchGame query_tx" "$?"
} }
function CloseGameTx() { function CloseGameTx() {
local gameId=$1 local gameId=$1
local secret=$2 local secret=$2
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"closeGame", "payload":{"gameId": "'"${gameId}"'","secret":"'"${secret}"'","result":1}}]' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"closeGame", "payload":{"gameId": "'"${gameId}"'","secret":"'"${secret}"'","result":1}}]}'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CloseGame createRawTx" 1
fi
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "CloseGame createRawTx" ".result"
chain33_SignAndSendTx "${RETURN_RESP}" "${PRIVA_A}" "${MAIN_HTTP}"
echo_rst "CloseGame query_tx" "$?" echo_rst "CloseGame query_tx" "$?"
} }
function CancleGameTx() { function CancleGameTx() {
local gameId=$1 local gameId=$1
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"cancelGame", "payload":{"gameId": "'"${gameId}"'"}}]' local req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"cancelGame", "payload":{"gameId": "'"${gameId}"'"}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "CancleGame createRawTx" ".result"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_SignAndSendTx "${RETURN_RESP}" "${PRIVA_A}" "${MAIN_HTTP}"
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CancleGame createRawTx" 1
fi
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
echo_rst "CancleGame query_tx" "$?" echo_rst "CancleGame query_tx" "$?"
} }
function QueryGameByStatus() { function QueryGameByStatus() {
local status=$1 local status=$1
local req='"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameListByStatusAndAddr","payload":{"status":'"${status}"',"address":""}}]' local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameListByStatusAndAddr","payload":{"status":'"${status}"',"address":""}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result.games"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
GAMES=$(echo "${resp}" | jq -r ".result.games")
echo "${GAMES}"
echo_rst "$FUNCNAME" "$?"
} }
function QueryGameByGameId() { function QueryGameByGameId() {
local gameId=$1 local gameId=$1
local status=$2 local status=$2
local req='"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameById","payload":{"gameId":"'"${gameId}"'"}}]' local req='{"method":"Chain33.Query","params":[{"execer":"'"${EXECTOR}"'","funcName":"QueryGameById","payload":{"gameId":"'"${gameId}"'"}}]}'
echo "#request: $req" resok='(.error|not) and (.result.game.status = "'"${status}"'")'
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
echo "#response: $resp"
STATUS=$(echo "${resp}" | jq -r ".result.game.status")
if [ "${STATUS}" -ne "${status}" ]; then
echo "status is not equal"
echo_rst "QueryGameByGameId" 1
return 0
fi
echo_rst "QueryGameByGameId" 0
} }
function init() { function init() {
...@@ -138,10 +88,8 @@ function init() { ...@@ -138,10 +88,8 @@ function init() {
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key #main chain import pri key
#16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f chain33_ImportPrivkey "$PRIVA_A" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "${main_ip}"
chain33_ImportPrivkey "0xfa21dc33a6144c546537580d28d894355d1e9af7292be175808b0f5737c30849" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "${main_ip}" chain33_ImportPrivkey "$PRIVA_B" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$main_ip"
#16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc
chain33_ImportPrivkey "0x213286d352b01fd740b6eaeb78a4fd316d743dd51d2f12c6789977430a41e0c7" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$main_ip"
local ACCOUNT_A="16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" local ACCOUNT_A="16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f"
local ACCOUNT_B="16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" local ACCOUNT_B="16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc"
...@@ -153,16 +101,14 @@ function init() { ...@@ -153,16 +101,14 @@ function init() {
chain33_applyCoins "$ACCOUNT_B" 12000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_B" 12000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_B}" "$main_ip" chain33_QueryBalance "${ACCOUNT_B}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip" chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
chain33_applyCoins "$ACCOUNT_B" 1000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_B" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_B}" "$main_ip" chain33_QueryBalance "${ACCOUNT_B}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key chain33_ImportPrivkey "$PRIVA_A" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "$para_ip"
chain33_ImportPrivkey "0xfa21dc33a6144c546537580d28d894355d1e9af7292be175808b0f5737c30849" "16Z3haNPQd9wrnFDw19rtpbgnN2xynNT9f" "game1" "$para_ip" chain33_ImportPrivkey "$PRIVA_B" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$para_ip"
chain33_ImportPrivkey "0x213286d352b01fd740b6eaeb78a4fd316d743dd51d2f12c6789977430a41e0c7" "16GXRfd9xj3XYMDti4y4ht7uzwoh55gZEc" "game2" "$para_ip"
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}" chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$para_ip" chain33_QueryBalance "${ACCOUNT_A}" "$para_ip"
...@@ -181,43 +127,28 @@ function init() { ...@@ -181,43 +127,28 @@ function init() {
function run_test() { function run_test() {
local ip=$1 local ip=$1
CreateGameTx 1000000000 "${HASH_VALUE}" CreateGameTx 1000000000 "${HASH_VALUE}"
QueryGameByGameId "${GAME_ID}" 1 QueryGameByGameId "${GAME_ID}" 1
QueryGameByStatus 1 QueryGameByStatus 1
MatchGameTx "${GAME_ID}" MatchGameTx "${GAME_ID}"
QueryGameByGameId "${GAME_ID}" 2 QueryGameByGameId "${GAME_ID}" 2
QueryGameByStatus 2 QueryGameByStatus 2
CloseGameTx "${GAME_ID}" "${PASSWD}" CloseGameTx "${GAME_ID}" "${PASSWD}"
QueryGameByGameId "${GAME_ID}" 4 QueryGameByGameId "${GAME_ID}" 4
QueryGameByStatus 4 QueryGameByStatus 4
CreateGameTx 500000000 "${HASH_VALUE}" CreateGameTx 500000000 "${HASH_VALUE}"
QueryGameByGameId "${GAME_ID}" 1 QueryGameByGameId "${GAME_ID}" 1
CancleGameTx "${GAME_ID}" CancleGameTx "${GAME_ID}"
QueryGameByGameId "${GAME_ID}" 3 QueryGameByGameId "${GAME_ID}" 3
QueryGameByStatus 3 QueryGameByStatus 3
} }
function main() { function main() {
chain33_RpcTestBegin game
local ip=$1 local ip=$1
MAIN_HTTP=$ip MAIN_HTTP=$ip
chain33_RpcTestBegin game
echo "main_ip=$MAIN_HTTP"
init init
run_test "$MAIN_HTTP" run_test "$MAIN_HTTP"
chain33_RpcTestRst game "$CASE_ERR" chain33_RpcTestRst game "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
guess_admin_addr=12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv guess_admin_addr=12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
guess_user1_addr=1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM guess_user1_addr=1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM
guess_user2_addr=17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN guess_user2_addr=17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN
...@@ -20,103 +18,38 @@ eventId="" ...@@ -20,103 +18,38 @@ eventId=""
txhash="" txhash=""
guess_game_start() { guess_game_start() {
echo "========== # guess start tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Start", "payload":{"topic":"WorldCup Final","options":"A:France;B:Claodia","category":"football","maxBetsOneTime":10000000000,"maxBetsNumber":100000000000,"devFeeFactor":5,"devFeeAddr":"1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7","platFeeFactor":5,"platFeeAddr":"1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Start", "payload":{"topic":"WorldCup Final","options":"A:France;B:Claodia","category":"football","maxBetsOneTime":10000000000,"maxBetsNumber":100000000000,"devFeeFactor":5,"devFeeAddr":"1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7","platFeeFactor":5,"platFeeAddr":"1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
eventId="${txhash}" eventId="${txhash}"
echo "eventId $eventId"
echo "========== # guess start tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_game_bet() { guess_game_bet() {
local priv=$1 local priv=$1
local opt=$2 local opt=$2
echo "========== # guess bet tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Bet", "payload":{"gameID":"'"${eventId}"'","option":"'"${opt}"'", "betsNum":500000000}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Bet", "payload":{"gameID":"'"${eventId}"'","option":"'"${opt}"'", "betsNum":500000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "${priv}" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "${priv}" ${MAIN_HTTP}
echo "========== # guess bet tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_game_stop() { guess_game_stop() {
echo "========== # guess stop tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"StopBet", "payload":{"gameID":"'"${eventId}"'"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"StopBet", "payload":{"gameID":"'"${eventId}"'"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
echo "========== # guess stop tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_game_publish() { guess_game_publish() {
echo "========== # guess publish tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Publish", "payload":{"gameID":"'"${eventId}"'","result":"A"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Publish", "payload":{"gameID":"'"${eventId}"'","result":"A"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
echo "========== # guess publish tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_game_abort() { guess_game_abort() {
echo "========== # guess abort tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Abort", "payload":{"gameID":"'"${eventId}"'"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"guess","actionName":"Abort", "payload":{"gameID":"'"${eventId}"'"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" ${MAIN_HTTP}
echo "========== # guess abort tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
guess_QueryGameByID() { guess_QueryGameByID() {
local event_id=$1 local event_id=$1
local status=$2 local status=$2
echo "========== # guess QueryGameByID begin ==========" local req='{"method":"Chain33.Query", "params":[{"execer":"guess","funcName":"QueryGameByID","payload":{"gameID":"'"$event_id"'"}}]}'
local req='"method":"Chain33.Query", "params":[{"execer":"guess","funcName":"QueryGameByID","payload":{"gameID":"'"$event_id"'"}}]' chain33_Http "$req" ${MAIN_HTTP} '(.result|has("game")) and (.result.game.status == '"$status"')' "$FUNCNAME"
#echo "#request: $req"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.result|has("game")) and (.result.game.status == '"$status"')' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
echo "========== # guess QueryGameByID end =========="
} }
init() { init() {
...@@ -132,10 +65,7 @@ init() { ...@@ -132,10 +65,7 @@ init() {
echo "guess_addr=$guess_addr" echo "guess_addr=$guess_addr"
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM
chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "guess11" "${main_ip}" chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "guess11" "${main_ip}"
#17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN
chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "guess22" "$main_ip" chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "guess22" "$main_ip"
local guess1="1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" local guess1="1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM"
...@@ -148,14 +78,12 @@ init() { ...@@ -148,14 +78,12 @@ init() {
chain33_applyCoins "$guess2" 12000000000 "${main_ip}" chain33_applyCoins "$guess2" 12000000000 "${main_ip}"
chain33_QueryBalance "${guess2}" "$main_ip" chain33_QueryBalance "${guess2}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$guess1" 1000000000 "${main_ip}" chain33_applyCoins "$guess1" 1000000000 "${main_ip}"
chain33_QueryBalance "${guess1}" "$main_ip" chain33_QueryBalance "${guess1}" "$main_ip"
chain33_applyCoins "$guess2" 1000000000 "${main_ip}" chain33_applyCoins "$guess2" 1000000000 "${main_ip}"
chain33_QueryBalance "${guess2}" "$main_ip" chain33_QueryBalance "${guess2}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "guess11" "$para_ip" chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "guess11" "$para_ip"
chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "guess22" "$para_ip" chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "guess22" "$para_ip"
...@@ -174,7 +102,6 @@ init() { ...@@ -174,7 +102,6 @@ init() {
} }
function run_test() { function run_test() {
#导入地址私钥 #导入地址私钥
chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "user1" "$MAIN_HTTP" chain33_ImportPrivkey "0xc889d2958843fc96d4bd3f578173137d37230e580d65e9074545c61e7e9c1932" "1NrfEBfdFJUUqgbw5ZbHXhdew6NNQumYhM" "user1" "$MAIN_HTTP"
chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "user2" "$MAIN_HTTP" chain33_ImportPrivkey "0xf10c79470dc74c229c4ee73b05d14c58322b771a6c749d27824f6a59bb6c2d73" "17tRkBrccmFiVcLPXgEceRxDzJ2WaDZumN" "user2" "$MAIN_HTTP"
...@@ -320,7 +247,6 @@ function main() { ...@@ -320,7 +247,6 @@ function main() {
init init
run_test run_test
chain33_RpcTestRst guess "$CASE_ERR" chain33_RpcTestRst guess "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
...@@ -7,67 +8,24 @@ MAIN_HTTP="" ...@@ -7,67 +8,24 @@ MAIN_HTTP=""
addr_A=19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3 addr_A=19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3
addr_B=1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD addr_B=1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
hashlock_lock() { hashlock_lock() {
local secret=$1 local secret=$1
echo "========== # hashlock lock tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockLock", "payload":{"secret":"'"${secret}"'","amount":1000000000, "time":75,"toAddr":"'"${addr_B}"'", "returnAddr":"'"${addr_A}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockLock", "payload":{"secret":"'"${secret}"'","amount":1000000000, "time":75,"toAddr":"'"${addr_B}"'", "returnAddr":"'"${addr_A}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP}
#echo "txHash ${txhash}"
echo "========== # hashlock lock tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
hashlock_send() { hashlock_send() {
local secret=$1 local secret=$1
echo "========== # hashlock send tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockSend", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockSend", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0xb76a398c3901dfe5c7335525da88fda4df24c11ad11af4332f00c0953cc2910f" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0xb76a398c3901dfe5c7335525da88fda4df24c11ad11af4332f00c0953cc2910f" ${MAIN_HTTP}
#echo "txHash ${txhash}"
echo "========== # hashlock send tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
hashlock_unlock() { hashlock_unlock() {
local secret=$1 local secret=$1
echo "========== # hashlock unlock tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockUnlock", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"hashlock","actionName":"HashlockUnlock", "payload":{"secret":"'"${secret}"'","fee":100000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" ${MAIN_HTTP}
#echo "txHash ${txhash}"
echo "========== # hashlock unlock tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
init() { init() {
...@@ -80,10 +38,7 @@ init() { ...@@ -80,10 +38,7 @@ init() {
fi fi
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3
chain33_ImportPrivkey "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" "19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3" "hashlock1" "${main_ip}" chain33_ImportPrivkey "0x1089b7f980fc467f029b7ae301249b36e3b582c911b1af1a24616c83b3563dcb" "19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3" "hashlock1" "${main_ip}"
#1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD
chain33_ImportPrivkey "0xb76a398c3901dfe5c7335525da88fda4df24c11ad11af4332f00c0953cc2910f" "1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD" "hashlock2" "$main_ip" chain33_ImportPrivkey "0xb76a398c3901dfe5c7335525da88fda4df24c11ad11af4332f00c0953cc2910f" "1FcofeCgU1KYbB8dSa7cV2wjAF2RpMuUQD" "hashlock2" "$main_ip"
local hashlock1="19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3" local hashlock1="19vpbRuz2XtKopQS2ruiVuVZeRdLd5n4t3"
...@@ -129,10 +84,8 @@ function run_test() { ...@@ -129,10 +84,8 @@ function run_test() {
hashlock_send "abc" hashlock_send "abc"
chain33_QueryBalance "$addr_B" "${MAIN_HTTP}" chain33_QueryBalance "$addr_B" "${MAIN_HTTP}"
hashlock_unlock "abc" hashlock_unlock "abc"
hashlock_lock "aef" hashlock_lock "aef"
chain33_QueryBalance "$addr_A" "${MAIN_HTTP}" chain33_QueryBalance "$addr_A" "${MAIN_HTTP}"
sleep 5 sleep 5
hashlock_unlock "aef" hashlock_unlock "aef"
chain33_BlockWait 1 ${MAIN_HTTP} chain33_BlockWait 1 ${MAIN_HTTP}
...@@ -140,13 +93,12 @@ function run_test() { ...@@ -140,13 +93,12 @@ function run_test() {
} }
function main() { function main() {
MAIN_HTTP="$1"
chain33_RpcTestBegin hashlock chain33_RpcTestBegin hashlock
MAIN_HTTP="$1"
echo "ip=$MAIN_HTTP" echo "ip=$MAIN_HTTP"
init init
run_test run_test
chain33_RpcTestRst hashlock "$CASE_ERR" chain33_RpcTestRst hashlock "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
...@@ -12,11 +11,6 @@ function init() { ...@@ -12,11 +11,6 @@ function init() {
beneficiary_key=0xf146df80206194c81e0b3171db6aa40c7ad6182a24560698d4871d4dc75223ce beneficiary_key=0xf146df80206194c81e0b3171db6aa40c7ad6182a24560698d4871d4dc75223ce
beneficiary=1DwHQp8S7RS9krQTyrqePxRyvaLcuoQGks beneficiary=1DwHQp8S7RS9krQTyrqePxRyvaLcuoQGks
chain33_applyCoins "${beneficiary}" 10000000000 "${MAIN_HTTP}" chain33_applyCoins "${beneficiary}" 10000000000 "${MAIN_HTTP}"
#paracross_get_money 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
#//beneficiary=12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
#beneficiary_key=0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01
#owner=14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
#owner_key=CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944
echo "ipara=$ispara" echo "ipara=$ispara"
manager_name="manage" manager_name="manage"
exec_name="jsvm" exec_name="jsvm"
...@@ -40,55 +34,30 @@ function init() { ...@@ -40,55 +34,30 @@ function init() {
} }
function configJSCreator() { function configJSCreator() {
req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${manager_name}'","actionName":"Modify","payload":{"key":"js-creator","op":"add", "value" : "'${beneficiary}'"}}]}' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'${manager_name}'","actionName":"Modify","payload":{"key":"js-creator","op":"add","value":"'${beneficiary}'"}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "${super_manager}" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${super_manager}" "${MAIN_HTTP}"
} }
function createJSContract() { function createJSContract() {
req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${exec_name}'","actionName":"Create","payload":{"name":"'${game}'","code":"'${jsCode}'"}}]}' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'${exec_name}'","actionName":"Create","payload":{"name":"'${game}'","code":"'${jsCode}'"}}]}'
echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "${beneficiary_key}" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${beneficiary_key}" "${MAIN_HTTP}"
} }
function callJS() { function callJS() {
#the_exec= req='{"method":"Chain33.CreateTransaction","params":[{"execer":"'${user_game}'","actionName":"Call","payload":{"name":"'${game}'","funcname":"hello","args":"{}"}}]}'
req='{"jsonrpc": "2.0", "method" : "Chain33.CreateTransaction" , "params":[{"execer":"'${user_game}'","actionName":"Call","payload":{"name":"'${game}'","funcname":"hello", "args" : "{}"}}]}' chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
# echo "#request: $req" chain33_SignAndSendTx "$RETURN_RESP" "${beneficiary_key}" "${MAIN_HTTP}"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${beneficiary_key}" "${MAIN_HTTP}"
} }
function queryJS() { function queryJS() {
req='{"jsonrpc": "2.0", "method" : "Chain33.Query" , "params":[{"execer":"'${user_game}'","funcName":"Query","payload":{"name":"'${game}'","funcname":"hello", "args" : "{}"}}]}' req='{"method":"Chain33.Query","params":[{"execer":"'${user_game}'","funcName":"Query","payload":{"name":"'${game}'","funcname":"hello","args":"{}"}}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function run_testcases() { function run_testcases() {
configJSCreator configJSCreator
createJSContract createJSContract
callJS callJS
queryJS queryJS
...@@ -96,13 +65,11 @@ function run_testcases() { ...@@ -96,13 +65,11 @@ function run_testcases() {
function rpc_test() { function rpc_test() {
chain33_RpcTestBegin js chain33_RpcTestBegin js
MAIN_HTTP="$1" MAIN_HTTP="$1"
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_testcases run_testcases
chain33_RpcTestRst js "$CASE_ERR" chain33_RpcTestRst js "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
lottery_addCreator_unsignedTx="0a066d616e616765123c0a3a0a0f6c6f74746572792d63726561746f721222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630c788b8f7ccbadbc0703a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32" lottery_addCreator_unsignedTx="0a066d616e616765123c0a3a0a0f6c6f74746572792d63726561746f721222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630c788b8f7ccbadbc0703a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32"
...@@ -29,18 +28,15 @@ init() { ...@@ -29,18 +28,15 @@ init() {
if [[ $ispara == true ]]; then if [[ $ispara == true ]]; then
lottExecAddr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.lottery"}]}' ${MAIN_HTTP} | jq -r ".result") lottExecAddr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.lottery"}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignRawTx "${lottery_addCreator_unsignedTx_para}" "${lottery_creator_priv}" ${MAIN_HTTP} chain33_SignAndSendTx "${lottery_addCreator_unsignedTx_para}" "${lottery_creator_priv}" ${MAIN_HTTP}
else else
lottExecAddr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"lottery"}]}' ${MAIN_HTTP} | jq -r ".result") lottExecAddr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"lottery"}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignRawTx "${lottery_addCreator_unsignedTx}" "${lottery_creator_priv}" ${MAIN_HTTP} chain33_SignAndSendTx "${lottery_addCreator_unsignedTx}" "${lottery_creator_priv}" ${MAIN_HTTP}
fi fi
echo "lottExecAddr=$lottExecAddr" echo "lottExecAddr=$lottExecAddr"
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#1FLh9wBS2rat1mUS4G95hRpJt6yHYy5nHF
chain33_ImportPrivkey "0x8223b757a5d0f91b12e7af3b9666ca33be47fe63e1502987b0537089aaf90bc1" "1FLh9wBS2rat1mUS4G95hRpJt6yHYy5nHF" "lottery1" "${main_ip}" chain33_ImportPrivkey "0x8223b757a5d0f91b12e7af3b9666ca33be47fe63e1502987b0537089aaf90bc1" "1FLh9wBS2rat1mUS4G95hRpJt6yHYy5nHF" "lottery1" "${main_ip}"
#1UWE6NfXPR7eNAjYgT4HMERp7cMMi486E
chain33_ImportPrivkey "0xbfccb96690e0a1f89748b321f85b03e14bda0cb3d5d19f255ff0b9b0ffb624b3" "1UWE6NfXPR7eNAjYgT4HMERp7cMMi486E" "lottery2" "$main_ip" chain33_ImportPrivkey "0xbfccb96690e0a1f89748b321f85b03e14bda0cb3d5d19f255ff0b9b0ffb624b3" "1UWE6NfXPR7eNAjYgT4HMERp7cMMi486E" "lottery2" "$main_ip"
local ACCOUNT_A="1FLh9wBS2rat1mUS4G95hRpJt6yHYy5nHF" local ACCOUNT_A="1FLh9wBS2rat1mUS4G95hRpJt6yHYy5nHF"
...@@ -53,14 +49,12 @@ init() { ...@@ -53,14 +49,12 @@ init() {
chain33_applyCoins "$ACCOUNT_B" 12000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_B" 12000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_B}" "$main_ip" chain33_QueryBalance "${ACCOUNT_B}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip" chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
chain33_applyCoins "$ACCOUNT_B" 1000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_B" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_B}" "$main_ip" chain33_QueryBalance "${ACCOUNT_B}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0x8223b757a5d0f91b12e7af3b9666ca33be47fe63e1502987b0537089aaf90bc1" "1FLh9wBS2rat1mUS4G95hRpJt6yHYy5nHF" "lottery1" "$para_ip" chain33_ImportPrivkey "0x8223b757a5d0f91b12e7af3b9666ca33be47fe63e1502987b0537089aaf90bc1" "1FLh9wBS2rat1mUS4G95hRpJt6yHYy5nHF" "lottery1" "$para_ip"
chain33_ImportPrivkey "0xbfccb96690e0a1f89748b321f85b03e14bda0cb3d5d19f255ff0b9b0ffb624b3" "1UWE6NfXPR7eNAjYgT4HMERp7cMMi486E" "lottery2" "$para_ip" chain33_ImportPrivkey "0xbfccb96690e0a1f89748b321f85b03e14bda0cb3d5d19f255ff0b9b0ffb624b3" "1UWE6NfXPR7eNAjYgT4HMERp7cMMi486E" "lottery2" "$para_ip"
...@@ -74,15 +68,11 @@ init() { ...@@ -74,15 +68,11 @@ init() {
lottery_LotteryCreate() { lottery_LotteryCreate() {
#创建交易 #创建交易
priv=$1 priv=$1
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryCreate", req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryCreate","payload":{"purBlockNum":'"$purNum"',"drawBlockNum":'"$drawNum"', "opRewardRatio":'"$opRatio"',"devRewardRatio":'"$devRatio"',"fee":1000000}}]}'
"payload":{"purBlockNum":'"$purNum"',"drawBlockNum":'"$drawNum"', "opRewardRatio":'"$opRatio"',"devRewardRatio":'"$devRatio"',"fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
ok=$(echo "${resp}" | jq -r ".error")
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") chain33_SignAndSendTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP}
chain33_SignRawTx "${rawTx}" "${priv}" ${MAIN_HTTP}
gID="${RAW_TX_HASH}" gID="${RAW_TX_HASH}"
echo "gameID $gID" echo "gameID $gID"
...@@ -94,111 +84,78 @@ lottery_LotteryBuy() { ...@@ -94,111 +84,78 @@ lottery_LotteryBuy() {
amount=$2 amount=$2
number=$3 number=$3
way=$4 way=$4
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryBuy", req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryBuy","payload":{"lotteryId":"'"$gID"'","amount":'"$amount"',"number":'"$number"',"way":'"$way"',"fee":1000000}}]}'
"payload":{"lotteryId":"'"$gID"'","amount":'"$amount"',"number":'"$number"',"way":'"$way"',"fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
ok=$(echo "${resp}" | jq -r ".error")
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") chain33_SignAndSendTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP}
chain33_SignRawTx "${rawTx}" "${priv}" ${MAIN_HTTP}
} }
lottery_LotteryDraw() { lottery_LotteryDraw() {
#创建交易 #创建交易
priv=$1 priv=$1
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryDraw", req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryDraw","payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}'
"payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
ok=$(echo "${resp}" | jq -r ".error")
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") chain33_SignAndSendTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP}
chain33_SignRawTx "${rawTx}" "${priv}" ${MAIN_HTTP}
} }
lottery_LotteryClose() { lottery_LotteryClose() {
#创建交易 #创建交易
priv=$1 priv=$1
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryClose", req='{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryClose","payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}'
"payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result"
ok=$(echo "${resp}" | jq -r ".error")
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") chain33_SignAndSendTx "${RETURN_RESP}" "${priv}" ${MAIN_HTTP}
chain33_SignRawTx "${rawTx}" "${priv}" ${MAIN_HTTP}
} }
lottery_GetLotteryNormalInfo() { lottery_GetLotteryNormalInfo() {
gameID=$1 gameID=$1
addr=$2 addr=$2
execer="lottery" req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryNormalInfo","payload":{"lotteryId":"'"$gameID"'"}}]}'
funcName="GetLotteryNormalInfo" resok='(.error|not) and (.result.purBlockNum == "'"$purNum"'") and (.result.drawBlockNum == "'"$drawNum"'") and (.result.createAddr == "'"$addr"'") and (.result.opRewardRatio == "'"$opRatio"'") and (.result.devRewardRatio == "'"$devRatio"'") and (.result | [has("createHeight"), true] | unique | length == 1)'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"lotteryId":"'"$gameID"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.purBlockNum == "'"$purNum"'") and (.result.drawBlockNum == "'"$drawNum"'") and (.result.createAddr == "'"$addr"'") and (.result.opRewardRatio == "'"$opRatio"'") and (.result.devRewardRatio == "'"$devRatio"'") and (.result | [has("createHeight"), true] | unique | length == 1)' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
lottery_GetLotteryCurrentInfo() { lottery_GetLotteryCurrentInfo() {
gameID=$1 gameID=$1
status=$2 status=$2
amount=$3 amount=$3
execer="lottery" req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryCurrentInfo","payload":{"lotteryId":"'"$gameID"'"}}]}'
funcName="GetLotteryCurrentInfo" resok='(.error|not) and (.result.status == '"$status"') and (.result.buyAmount == "'"$amount"'") and (.result | [has("lastTransToPurState", "lastTransToDrawState", "totalPurchasedTxNum", "round", "luckyNumber", "lastTransToPurStateOnMain", "lastTransToDrawStateOnMain", "purBlockNum", "drawBlockNum", "missingRecords", "totalAddrNum"), true] | unique | length == 1)'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"lotteryId":"'"$gameID"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME" ".result.luckyNumber"
ok=$(jq '(.error|not) and (.result.status == '"$status"') and (.result.buyAmount == "'"$amount"'") and (.result | [has("lastTransToPurState", "lastTransToDrawState", "totalPurchasedTxNum", "round", "luckyNumber", "lastTransToPurStateOnMain", "lastTransToDrawStateOnMain", "purBlockNum", "drawBlockNum", "missingRecords", "totalAddrNum"), true] | unique | length == 1)' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
if [[ $status == 3 ]]; then if [[ $status == 3 ]]; then
luckyNumber=$(echo "${resp}" | jq -r ".result.luckyNumber") luckyNumber=$RETURN_RESP
echo -e "######\\n luckyNumber is $luckyNumber \\n######" echo -e "######\\n luckyNumber is $luckyNumber \\n######"
fi fi
echo "end"
} }
lottery_GetLotteryPurchaseAddr() { lottery_GetLotteryPurchaseAddr() {
gameID=$1 gameID=$1
count=$2 count=$2
execer="lottery" req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryPurchaseAddr","payload":{"lotteryId":"'"$gameID"'"}}]}'
funcName="GetLotteryPurchaseAddr" resok='(.error|not) and (.result.address | length == '"$count"')'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"lotteryId":"'"$gameID"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.address | length == '"$count"')' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
lottery_GetLotteryHistoryLuckyNumber() { lottery_GetLotteryHistoryLuckyNumber() {
gameID=$1 gameID=$1
count=$2 count=$2
lucky=$3 lucky=$3
execer="lottery" req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryHistoryLuckyNumber","payload":{"lotteryId":"'"$gameID"'"}}]}'
funcName="GetLotteryHistoryLuckyNumber" resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$lucky"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"lotteryId":"'"$gameID"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$lucky"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
lottery_GetLotteryRoundLuckyNumber() { lottery_GetLotteryRoundLuckyNumber() {
gameID=$1 gameID=$1
round=$2 round=$2
lucky=$3 lucky=$3
execer="lottery" req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryRoundLuckyNumber","payload":{"lotteryId":"'"$gameID"'", "round":['"$round"']}}]}'
funcName="GetLotteryRoundLuckyNumber" resok='(.error|not) and (.result.records | length == 1) and (.result.records[0].number == "'"$lucky"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"lotteryId":"'"$gameID"'", "round":['"$round"']}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.records | length == 1) and (.result.records[0].number == "'"$lucky"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
lottery_GetLotteryHistoryBuyInfo() { lottery_GetLotteryHistoryBuyInfo() {
...@@ -206,13 +163,9 @@ lottery_GetLotteryHistoryBuyInfo() { ...@@ -206,13 +163,9 @@ lottery_GetLotteryHistoryBuyInfo() {
addr=$2 addr=$2
count=$3 count=$3
number=$4 number=$4
execer="lottery" req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryHistoryBuyInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'"}}]}'
funcName="GetLotteryHistoryBuyInfo" resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$number"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$number"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
lottery_GetLotteryBuyRoundInfo() { lottery_GetLotteryBuyRoundInfo() {
...@@ -221,13 +174,9 @@ lottery_GetLotteryBuyRoundInfo() { ...@@ -221,13 +174,9 @@ lottery_GetLotteryBuyRoundInfo() {
round=$3 round=$3
count=$4 count=$4
number=$5 number=$5
execer="lottery" req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryBuyRoundInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'", "round":'"$round"'}}]}'
funcName="GetLotteryBuyRoundInfo" resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$number"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'", "round":'"$round"'}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].number == "'"$number"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
lottery_GetLotteryHistoryGainInfo() { lottery_GetLotteryHistoryGainInfo() {
...@@ -235,13 +184,9 @@ lottery_GetLotteryHistoryGainInfo() { ...@@ -235,13 +184,9 @@ lottery_GetLotteryHistoryGainInfo() {
addr=$2 addr=$2
count=$3 count=$3
amount=$4 amount=$4
execer="lottery" req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryHistoryGainInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'"}}]}'
funcName="GetLotteryHistoryGainInfo" resok='(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].addr == "'"$addr"'") and (.result.records[0].buyAmount == "'"$amount"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.records | length == '"$count"') and (.result.records[0].addr == "'"$addr"'") and (.result.records[0].buyAmount == "'"$amount"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
lottery_GetLotteryRoundGainInfo() { lottery_GetLotteryRoundGainInfo() {
...@@ -249,13 +194,9 @@ lottery_GetLotteryRoundGainInfo() { ...@@ -249,13 +194,9 @@ lottery_GetLotteryRoundGainInfo() {
addr=$2 addr=$2
round=$3 round=$3
amount=$4 amount=$4
execer="lottery" req='{"method":"Chain33.Query","params":[{"execer":"lottery","funcName":"GetLotteryRoundGainInfo","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'", "round":'"$round"'}}]}'
funcName="GetLotteryRoundGainInfo" resok='(.error|not) and (.result.addr == "'"$addr"'") and (.result.round == "'"$round"'") and (.result.buyAmount == "'"$amount"'") and (.result | [has("fundAmount"), true] | unique | length == 1)'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"lotteryId":"'"$gameID"'", "addr":"'"$addr"'", "round":'"$round"'}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.addr == "'"$addr"'") and (.result.round == "'"$round"'") and (.result.buyAmount == "'"$amount"'") and (.result | [has("fundAmount"), true] | unique | length == 1)' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function run_testcases() { function run_testcases() {
...@@ -312,13 +253,12 @@ function run_testcases() { ...@@ -312,13 +253,12 @@ function run_testcases() {
} }
function main() { function main() {
chain33_RpcTestBegin lottery
MAIN_HTTP="$1" MAIN_HTTP="$1"
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
chain33_RpcTestBegin lottery
init init
run_testcases run_testcases
chain33_RpcTestRst lottery "$CASE_ERR" chain33_RpcTestRst lottery "$CASE_ERR"
} }
......
...@@ -10,18 +10,9 @@ source ../dapp-test-common.sh ...@@ -10,18 +10,9 @@ source ../dapp-test-common.sh
Symbol="BTY" Symbol="BTY"
Asset="coins" Asset="coins"
#PrivKeyA="0x06c0fa653c719275d1baa365c7bc0b9306447287499a715b541b930482eaa504"
#PrivKeyB="0x4c8663cded61093af20339ae038b3c6bfa58a33e65874a655022f82eaf3f2fa0"
#PrivKeyC="0x9abcf378b397682109c174b37a45bfc8a459c9514dd2ef719e22a9815373047d"
#PrivKeyD="0xbf8f865a03fec64f30d2243847807e88d2dbc8104e77925e4fc11c4d4380f3da"
#PrivKeyE="0x5b8ca316cf073aa94f1056a9e3f6e0b9a9ec11ae45862d58c7a09640b4d55302"
#PrivKeyGen="CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
AddrA="1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK" AddrA="1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK"
AddrB="1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj" AddrB="1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj"
#AddrC="1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd"
#AddrD="166po3ghRbRu53hu8jBBQzddp7kUJ9Ynyf"
AddrE="1KHwX7ZadNeQDjBGpnweb4k2dqj2CWtAYo" AddrE="1KHwX7ZadNeQDjBGpnweb4k2dqj2CWtAYo"
#GenAddr="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
GenAddr="15wcitPEu1X1TBfrGfwN8GTkNTJoCmGc75" GenAddr="15wcitPEu1X1TBfrGfwN8GTkNTJoCmGc75"
PrivKeyGen="0x295710fa409bd0b0bf928efa0994645edfe80a247d89c1e1637f90dc5e303f5e" PrivKeyGen="0x295710fa409bd0b0bf928efa0994645edfe80a247d89c1e1637f90dc5e303f5e"
...@@ -29,8 +20,7 @@ PrivKeyGen="0x295710fa409bd0b0bf928efa0994645edfe80a247d89c1e1637f90dc5e303f5e" ...@@ -29,8 +20,7 @@ PrivKeyGen="0x295710fa409bd0b0bf928efa0994645edfe80a247d89c1e1637f90dc5e303f5e"
multisigExecAddr="" multisigExecAddr=""
multisigAccAddr="" multisigAccAddr=""
execName="" execName=""
#execCoins=""
#symbolCoins=""
function init() { function init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")') ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara" echo "ipara=$ispara"
...@@ -70,169 +60,115 @@ function init() { ...@@ -70,169 +60,115 @@ function init() {
function multisig_AccCreateTx() { function multisig_AccCreateTx() {
echo "========== # multisig_AccCreateTx begin ==========" echo "========== # multisig_AccCreateTx begin =========="
txHex=$(curl -ksd '{"method":"multisig.MultiSigAccCreateTx","params":[{"owners":[{"ownerAddr":"'$AddrA'","weight":20},{"ownerAddr":"'$AddrB'","weight":10},{"ownerAddr":"'$GenAddr'","weight":30}],"requiredWeight":15,"dailyLimit":{"symbol":"'$Symbol'","execer":"'$Asset'","dailyLimit":1000000000}}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigAccCreateTx","params":[{"owners":[{"ownerAddr":"'$AddrA'","weight":20},{"ownerAddr":"'$AddrB'","weight":10},{"ownerAddr":"'$GenAddr'","weight":30}],"requiredWeight":15,"dailyLimit":{"symbol":"'$Symbol'","execer":"'$Asset'","dailyLimit":1000000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP} chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#查看创建的多重签名地址是否ok #查看创建的多重签名地址是否ok
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccCount","payload":{}}]}' ${MAIN_HTTP} | jq -r ".result.data") data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccCount","payload":{}}]}' ${MAIN_HTTP} | jq -r ".result.data")
echo "$data"
#获取创建的多重签名地址 #获取创建的多重签名地址
multisigAccAddr=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccounts","payload":{"start":"0","end":"0"}}]}' ${MAIN_HTTP} | jq -r ".result.address[0]") multisigAccAddr=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccounts","payload":{"start":"0","end":"0"}}]}' ${MAIN_HTTP} | jq -r ".result.address[0]")
echo "multisigAccAddr=$multisigAccAddr"
#多重签名地址查询具体信息
result1=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccountInfo","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}' ${MAIN_HTTP})
ok1=$(jq '(.result.createAddr == "'$GenAddr'")' <<<"$result1") #多重签名地址查询具体信息
[ "$ok1" == true ] req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccountInfo","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}'
rst=$? resok='(.result.createAddr == "'$GenAddr'")'
echo_rst "$FUNCNAME" "$rst" chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
result=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccAllAddress","payload":{"multiSigAccAddr":"'$GenAddr'"}}]}' ${MAIN_HTTP})
ok=$(jq '(.result.address[0] == "'"$multisigAccAddr"'")' <<<"$result")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccAllAddress","payload":{"multiSigAccAddr":"'$GenAddr'"}}]}'
resok='(.result.address[0] == "'"$multisigAccAddr"'")'
chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
echo "========== # multisig_AccCreateTx ok ==========" echo "========== # multisig_AccCreateTx ok =========="
} }
#多重签名地址转入操作 #多重签名地址转入操作
function multisig_TransferInTx() { function multisig_TransferInTx() {
echo "========== # multisig_TransferInTx begin ==========" echo "========== # multisig_TransferInTx begin =========="
#首先转账到multisig合约中 #首先转账到multisig合约中
txHex=$(curl -ksd '{"method":"Chain33.CreateRawTransaction","params":[{"to":"'"$multisigExecAddr"'","amount":5000000000,"fee":1,"note":"12312","execName":"'"$execName"'"}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"Chain33.CreateRawTransaction","params":[{"to":"'"$multisigExecAddr"'","amount":5000000000,"fee":1,"note":"12312","execName":"'"$execName"'"}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP} chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#chain33_BlockWait 1 ${MAIN_HTTP}
#转账到multisigAccAddr地址中 #转账到multisigAccAddr地址中
txHex=$(curl -ksd '{"method":"multisig.MultiSigAccTransferInTx","params":[{"symbol":"'$Symbol'","amount":4000000000,"note":"test ","execname":"'$Asset'","to":"'"$multisigAccAddr"'"}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigAccTransferInTx","params":[{"symbol":"'$Symbol'","amount":4000000000,"note":"test ","execname":"'$Asset'","to":"'"$multisigAccAddr"'"}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#chain33_BlockWait 1 ${MAIN_HTTP}
#查询multisigAccAddr地址资产信息 #查询multisigAccAddr地址资产信息
accountasset=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccAssets","payload":{"multiSigAddr":"'"$multisigAccAddr"'","assets":{"execer":"'$Asset'","symbol":"'$Symbol'"},"isAll":false}}]}' ${MAIN_HTTP} | jq -r ".result.accAssets[0]") req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccAssets","payload":{"multiSigAddr":"'"$multisigAccAddr"'","assets":{"execer":"'$Asset'","symbol":"'$Symbol'"},"isAll":false}}]}'
echo "multisig_TransferInTx:=${accountasset}" resok='(.result.accAssets[0].assets.execer == "'$Asset'") and (.result.accAssets[0].assets.symbol == "'$Symbol'") and (.result.accAssets[0].account.frozen == "4000000000")'
ok=$(jq '(.assets.execer == "'$Asset'") and (.assets.symbol == "'$Symbol'") and (.account.frozen == "4000000000")' <<<"$accountasset") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
echo "========== # multisig_TransferInTx end ==========" echo "========== # multisig_TransferInTx end =========="
} }
function multisig_TransferOutTx() { function multisig_TransferOutTx() {
echo "========== # multisig_TransferOutTx begin ==========" echo "========== # multisig_TransferOutTx begin =========="
#由GenAddr账户签名从multisigAccAddr账户转出2000000000到AddrB #由GenAddr账户签名从multisigAccAddr账户转出2000000000到AddrB
txHex=$(curl -ksd '{"method":"multisig.MultiSigAccTransferOutTx","params":[{"symbol":"'$Symbol'","amount":2000000000,"note":"test ","execname":"coins","to":"'$AddrB'","from":"'"$multisigAccAddr"'"}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigAccTransferOutTx","params":[{"symbol":"'$Symbol'","amount":2000000000,"note":"test ","execname":"coins","to":"'$AddrB'","from":"'"$multisigAccAddr"'"}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP} chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#chain33_BlockWait 1 ${MAIN_HTTP}
#查询AddrB账户在multisig合约下有2000000000 #查询AddrB账户在multisig合约下有2000000000
accountasset=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccAssets","payload":{"multiSigAddr":"1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj","assets":{"execer":"coins","symbol":"'$Symbol'"},"isAll":false}}]}' ${MAIN_HTTP} | jq -r ".result.accAssets[0]") req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccAssets","payload":{"multiSigAddr":"1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj","assets":{"execer":"coins","symbol":"'$Symbol'"},"isAll":false}}]}'
echo "multisig_TransferOutTx:=${accountasset}" resok='(.result.accAssets[0].assets.execer == "'$Asset'") and (.result.accAssets[0].assets.symbol == "'$Symbol'") and (.result.accAssets[0].account.balance == "2000000000")'
ok=$(jq '(.assets.execer == "'$Asset'") and (.assets.symbol == "'$Symbol'") and (.account.balance == "2000000000")' <<<"$accountasset") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#查询multisigAccAddr地址资产信息,减少了2000000000 #查询multisigAccAddr地址资产信息,减少了2000000000
req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccAssets","payload":{"multiSigAddr":"'"$multisigAccAddr"'","assets":{"execer":"'$Asset'","symbol":"'$Symbol'"},"isAll":false}}]}'
accountasset=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccAssets","payload":{"multiSigAddr":"'"$multisigAccAddr"'","assets":{"execer":"'$Asset'","symbol":"'$Symbol'"},"isAll":false}}]}' ${MAIN_HTTP} | jq -r ".result.accAssets[0]") resok='(.result.accAssets[0].assets.execer == "'$Asset'") and (.result.accAssets[0].assets.symbol == "'$Symbol'") and (.result.accAssets[0].account.frozen == "2000000000")'
ok=$(jq '(.assets.execer == "'$Asset'") and (.assets.symbol == "'$Symbol'") and (.account.frozen == "2000000000")' <<<"$accountasset") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
echo "========== # multisig_TransferOutTx end ==========" echo "========== # multisig_TransferOutTx end =========="
} }
function multisig_OwnerOperateTx() { function multisig_OwnerOperateTx() {
echo "========== # multisig_OwnerOperateTx begin ==========" echo "========== # multisig_OwnerOperateTx begin =========="
#通过GenAddr账户添加AddrE到多重签名账户的owner #通过GenAddr账户添加AddrE到多重签名账户的owner
txHex=$(curl -ksd '{"method":"multisig.MultiSigOwnerOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","newOwner":"'$AddrE'","newWeight":8,"operateFlag":1}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigOwnerOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","newOwner":"'$AddrE'","newWeight":8,"operateFlag":1}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP} #查询多重签名账户的信息中有AddrEmultisig_TransferInTx
#chain33_BlockWait 1 ${MAIN_HTTP} req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccountInfo","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}'
resok='(.result.owners[3].ownerAddr == "'$AddrE'")'
#查询多重签名账户的信息中有AddrE chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
owner=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccountInfo","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}' ${MAIN_HTTP} | jq -r ".result.owners[3]")
ok=$(jq '(.ownerAddr == "'$AddrE'")' <<<"$owner")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
#删除多重签名账户的信息中owner AddrE #删除多重签名账户的信息中owner AddrE
txHex=$(curl -ksd '{"method":"multisig.MultiSigOwnerOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","oldOwner":"'$AddrE'","operateFlag":2}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigOwnerOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","oldOwner":"'$AddrE'","operateFlag":2}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#chain33_BlockWait 1 ${MAIN_HTTP}
#修改多重签名账户中owner AddrA的weight为30 #修改多重签名账户中owner AddrA的weight为30
txHex=$(curl -ksd '{"method":"multisig.MultiSigOwnerOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","oldOwner":"'$AddrA'","newWeight":30,"operateFlag":3}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigOwnerOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","oldOwner":"'$AddrA'","newWeight":30,"operateFlag":3}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#chain33_BlockWait 1 ${MAIN_HTTP}
#将多重签名账户中owner AddrA的地址替换成AddrE #将多重签名账户中owner AddrA的地址替换成AddrE
txHex=$(curl -ksd '{"method":"multisig.MultiSigOwnerOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","oldOwner":"'$AddrA'","newOwner":"'$AddrE'","operateFlag":4}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigOwnerOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","oldOwner":"'$AddrA'","newOwner":"'$AddrE'","operateFlag":4}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#chain33_BlockWait 1 ${MAIN_HTTP}
#查询多重签名账户的信息中有AddrE并且weight为30 #查询多重签名账户的信息中有AddrE并且weight为30
req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccountInfo","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}'
owner=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccountInfo","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}' ${MAIN_HTTP} | jq -r ".result.owners[0]") resok='(.result.owners[0].ownerAddr == "'$AddrE'") and (.result.owners[0].weight == "30")'
ok=$(jq '(.ownerAddr == "'$AddrE'") and (.weight == "30")' <<<"$owner") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
echo "========== # multisig_OwnerOperateTx end =========="
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function multisig_AccOperateTx() { function multisig_AccOperateTx() {
echo "========== # multisig_AccOperateTx begin ==========" echo "========== # multisig_AccOperateTx begin =========="
#修改每日限额的值为 Symbol:Asset dailyLimit=1200000000 #修改每日限额的值为 Symbol:Asset dailyLimit=1200000000
txHex=$(curl -ksd '{"method":"multisig.MultiSigAccOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","dailyLimit":{"symbol":"'$Symbol'","execer":"'$Asset'","dailyLimit":1200000000}}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigAccOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","dailyLimit":{"symbol":"'$Symbol'","execer":"'$Asset'","dailyLimit":1200000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP} chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#chain33_BlockWait 1 ${MAIN_HTTP}
#增加资产的配置 HYB:token dailyLimit=1000000000 #增加资产的配置 HYB:token dailyLimit=1000000000
txHex=$(curl -ksd '{"method":"multisig.MultiSigAccOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","dailyLimit":{"symbol":"HYB","execer":"token","dailyLimit":1000000000}}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigAccOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","dailyLimit":{"symbol":"HYB","execer":"token","dailyLimit":1000000000}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#chain33_BlockWait 1 ${MAIN_HTTP}
#修改RequiredWeight=16 #修改RequiredWeight=16
txHex=$(curl -ksd '{"method":"multisig.MultiSigAccOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","newRequiredWeight":16,"operateFlag":true}]}' ${MAIN_HTTP} | jq -r ".result") txHex=$(curl -ksd '{"method":"multisig.MultiSigAccOperateTx","params":[{"multiSigAccAddr":"'"$multisigAccAddr"'","newRequiredWeight":16,"operateFlag":true}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignRawTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP} chain33_SignAndSendTx "$txHex" "$PrivKeyGen" ${MAIN_HTTP}
#chain33_BlockWait 1 ${MAIN_HTTP}
#获取本多重签名账户上的交易数,已经对应的交易信息 #获取本多重签名账户上的交易数,已经对应的交易信息
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccTxCount","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}' ${MAIN_HTTP} | jq -r ".result") req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccTxCount","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}'
ok=$(jq '(.data != "")' <<<"$data") chain33_Http "$req" ${MAIN_HTTP} '(.result.data != null)' "$FUNCNAME"
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
#获取本多重签名账户上的交易数,通过交易交易id获取交易信息
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigAccTxCount","payload":{"multiSigAccAddr":"'"$multisigAccAddr"'"}}]}' ${MAIN_HTTP} | jq -r ".result")
ok=$(jq '(.data != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
#查询多重签名账户信息中 #查询多重签名账户信息中
req='{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigTxInfo","payload":{"multiSigAddr":"'"$multisigAccAddr"'","txId":"7"}}]}'
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"multisig","funcName":"MultiSigTxInfo","payload":{"multiSigAddr":"'"$multisigAccAddr"'","txId":"7"}}]}' ${MAIN_HTTP} | jq -r ".result") resok='(.result.txid == "7") and (.result.executed == true) and (.result.multiSigAddr == "'"$multisigAccAddr"'")'
ok=$(jq '(.txid == "7") and (.executed == true) and (.multiSigAddr == "'"$multisigAccAddr"'") ' <<<"$data") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
echo "========== # multisig_AccOperateTx end =========="
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function run_test() { function run_test() {
...@@ -241,7 +177,6 @@ function run_test() { ...@@ -241,7 +177,6 @@ function run_test() {
multisig_TransferOutTx multisig_TransferOutTx
multisig_OwnerOperateTx multisig_OwnerOperateTx
multisig_AccOperateTx multisig_AccOperateTx
} }
function main() { function main() {
...@@ -251,8 +186,7 @@ function main() { ...@@ -251,8 +186,7 @@ function main() {
init init
run_test run_test
chain33_RpcTestRst multisi "$CASE_ERR" chain33_RpcTestRst multisi "$CASE_ERR"
} }
main "$1" chain33_debug_function main "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
MAIN_HTTP="" MAIN_HTTP=""
oracle_addPublisher_unsignedTx="0a066d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630e6b685d696ee9394163a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32" oracle_addPublisher_unsignedTx="0a066d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630e6b685d696ee9394163a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32"
...@@ -8,7 +9,6 @@ oracle_publisher_key="4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C72 ...@@ -8,7 +9,6 @@ oracle_publisher_key="4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C72
eventId="" eventId=""
txhash="" txhash=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
oracle_AddPublisher() { oracle_AddPublisher() {
...@@ -16,88 +16,52 @@ oracle_AddPublisher() { ...@@ -16,88 +16,52 @@ oracle_AddPublisher() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")') ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ispara=$ispara" echo "ispara=$ispara"
if [ "$ispara" == true ]; then if [ "$ispara" == true ]; then
chain33_SignRawTx "${oracle_addPublisher_unsignedTx_para}" "${oracle_publisher_key}" "${MAIN_HTTP}" chain33_SignAndSendTx "${oracle_addPublisher_unsignedTx_para}" "${oracle_publisher_key}" "${MAIN_HTTP}"
else else
chain33_SignRawTx "${oracle_addPublisher_unsignedTx}" "${oracle_publisher_key}" "${MAIN_HTTP}" chain33_SignAndSendTx "${oracle_addPublisher_unsignedTx}" "${oracle_publisher_key}" "${MAIN_HTTP}"
fi fi
} }
oracle_publish_transaction() { oracle_publish_transaction() {
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"EventPublish","payload":{"type":"football", "subType":"Premier League","time":1747814996,"content":"test","introduction":"test"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"EventPublish","payload":{"type":"football", "subType":"Premier League","time":1747814996,"content":"test","introduction":"test"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
eventId="${txhash}" eventId="${txhash}"
echo "eventId $eventId" echo "eventId $eventId"
} }
oracle_prePublishResult_transaction() { oracle_prePublishResult_transaction() {
event_id=$1 event_id=$1
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultPrePublish","payload":{"eventID":"'"$event_id"'", "source":"sina sport","result":"0:1"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultPrePublish","payload":{"eventID":"'"$event_id"'", "source":"sina sport","result":"0:1"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_eventAbort_transaction() { oracle_eventAbort_transaction() {
event_id=$1 event_id=$1
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"EventAbort","payload":{"eventID":"'"$event_id"'"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"EventAbort","payload":{"eventID":"'"$event_id"'"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_resultAbort_transaction() { oracle_resultAbort_transaction() {
event_id=$1 event_id=$1
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultAbort","payload":{"eventID":"'"$event_id"'"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultAbort","payload":{"eventID":"'"$event_id"'"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_publishResult_transaction() { oracle_publishResult_transaction() {
event_id=$1 event_id=$1
req='"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultPublish","payload":{"eventID":"'"$event_id"'", "source":"sina sport","result":"1:1"}}]' req='{"method":"Chain33.CreateTransaction","params":[{"execer":"oracle","actionName":"ResultPublish","payload":{"eventID":"'"$event_id"'", "source":"sina sport","result":"1:1"}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_SignAndSendTx "$RETURN_RESP" "${oracle_publisher_key}" "${MAIN_HTTP}"
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
} }
oracle_QueryOraclesByID() { oracle_QueryOraclesByID() {
event_id=$1 event_id=$1
local req='"method":"Chain33.Query", "params":[{"execer":"oracle","funcName":"QueryOraclesByIDs","payload":{"eventID":["'"$event_id"'"]}}]' req='{"method":"Chain33.Query", "params":[{"execer":"oracle","funcName":"QueryOraclesByIDs","payload":{"eventID":["'"$event_id"'"]}}]}'
#echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.status[0] | [has("eventID", "status", "type", "subType", "source"),true] | unique | length == 1)' "$FUNCNAME"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result.status[0] | [has("eventID", "status", "type", "subType", "source"),true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function run_test() { function run_test() {
...@@ -134,14 +98,12 @@ function run_test() { ...@@ -134,14 +98,12 @@ function run_test() {
} }
function main() { function main() {
chain33_RpcTestBegin oracle
MAIN_HTTP="$1" MAIN_HTTP="$1"
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
chain33_RpcTestBegin oracle
run_test run_test
chain33_RpcTestRst oracle "$CASE_ERR" chain33_RpcTestRst oracle "$CASE_ERR"
} }
main "$1" chain33_debug_function main "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
CASE_ERR=""
UNIT_HTTP="" UNIT_HTTP=""
IS_PARA=false IS_PARA=false
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
paracross_GetBlock2MainInfo() { paracross_GetBlock2MainInfo() {
local height chain33_Http '{"method":"paracross.GetBlock2MainInfo","params":[{"start":1,"end":3}]}' ${UNIT_HTTP} "(.result.items[1].height == 2)" "$FUNCNAME"
height=$(curl -ksd '{"method":"paracross.GetBlock2MainInfo","params":[{"start":1,"end":3}]}' ${UNIT_HTTP} | jq -r ".result.items[1].height")
[ "$height" -eq 2 ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function paracross_SignAndSend() {
local signedTx
local sendedTx
signedTx=$(curl -ksd '{"method":"Chain33.SignRawTx","params":[{"expire":"120s","fee":'"$1"',"privkey":"'"$2"'","txHex":"'"$3"'"}]}' ${UNIT_HTTP} | jq -r ".result")
#echo "signedTx:$signedTx"
sendedTx=$(curl -ksd '{"method":"Chain33.SendTransaction","params":[{"data":"'"$signedTx"'"}]}' ${UNIT_HTTP} | jq -r ".result")
echo "sendedTx:$sendedTx"
} }
function paracross_QueryParaBalance() { function paracross_QueryParaBalance() {
...@@ -63,7 +47,6 @@ function paracross_QueryMainBalance() { ...@@ -63,7 +47,6 @@ function paracross_QueryMainBalance() {
} }
function paracross_Transfer_Withdraw_Inner() { function paracross_Transfer_Withdraw_Inner() {
# 计数器,资产转移操作和取钱操作都成功才算成功,也就是 counter == 2 # 计数器,资产转移操作和取钱操作都成功才算成功,也就是 counter == 2
local count=0 local count=0
#fromAddr 跨链资产转移地址 #fromAddr 跨链资产转移地址
...@@ -80,8 +63,6 @@ function paracross_Transfer_Withdraw_Inner() { ...@@ -80,8 +63,6 @@ function paracross_Transfer_Withdraw_Inner() {
local amount_should=27000 local amount_should=27000
#withdraw_should 应取款金额 #withdraw_should 应取款金额
local withdraw_should=13000 local withdraw_should=13000
#fee 交易费
#local fee=1000000
#平行链转移前余额 #平行链转移前余额
local para_balance_before local para_balance_before
#平行链转移后余额 #平行链转移后余额
...@@ -108,9 +89,7 @@ function paracross_Transfer_Withdraw_Inner() { ...@@ -108,9 +89,7 @@ function paracross_Transfer_Withdraw_Inner() {
#2 存钱到合约地址 #2 存钱到合约地址
tx_hash=$(curl -ksd '{"method":"Chain33.CreateRawTransaction","params":[{"to":"'"$paracross_addr"'","amount":'$amount_save'}]}' ${UNIT_HTTP} | jq -r ".result") tx_hash=$(curl -ksd '{"method":"Chain33.CreateRawTransaction","params":[{"to":"'"$paracross_addr"'","amount":'$amount_save'}]}' ${UNIT_HTTP} | jq -r ".result")
##echo "tx:$tx" chain33_SignAndSendTx "$tx_hash" "$privkey" ${UNIT_HTTP}
chain33_SignRawTx "$tx_hash" "$privkey" ${UNIT_HTTP}
#paracross_SignAndSend $fee "$privkey" "$tx_hash"
#1. 查询资产转移前余额状态 #1. 查询资产转移前余额状态
para_balance_before=$(paracross_QueryParaBalance "$from_addr" "paracross") para_balance_before=$(paracross_QueryParaBalance "$from_addr" "paracross")
...@@ -120,9 +99,7 @@ function paracross_Transfer_Withdraw_Inner() { ...@@ -120,9 +99,7 @@ function paracross_Transfer_Withdraw_Inner() {
#3 资产从主链转移到平行链 #3 资产从主链转移到平行链
tx_hash=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"'"$execer_name"'","actionName":"ParacrossAssetTransfer","payload":{"execName":"'"$execer_name"'","to":"'"$from_addr"'","amount":'$amount_should'}}]}' ${UNIT_HTTP} | jq -r ".result") tx_hash=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"'"$execer_name"'","actionName":"ParacrossAssetTransfer","payload":{"execName":"'"$execer_name"'","to":"'"$from_addr"'","amount":'$amount_should'}}]}' ${UNIT_HTTP} | jq -r ".result")
#echo "rawTx:$rawTx" chain33_SignAndSendTx "$tx_hash" "$privkey" ${UNIT_HTTP}
chain33_SignRawTx "$tx_hash" "$privkey" ${UNIT_HTTP}
#paracross_SignAndSend $fee "$privkey" "$tx_hash"
#4 查询转移后余额状态 #4 查询转移后余额状态
local times=100 local times=100
...@@ -143,7 +120,6 @@ function paracross_Transfer_Withdraw_Inner() { ...@@ -143,7 +120,6 @@ function paracross_Transfer_Withdraw_Inner() {
exit 1 exit 1
fi fi
else else
#echo "para_cross_transfer_withdraw success"
count=$((count + 1)) count=$((count + 1))
break break
fi fi
...@@ -151,9 +127,7 @@ function paracross_Transfer_Withdraw_Inner() { ...@@ -151,9 +127,7 @@ function paracross_Transfer_Withdraw_Inner() {
#5 取钱 #5 取钱
tx_hash=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"'"$execer_name"'","actionName":"ParacrossAssetWithdraw","payload":{"IsWithdraw":true,"execName":"'"$execer_name"'","to":"'"$from_addr"'","amount":'$withdraw_should'}}]}' ${UNIT_HTTP} | jq -r ".result") tx_hash=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"'"$execer_name"'","actionName":"ParacrossAssetWithdraw","payload":{"IsWithdraw":true,"execName":"'"$execer_name"'","to":"'"$from_addr"'","amount":'$withdraw_should'}}]}' ${UNIT_HTTP} | jq -r ".result")
#echo "rawTx:$rawTx" chain33_SignAndSendTx "$tx_hash" "$privkey" ${UNIT_HTTP}
chain33_SignRawTx "$tx_hash" "$privkey" ${UNIT_HTTP}
#paracross_SignAndSend $fee "$privkey" "$tx_hash"
#6 查询取钱后余额状态 #6 查询取钱后余额状态
local times=100 local times=100
...@@ -165,7 +139,6 @@ function paracross_Transfer_Withdraw_Inner() { ...@@ -165,7 +139,6 @@ function paracross_Transfer_Withdraw_Inner() {
#实际取钱金额 #实际取钱金额
para_withdraw_real=$((para_balance_after - para_balance_withdraw_after)) para_withdraw_real=$((para_balance_after - para_balance_withdraw_after))
main_withdraw_real=$((main_balance_withdraw_after - main_balance_after)) main_withdraw_real=$((main_balance_withdraw_after - main_balance_after))
#echo $withdraw_real
if [ "$withdraw_should" != "$para_withdraw_real" ] || [ "$withdraw_should" != "$main_withdraw_real" ]; then if [ "$withdraw_should" != "$para_withdraw_real" ] || [ "$withdraw_should" != "$main_withdraw_real" ]; then
chain33_BlockWait 2 ${UNIT_HTTP} chain33_BlockWait 2 ${UNIT_HTTP}
times=$((times - 1)) times=$((times - 1))
...@@ -174,7 +147,6 @@ function paracross_Transfer_Withdraw_Inner() { ...@@ -174,7 +147,6 @@ function paracross_Transfer_Withdraw_Inner() {
exit 1 exit 1
fi fi
else else
#echo "para_cross_transfer_withdraw success"
count=$((count + 1)) count=$((count + 1))
break break
fi fi
...@@ -197,99 +169,44 @@ function paracross_Transfer_Withdraw() { ...@@ -197,99 +169,44 @@ function paracross_Transfer_Withdraw() {
local execer_name="user.p.para.paracross" local execer_name="user.p.para.paracross"
paracross_Transfer_Withdraw_Inner "$from_addr" "$privkey" "$paracross_addr" "$execer_name" paracross_Transfer_Withdraw_Inner "$from_addr" "$privkey" "$paracross_addr" "$execer_name"
} }
function paracross_IsSync() { function paracross_IsSync() {
local ok
if [ "$IS_PARA" == "true" ]; then if [ "$IS_PARA" == "true" ]; then
ok=$(curl -ksd '{"method":"paracross.IsSync","params":[]}' ${UNIT_HTTP} | jq -r ".result") req='{"method":"paracross.IsSync","params":[]}'
else else
ok=$(curl -ksd '{"method":"Chain33.IsSync","params":[]}' ${UNIT_HTTP} | jq -r ".result") req='{"method":"Chain33.IsSync","params":[]}'
fi fi
chain33_Http "$req" ${UNIT_HTTP} '.result' "$FUNCNAME"
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function paracross_ListTitles() { function paracross_ListTitles() {
local resp
local ok
local main_ip=${UNIT_HTTP//8901/8801} local main_ip=${UNIT_HTTP//8901/8801}
resp=$(curl -ksd '{"method":"paracross.ListTitles","params":[]}' ${main_ip}) chain33_Http '{"method":"paracross.ListTitles","params":[]}' ${main_ip} '(.error|not) and (.result| [has("titles"),true])' "$FUNCNAME"
echo "$resp"
ok=$(jq '(.error|not) and (.result| [has("titles"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function paracross_GetHeight() { function paracross_GetHeight() {
local resp
local ok
if [ "$IS_PARA" == "true" ]; then if [ "$IS_PARA" == "true" ]; then
resp=$(curl -ksd '{"method":"paracross.GetHeight","params":[]}' ${UNIT_HTTP}) chain33_Http '{"method":"paracross.GetHeight","params":[]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("consensHeight"),true])' "$FUNCNAME"
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("consensHeight"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
fi fi
} }
function paracross_GetNodeGroupAddrs() { function paracross_GetNodeGroupAddrs() {
local resp chain33_Http '{"method":"paracross.GetNodeGroupAddrs","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("key","value"),true])' "$FUNCNAME"
local ok
resp=$(curl -ksd '{"method":"paracross.GetNodeGroupAddrs","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("key","value"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function paracross_GetNodeGroupStatus() { function paracross_GetNodeGroupStatus() {
local resp chain33_Http '{"method":"paracross.GetNodeGroupStatus","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME"
local ok
resp=$(curl -ksd '{"method":"paracross.GetNodeGroupStatus","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function paracross_ListNodeGroupStatus() { function paracross_ListNodeGroupStatus() {
local resp chain33_Http '{"method":"paracross.ListNodeGroupStatus","params":[{"title":"user.p.para.","status":2}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME"
local ok
resp=$(curl -ksd '{"method":"paracross.ListNodeGroupStatus","params":[{"title":"user.p.para.","status":2}]}' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function paracross_ListNodeStatus() { function paracross_ListNodeStatus() {
local resp chain33_Http '{"method":"paracross.ListNodeStatus","params":[{"title":"user.p.para.","status":4}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME"
local ok
resp=$(curl -ksd '{"method":"paracross.ListNodeStatus","params":[{"title":"user.p.para.","status":4}]}' ${UNIT_HTTP})
#echo $resp
ok=$(jq '(.error|not) and (.result| [has("status"),true])' <<<"$resp")
[ "$ok" == true ]
local rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
#main chain import pri key
para_test_addr="1MAuE8QSbbech3bVKK2JPJJxYxNtT95oSU" para_test_addr="1MAuE8QSbbech3bVKK2JPJJxYxNtT95oSU"
para_test_prikey="0x24d1fad138be98eebee31440f144aa38c404533f40862995282162bc538e91c8" para_test_prikey="0x24d1fad138be98eebee31440f144aa38c404533f40862995282162bc538e91c8"
...@@ -312,7 +229,6 @@ function paracross_txgroupex() { ...@@ -312,7 +229,6 @@ function paracross_txgroupex() {
exit 1 exit 1
fi fi
tx_hash_asset=$(jq -r ".result" <<<"$resp") tx_hash_asset=$(jq -r ".result" <<<"$resp")
# tx_hash_asset=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"'"${paracross_execer_name}"'","actionName":"ParacrossAssetTransfer","payload":{"execName":"'"${paracross_execer_name}"'","to":"'"$para_test_addr"'","amount":'${amount_transfer}'}}]}' "${para_ip}" | jq -r ".result")
# 资产从平行链转移到平行链合约 # 资产从平行链转移到平行链合约
req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${paracross_execer_name}"'","actionName":"TransferToExec","payload":{"execName":"'"${paracross_execer_name}"'","to":"'"${trade_exec_addr}"'","amount":'${amount_trade}', "cointoken":"coins.bty"}}]' req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${paracross_execer_name}"'","actionName":"TransferToExec","payload":{"execName":"'"${paracross_execer_name}"'","to":"'"${trade_exec_addr}"'","amount":'${amount_trade}', "cointoken":"coins.bty"}}]'
...@@ -343,10 +259,9 @@ function paracross_txgroupex() { ...@@ -343,10 +259,9 @@ function paracross_txgroupex() {
#send #send
chain33_SendTx "${tx_sign2}" "${para_ip}" chain33_SendTx "${tx_sign2}" "${para_ip}"
} }
//测试平行链交易组跨链失败,主链自动恢复原值 #测试平行链交易组跨链失败,主链自动恢复原值
function paracross_testTxGroupFail() { function paracross_testTxGroupFail() {
local para_ip=$1 local para_ip=$1
...@@ -359,9 +274,8 @@ function paracross_testTxGroupFail() { ...@@ -359,9 +274,8 @@ function paracross_testTxGroupFail() {
echo "paracross_addr=$paracross_addr" echo "paracross_addr=$paracross_addr"
#execer #execer
local trade_exec_addr="12bihjzbaYWjcpDiiy9SuAWeqNksQdiN13" local trade_exec_addr="12bihjzbaYWjcpDiiy9SuAWeqNksQdiN13"
//测试跨链过去1个,交易组转账8个失败的场景,主链应该还保持原来的 #测试跨链过去1个,交易组转账8个失败的场景,主链应该还保持原来的
local amount_trade=800000000 local amount_trade=800000000
local amount_transfer=100000000 local amount_transfer=100000000
local amount_left=500000000 local amount_left=500000000
...@@ -471,7 +385,7 @@ paracross_testSelfConsensStages() { ...@@ -471,7 +385,7 @@ paracross_testSelfConsensStages() {
req='"method":"Chain33.CreateTransaction","params":[{"execer" : "user.p.para.paracross","actionName" : "selfConsStageConfig","payload" : {"title":"user.p.para.","op" : "1", "stage" : {"startHeight":'"$newHeight"',"enable":2} }}]' req='"method":"Chain33.CreateTransaction","params":[{"execer" : "user.p.para.paracross","actionName" : "selfConsStageConfig","payload" : {"title":"user.p.para.","op" : "1", "stage" : {"startHeight":'"$newHeight"',"enable":2} }}]'
resp=$(curl -ksd "{$req}" "${para_ip}") resp=$(curl -ksd "{$req}" "${para_ip}")
rawtx=$(jq -r ".result" <<<"$resp") rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "$para_test_prikey" "${para_ip}" chain33_SignAndSendTx "$rawtx" "$para_test_prikey" "${para_ip}"
echo "get stage apply id" echo "get stage apply id"
req='"method":"paracross.ListSelfStages","params":[{"status":1,"count":1}]' req='"method":"paracross.ListSelfStages","params":[{"status":1,"count":1}]'
...@@ -492,11 +406,11 @@ paracross_testSelfConsensStages() { ...@@ -492,11 +406,11 @@ paracross_testSelfConsensStages() {
resp=$(curl -ksd "{$req}" "${para_ip}") resp=$(curl -ksd "{$req}" "${para_ip}")
rawtx=$(jq -r ".result" <<<"$resp") rawtx=$(jq -r ".result" <<<"$resp")
echo "send vote 1" echo "send vote 1"
chain33_SignRawTx "$rawtx" "$KS_PRI" "${para_ip}" chain33_SignAndSendTx "$rawtx" "$KS_PRI" "${para_ip}"
echo "send vote 2" echo "send vote 2"
chain33_SignRawTx "$rawtx" "$JR_PRI" "${para_ip}" "110s" chain33_SignAndSendTx "$rawtx" "$JR_PRI" "${para_ip}" "110s"
echo "send vote 3" echo "send vote 3"
chain33_SignRawTx "$rawtx" "$NL_PRI" "${para_ip}" "111s" chain33_SignAndSendTx "$rawtx" "$NL_PRI" "${para_ip}" "111s"
echo "query status" echo "query status"
req='"method":"paracross.ListSelfStages","params":[{"status":3,"count":1}]' req='"method":"paracross.ListSelfStages","params":[{"status":3,"count":1}]'
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
GAME_ID="" GAME_ID=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
pokerbull_PlayRawTx() { pokerbull_PlayRawTx() {
echo "========== # pokerbull play tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Play","payload":{"gameId":"pokerbull-abc", "value":"1000000000", "round":1}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Play","payload":{"gameId":"pokerbull-abc", "value":"1000000000", "round":1}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
echo "========== # pokerbull play tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
} }
pokerbull_QuitRawTx() { pokerbull_QuitRawTx() {
echo "========== # pokerbull quit tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Quit","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Quit","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
echo "========== # pokerbull quit tx end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
pokerbull_ContinueRawTx() { pokerbull_ContinueRawTx() {
echo "========== # pokerbull continue tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Continue","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Continue","payload":{"gameId":"'$GAME_ID'"}}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" ${MAIN_HTTP} "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
ok=$(jq '(.execer != "")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" ${MAIN_HTTP}
echo "========== # pokerbull continue tx end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
pokerbull_StartRawTx() { pokerbull_StartRawTx() {
echo "========== # pokerbull start tx begin =========="
tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Start","payload":{"value":"1000000000", "playerNum":"2"}}]}' ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"pokerbull","actionName":"Start","payload":{"value":"1000000000", "playerNum":"2"}}]}' ${MAIN_HTTP} | jq -r ".result")
req='{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}'
data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]") chain33_Http "$req" ${MAIN_HTTP} '(.result.txs[0].execer != null)' "$FUNCNAME"
ok=$(jq '(.execer != "")' <<<"$data") chain33_SignAndSendTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
chain33_SignRawTx "$tx" "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" ${MAIN_HTTP}
GAME_ID=$RAW_TX_HASH GAME_ID=$RAW_TX_HASH
echo "========== # pokerbull start tx end =========="
chain33_BlockWait 1 "${MAIN_HTTP}" chain33_BlockWait 1 "${MAIN_HTTP}"
} }
pokerbull_QueryResult() { pokerbull_QueryResult() {
echo "========== # pokerbull query result begin ==========" req='{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]}'
local req='"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]' resok='(.result.game.gameId == "'"$GAME_ID"'")'
data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result") chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.game.gameId == "'"$GAME_ID"'")' <<<"$data")
[ "$ok" == true ] req='{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4"}}]}'
echo_rst "$FUNCNAME" "$?" chain33_Http "$req" ${MAIN_HTTP} '(.result != null)' "$FUNCNAME"
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4"}}]}' ${MAIN_HTTP} | jq -r ".result") req='{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByStatus","payload":{"status":"3"}}]}'
[ "$data" != null ] chain33_Http "$req" ${MAIN_HTTP} '(.result != null)' "$FUNCNAME"
echo_rst "$FUNCNAME" "$?"
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByStatus","payload":{"status":"3"}}]}' ${MAIN_HTTP} | jq -r ".result")
[ "$data" != null ]
echo_rst "$FUNCNAME" "$?"
echo "========== # pokerbull query result end =========="
} }
init() { init() {
...@@ -104,10 +55,7 @@ init() { ...@@ -104,10 +55,7 @@ init() {
fi fi
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4
chain33_ImportPrivkey "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" "14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" "pokerbull1" "${main_ip}" chain33_ImportPrivkey "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" "14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" "pokerbull1" "${main_ip}"
#1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1
chain33_ImportPrivkey "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" "1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1" "pokerbull2" "$main_ip" chain33_ImportPrivkey "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" "1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1" "pokerbull2" "$main_ip"
local pokerbull1="14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" local pokerbull1="14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4"
...@@ -120,14 +68,12 @@ init() { ...@@ -120,14 +68,12 @@ init() {
chain33_applyCoins "$pokerbull2" 12000000000 "${main_ip}" chain33_applyCoins "$pokerbull2" 12000000000 "${main_ip}"
chain33_QueryBalance "${pokerbull2}" "$main_ip" chain33_QueryBalance "${pokerbull2}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$pokerbull1" 1000000000 "${main_ip}" chain33_applyCoins "$pokerbull1" 1000000000 "${main_ip}"
chain33_QueryBalance "${pokerbull1}" "$main_ip" chain33_QueryBalance "${pokerbull1}" "$main_ip"
chain33_applyCoins "$pokerbull2" 1000000000 "${main_ip}" chain33_applyCoins "$pokerbull2" 1000000000 "${main_ip}"
chain33_QueryBalance "${pokerbull2}" "$main_ip" chain33_QueryBalance "${pokerbull2}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" "14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" "pokerbull1" "$para_ip" chain33_ImportPrivkey "0x0316d5e33e7bce2455413156cb95209f8c641af352ee5d648c647f24383e4d94" "14VkqML8YTRK4o15Cf97CQhpbnRUa6sJY4" "pokerbull1" "$para_ip"
chain33_ImportPrivkey "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" "1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1" "pokerbull2" "$para_ip" chain33_ImportPrivkey "0xa26038cbdd9e6fbfb85f2c3d032254755e75252b9edccbecc16d9ba117d96705" "1MuVM87DLigWhJxLJKvghTa1po4ZdWtDv1" "pokerbull2" "$para_ip"
...@@ -155,7 +101,6 @@ function run_test() { ...@@ -155,7 +101,6 @@ function run_test() {
pokerbull_PlayRawTx pokerbull_PlayRawTx
pokerbull_QueryResult pokerbull_QueryResult
} }
function main() { function main() {
...@@ -165,7 +110,6 @@ function main() { ...@@ -165,7 +110,6 @@ function main() {
init init
run_test run_test
chain33_RpcTestRst pokerbull "$CASE_ERR" chain33_RpcTestRst pokerbull "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
privacy_CreateRawTransaction() { privacy_CreateRawTransaction() {
req='{"method":"privacy.CreateRawTransaction","params":[{"pubkeypair":"0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb", "assetExec":"coins", "tokenname":"BTY", "type":1, "amount":100000000}]}'
local ip=$1 chain33_Http "$req" ${MAIN_HTTP} '.error|not' "$FUNCNAME"
req='"method":"privacy.CreateRawTransaction","params":[{"pubkeypair":"0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb", "assetExec":"coins", "tokenname":"BTY", "type":1, "amount":100000000}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '.error|not' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_GetPrivacyTxByAddr() { privacy_GetPrivacyTxByAddr() {
chain33_Http '{"method":"privacy.GetPrivacyTxByAddr","params":[{"tokenname":"BTY","sendRecvFlag":0,"from":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "direction":1, "count":1}]}' ${MAIN_HTTP} '.error|not' "$FUNCNAME"
local ip=$1
req='"method":"privacy.GetPrivacyTxByAddr","params":[{"tokenname":"BTY","sendRecvFlag":0,"from":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "direction":1, "count":1}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '.error|not' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_ShowPrivacyKey() { privacy_ShowPrivacyKey() {
req='{"method":"privacy.ShowPrivacyKey", "params":[{"data":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"}]}'
local ip=$1 resok='(.error|not) and .result.showSuccessful and (.result.pubkeypair=="0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb")'
req='"method":"privacy.ShowPrivacyKey", "params":[{"data":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"}]' chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and .result.showSuccessful and (.result.pubkeypair=="0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_ShowPrivacyAccountInfo() { privacy_ShowPrivacyAccountInfo() {
req='{"method":"privacy.ShowPrivacyAccountInfo", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY", "displaymode":1}]}'
local ip=$1 chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result|[has("utxos", "ftxos", "displaymode"), true] | unique | length == 1)' "$FUNCNAME"
req='"method":"privacy.ShowPrivacyAccountInfo", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY", "displaymode":1}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result|[has("utxos", "ftxos", "displaymode"), true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_ShowPrivacyAccountSpend() { privacy_ShowPrivacyAccountSpend() {
chain33_Http '{"method":"privacy.ShowPrivacyAccountSpend", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY"}]}' ${MAIN_HTTP} '(.error|not) and .result.utxoHaveTxHashs' "$FUNCNAME"
local ip=$1
req='"method":"privacy.ShowPrivacyAccountSpend", "params":[{"addr":"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv", "token":"BTY"}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and .result.utxoHaveTxHashs' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_RescanUtxos() { privacy_RescanUtxos() {
chain33_Http '{"method":"privacy.RescanUtxos", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"], "flag":0}]}' ${MAIN_HTTP} '(.error|not) and (.result|[has("flag", "repRescanResults"), true] | unique | length == 1)' "$FUNCNAME"
local ip=$1
req='"method":"privacy.RescanUtxos", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"], "flag":0}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result|[has("flag", "repRescanResults"), true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
privacy_EnablePrivacy() { privacy_EnablePrivacy() {
chain33_Http '{"method":"privacy.EnablePrivacy", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"]}]}' ${MAIN_HTTP} '(.error|not) and .result.results[0].IsOK' "$FUNCNAME"
local ip=$1
req='"method":"privacy.EnablePrivacy", "params":[{"addrs":["12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"]}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$ip")
echo "#response: $resp"
ok=$(jq '(.error|not) and .result.results[0].IsOK' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function run_test() { function run_test() {
local ip=$1 privacy_EnablePrivacy
privacy_EnablePrivacy "$ip" privacy_ShowPrivacyKey
privacy_ShowPrivacyKey "$ip" privacy_CreateRawTransaction
privacy_CreateRawTransaction "$ip" privacy_ShowPrivacyAccountInfo
privacy_ShowPrivacyAccountInfo "$ip" privacy_ShowPrivacyAccountSpend
privacy_ShowPrivacyAccountSpend "$ip" privacy_RescanUtxos
privacy_RescanUtxos "$ip" privacy_GetPrivacyTxByAddr
privacy_GetPrivacyTxByAddr "$ip"
} }
function main() { function main() {
MAIN_HTTP="$1"
chain33_RpcTestBegin privacy chain33_RpcTestBegin privacy
MAIN_HTTP="$1"
echo "ip=$MAIN_HTTP" echo "ip=$MAIN_HTTP"
run_test "$MAIN_HTTP" run_test
chain33_RpcTestRst privacy "$CASE_ERR" chain33_RpcTestRst privacy "$CASE_ERR"
} }
main "$1" chain33_debug_function main "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
relay_CreateRawRelaySaveBTCHeadTx() { relay_CreateRawRelaySaveBTCHeadTx() {
local req='"method":"relay.CreateRawRelaySaveBTCHeadTx","params":[{"hash":"5e7d9c599cd040ec2ba53f4dee28028710be8c135e779f65c56feadaae34c3f2","height":10,"version":536870912,"merkleRoot":"ab91cd4160e1379c337eee6b7a4bdbb7399d70268d86045aba150743c00c90b6","time":1530862108,"nonce":0,"bits":545259519,"previousHash":"604efe53975ab06cad8748fd703ad5bc960e8b752b2aae98f0f871a4a05abfc7","isReset":true}]' local req='{"method":"relay.CreateRawRelaySaveBTCHeadTx","params":[{"hash":"5e7d9c599cd040ec2ba53f4dee28028710be8c135e779f65c56feadaae34c3f2","height":10,"version":536870912,"merkleRoot":"ab91cd4160e1379c337eee6b7a4bdbb7399d70268d86045aba150743c00c90b6","time":1530862108,"nonce":0,"bits":545259519,"previousHash":"604efe53975ab06cad8748fd703ad5bc960e8b752b2aae98f0f871a4a05abfc7","isReset":true}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "0x22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "0x22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "${MAIN_HTTP}"
} }
relay_CreateRawRelaySaveBTCHeadTx_11() { relay_CreateRawRelaySaveBTCHeadTx_11() {
local req='"method":"relay.CreateRawRelaySaveBTCHeadTx","params":[{"hash":"7b7a4a9b49db5a1162be515d380cd186e98c2bf0bb90f1145485d7c43343fc7c","height":11,"version":536870912,"merkleRoot":"cfa9b66696aea63b7266ffaa1cb4b96c8dd6959eaabf2eb14173f4adaa551f6f","time":1530862108,"nonce":1,"bits":545259519,"previousHash":"5e7d9c599cd040ec2ba53f4dee28028710be8c135e779f65c56feadaae34c3f2","isReset":false}]' local req='{"method":"relay.CreateRawRelaySaveBTCHeadTx","params":[{"hash":"7b7a4a9b49db5a1162be515d380cd186e98c2bf0bb90f1145485d7c43343fc7c","height":11,"version":536870912,"merkleRoot":"cfa9b66696aea63b7266ffaa1cb4b96c8dd6959eaabf2eb14173f4adaa551f6f","time":1530862108,"nonce":1,"bits":545259519,"previousHash":"5e7d9c599cd040ec2ba53f4dee28028710be8c135e779f65c56feadaae34c3f2","isReset":false}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "0x22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "0x22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "${MAIN_HTTP}"
} }
relay_CreateRawRelayOrderTx() { relay_CreateRawRelayOrderTx() {
local req='"method":"relay.CreateRawRelayOrderTx","params":[{"operation":0,"coin":"BTC","amount":299000000,"addr":"1Am9UTGfdnxabvcywYG2hvzr6qK8T3oUZT","btyAmount":1000000000,"coinWaits":6}]' local req='{"method":"relay.CreateRawRelayOrderTx","params":[{"operation":0,"coin":"BTC","amount":299000000,"addr":"1Am9UTGfdnxabvcywYG2hvzr6qK8T3oUZT","btyAmount":1000000000,"coinWaits":6}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "0x22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "0x22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "${MAIN_HTTP}"
} }
relay_CreateRawRelayAcceptTx() { relay_CreateRawRelayAcceptTx() {
...@@ -54,16 +33,9 @@ relay_CreateRawRelayAcceptTx() { ...@@ -54,16 +33,9 @@ relay_CreateRawRelayAcceptTx() {
exit 1 exit 1
fi fi
local req='"method":"relay.CreateRawRelayAcceptTx","params":[{"orderId":"'"$id"'","coinAddr":"1Am9UTGfdnxabvcywYG2hvzr6qK8T3oUZT"}]' local req='{"method":"relay.CreateRawRelayAcceptTx","params":[{"orderId":"'"$id"'","coinAddr":"1Am9UTGfdnxabvcywYG2hvzr6qK8T3oUZT"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "0xec9162ea5fc2f473ab8240619a0a0f495ba9e9e5d4d9c434b8794a68280236c4" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "0xec9162ea5fc2f473ab8240619a0a0f495ba9e9e5d4d9c434b8794a68280236c4" "${MAIN_HTTP}"
} }
relay_CreateRawRelayRevokeTx() { relay_CreateRawRelayRevokeTx() {
...@@ -76,16 +48,9 @@ relay_CreateRawRelayRevokeTx() { ...@@ -76,16 +48,9 @@ relay_CreateRawRelayRevokeTx() {
exit 1 exit 1
fi fi
local req='"method":"relay.CreateRawRelayRevokeTx","params":[{"orderId":"'"$id"'","target":0,"action":1}]' local req='{"method":"relay.CreateRawRelayRevokeTx","params":[{"orderId":"'"$id"'","target":0,"action":1}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "0x22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "0x22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "${MAIN_HTTP}"
} }
relay_CreateRawRelayConfirmTx() { relay_CreateRawRelayConfirmTx() {
...@@ -98,71 +63,36 @@ relay_CreateRawRelayConfirmTx() { ...@@ -98,71 +63,36 @@ relay_CreateRawRelayConfirmTx() {
exit 1 exit 1
fi fi
local req='"method":"relay.CreateRawRelayConfirmTx","params":[{"orderId":"'"$id"'","rawTx":"6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4"}]' local req='{"method":"relay.CreateRawRelayConfirmTx","params":[{"orderId":"'"$id"'","rawTx":"6359f0868171b1d194cbee1af2f16ea598ae8fad666d9b012c8ed2b79a236ec4"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "0xec9162ea5fc2f473ab8240619a0a0f495ba9e9e5d4d9c434b8794a68280236c4" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "0xec9162ea5fc2f473ab8240619a0a0f495ba9e9e5d4d9c434b8794a68280236c4" "${MAIN_HTTP}"
} }
query_GetRelayOrderByStatus() { query_GetRelayOrderByStatus() {
status="$1" status="$1"
local req='"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetRelayOrderByStatus","payload":{"addr":"","status":"'"$status"'","coins":["BTC"],"pageNumber":0,"pageSize":0}}]' local req='{"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetRelayOrderByStatus","payload":{"addr":"","status":"'"$status"'","coins":["BTC"],"pageNumber":0,"pageSize":0}}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.relayorders[0].id != null)' "$FUNCNAME"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
# echo "#response: $resp"
ok=$(jq '(.error|not) and (.result.relayorders[0].id != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
query_GetSellRelayOrder() { query_GetSellRelayOrder() {
local req='"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetSellRelayOrder","payload":{"addr":"1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3","status":"pending","coins":["BTC"],"pageNumber":0,"pageSize":0}}]' local req='{"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetSellRelayOrder","payload":{"addr":"1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3","status":"pending","coins":["BTC"],"pageNumber":0,"pageSize":0}}]}'
# echo "#request: $req" resok='(.error|not) and (.result.relayorders[0].status == "pending") and (.result.relayorders[0].coinOperation == 0) and (.result.relayorders[0].id != null)'
resp=$(curl -ksd "{$req}" ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
# echo "#response: $resp"
ok=$(jq '(.error|not) and (.result.relayorders[0].status == "pending") and (.result.relayorders[0].coinOperation == 0) and (.result.relayorders[0].id != "") ' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
query_GetBuyRelayOrder() { query_GetBuyRelayOrder() {
local req='"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetBuyRelayOrder","payload":{"addr":"1EZKahMRfoMiKp1BewjWrQWoaJ9kmC4hum","status":"locking","coins":["BTC"],"pageNumber":0,"pageSize":0}}]' local req='{"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetBuyRelayOrder","payload":{"addr":"1EZKahMRfoMiKp1BewjWrQWoaJ9kmC4hum","status":"locking","coins":["BTC"],"pageNumber":0,"pageSize":0}}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.relayorders[0].status == "locking")' "$FUNCNAME"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
# echo "#response: $resp"
ok=$(jq '(.error|not) and (.result.relayorders[0].status == "locking")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
query_GetBTCHeaderList() { query_GetBTCHeaderList() {
local req='"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetBTCHeaderList","payload":{"reqHeight":"10","counts":10,"direction":0}}]' local req='{"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetBTCHeaderList","payload":{"reqHeight":"10","counts":10,"direction":0}}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.heights|length == 2)' "$FUNCNAME"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result.heights|length == 2)' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
query_GetBTCHeaderCurHeight() { query_GetBTCHeaderCurHeight() {
local req='"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetBTCHeaderCurHeight","payload":{"baseHeight":"0"}}]' local req='{"method":"Chain33.Query", "params":[{"execer":"relay","funcName":"GetBTCHeaderCurHeight","payload":{"baseHeight":"0"}}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.baseHeight == "10") and (.result.curHeight == "10")' "$FUNCNAME"
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result.baseHeight == "10") and (.result.curHeight == "10")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
init() { init() {
...@@ -178,10 +108,7 @@ init() { ...@@ -178,10 +108,7 @@ init() {
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3
chain33_ImportPrivkey "22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3" "relay_sell" "${main_ip}" chain33_ImportPrivkey "22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3" "relay_sell" "${main_ip}"
#1EZKahMRfoMiKp1BewjWrQWoaJ9kmC4hum
chain33_ImportPrivkey "ec9162ea5fc2f473ab8240619a0a0f495ba9e9e5d4d9c434b8794a68280236c4" "1EZKahMRfoMiKp1BewjWrQWoaJ9kmC4hum" "relay_acc" "$main_ip" chain33_ImportPrivkey "ec9162ea5fc2f473ab8240619a0a0f495ba9e9e5d4d9c434b8794a68280236c4" "1EZKahMRfoMiKp1BewjWrQWoaJ9kmC4hum" "relay_acc" "$main_ip"
local sellAddr="1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3" local sellAddr="1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3"
...@@ -194,14 +121,12 @@ init() { ...@@ -194,14 +121,12 @@ init() {
chain33_applyCoins "$accepAddr" 12000000000 "${main_ip}" chain33_applyCoins "$accepAddr" 12000000000 "${main_ip}"
chain33_QueryBalance "${accepAddr}" "$main_ip" chain33_QueryBalance "${accepAddr}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$sellAddr" 1000000000 "${main_ip}" chain33_applyCoins "$sellAddr" 1000000000 "${main_ip}"
chain33_QueryBalance "${sellAddr}" "$main_ip" chain33_QueryBalance "${sellAddr}" "$main_ip"
chain33_applyCoins "$accepAddr" 1000000000 "${main_ip}" chain33_applyCoins "$accepAddr" 1000000000 "${main_ip}"
chain33_QueryBalance "${accepAddr}" "$main_ip" chain33_QueryBalance "${accepAddr}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3" "relay_sell" "$para_ip" chain33_ImportPrivkey "22968d29c6de695381a8719ef7bf00e2edb6cce500bb59a4fc73c41887610962" "1G5Cjy8LuQex2fuYv3gzb7B8MxAnxLEqt3" "relay_sell" "$para_ip"
chain33_ImportPrivkey "ec9162ea5fc2f473ab8240619a0a0f495ba9e9e5d4d9c434b8794a68280236c4" "1EZKahMRfoMiKp1BewjWrQWoaJ9kmC4hum" "relay_acc" "$para_ip" chain33_ImportPrivkey "ec9162ea5fc2f473ab8240619a0a0f495ba9e9e5d4d9c434b8794a68280236c4" "1EZKahMRfoMiKp1BewjWrQWoaJ9kmC4hum" "relay_acc" "$para_ip"
...@@ -238,7 +163,6 @@ function run_testcases() { ...@@ -238,7 +163,6 @@ function run_testcases() {
relay_CreateRawRelaySaveBTCHeadTx_11 relay_CreateRawRelaySaveBTCHeadTx_11
query_GetBTCHeaderList query_GetBTCHeaderList
} }
function rpc_test() { function rpc_test() {
...@@ -248,7 +172,6 @@ function rpc_test() { ...@@ -248,7 +172,6 @@ function rpc_test() {
init init
run_testcases run_testcases
chain33_RpcTestRst Relay "$CASE_ERR" chain33_RpcTestRst Relay "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
# TODO # TODO
...@@ -19,7 +19,7 @@ function updateConfig() { ...@@ -19,7 +19,7 @@ function updateConfig() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}" chain33_SignAndSendTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
} }
function token_preCreate() { function token_preCreate() {
...@@ -29,7 +29,7 @@ function token_preCreate() { ...@@ -29,7 +29,7 @@ function token_preCreate() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}" chain33_SignAndSendTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
} }
function token_finish() { function token_finish() {
...@@ -39,7 +39,7 @@ function token_finish() { ...@@ -39,7 +39,7 @@ function token_finish() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}" chain33_SignAndSendTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
} }
function token_sendExec() { function token_sendExec() {
...@@ -49,7 +49,7 @@ function token_sendExec() { ...@@ -49,7 +49,7 @@ function token_sendExec() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "$3" "${MAIN_HTTP}" chain33_SignAndSendTx "${unsignedTx}" "$3" "${MAIN_HTTP}"
} }
function createToken() { function createToken() {
...@@ -61,126 +61,45 @@ function createToken() { ...@@ -61,126 +61,45 @@ function createToken() {
} }
retrieve_Backup() { retrieve_Backup() {
echo "========== # retrieve backup begin =========="
local req='{"method":"retrieve.CreateRawRetrieveBackupTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'","delayPeriod": 61}]}' local req='{"method":"retrieve.CreateRawRetrieveBackupTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'","delayPeriod": 61}]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve2_key" ${MAIN_HTTP} "$FUNCNAME"
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" "$?"
chain33_SignRawTx "$tx" "$retrieve2_key" ${MAIN_HTTP}
echo "========== # retrieve backup end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_Prepare() { retrieve_Prepare() {
echo "========== # retrieve prepare begin =========="
local req='{"method":"retrieve.CreateRawRetrievePrepareTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}' local req='{"method":"retrieve.CreateRawRetrievePrepareTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve1_key" ${MAIN_HTTP} "$FUNCNAME"
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" "$?"
chain33_SignRawTx "$tx" "$retrieve1_key" ${MAIN_HTTP}
echo "========== # retrieve prepare end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_Perform() { retrieve_Perform() {
echo "========== # retrieve perform begin =========="
local req='{"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}' local req='{"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve1_key" ${MAIN_HTTP} "$FUNCNAME"
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" "$?"
chain33_SignRawTx "$tx" "$retrieve1_key" ${MAIN_HTTP}
echo "========== # retrieve perform end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_Perform_Token() { retrieve_Perform_Token() {
echo "========== # retrieve perform begin =========="
local req='{"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'","assets": [{"exec":"token","symbol":"'"$symbol"'"}] }]}' local req='{"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'","assets": [{"exec":"token","symbol":"'"$symbol"'"}] }]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve1_key" ${MAIN_HTTP} "$FUNCNAME"
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" "$?"
chain33_SignRawTx "$tx" "$retrieve1_key" ${MAIN_HTTP}
echo "========== # retrieve perform end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_Cancel() { retrieve_Cancel() {
echo "========== # retrieve cancel begin =========="
local req='{"method":"retrieve.CreateRawRetrieveCancelTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}' local req='{"method":"retrieve.CreateRawRetrieveCancelTx","params":[{"backupAddr":"'$retrieve1'","defaultAddr":"'$retrieve2'"}]}'
tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") tx=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result")
chain33_SignAndSendTxWait "$tx" "$retrieve2_key" ${MAIN_HTTP} "$FUNCNAME"
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" "$?"
chain33_SignRawTx "$tx" "$retrieve2_key" ${MAIN_HTTP}
echo "========== # retrieve cancel end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
} }
retrieve_QueryResult() { retrieve_QueryResult() {
echo "========== # retrieve query result begin =========="
local status=$1 local status=$1
local req='{"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"'$retrieve1'", "defaultAddress":"'$retrieve2'"}}]}' local req='{"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"'$retrieve1'", "defaultAddress":"'$retrieve2'"}}]}'
data=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") chain33_Http "$req" ${MAIN_HTTP} '(.result.status == '"$status"')' "$FUNCNAME"
ok=$(jq '(.status == '"$status"')' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
echo "========== # retrieve query result end =========="
} }
retrieve_QueryAssetResult() { retrieve_QueryAssetResult() {
echo "========== # retrieve query result begin =========="
local status=$1 local status=$1
local req='{"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"'$retrieve1'", "defaultAddress":"'$retrieve2'","assetExec":"token", "assetSymbol":"'"$symbol"'"}}]}' local req='{"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"'$retrieve1'", "defaultAddress":"'$retrieve2'","assetExec":"token", "assetSymbol":"'"$symbol"'"}}]}'
data=$(curl -ksd "$req" ${MAIN_HTTP} | jq -r ".result") chain33_Http "$req" ${MAIN_HTTP} '(.result.status == '"$status"')' "$FUNCNAME"
ok=$(jq '(.status == '"$status"')' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
echo "========== # retrieve query result end =========="
} }
init() { init() {
...@@ -207,7 +126,6 @@ init() { ...@@ -207,7 +126,6 @@ init() {
chain33_applyCoins "${retrieve2}" 10000000000 "${MAIN_HTTP}" chain33_applyCoins "${retrieve2}" 10000000000 "${MAIN_HTTP}"
if [ "$ispara" == true ]; then if [ "$ispara" == true ]; then
# for fee
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
chain33_applyCoins "${retrieve1}" 1000000000 "${main_ip}" chain33_applyCoins "${retrieve1}" 1000000000 "${main_ip}"
chain33_applyCoins "${retrieve2}" 1000000000 "${main_ip}" chain33_applyCoins "${retrieve2}" 1000000000 "${main_ip}"
...@@ -244,15 +162,13 @@ function run_test() { ...@@ -244,15 +162,13 @@ function run_test() {
} }
function main() { function main() {
MAIN_HTTP="$1"
chain33_RpcTestBegin retrieve chain33_RpcTestBegin retrieve
MAIN_HTTP="$1"
echo "ip=$MAIN_HTTP" echo "ip=$MAIN_HTTP"
init init
run_test run_test
chain33_RpcTestRst retrieve "$CASE_ERR" chain33_RpcTestRst retrieve "$CASE_ERR"
} }
set -x
chain33_debug_function main "$1" chain33_debug_function main "$1"
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null
set -e set -e
set -o pipefail set -o pipefail
MAIN_HTTP="" MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
ticketId="" ticketId=""
...@@ -17,107 +17,71 @@ ticket_CreateBindMiner() { ...@@ -17,107 +17,71 @@ ticket_CreateBindMiner() {
returnAddr=$2 returnAddr=$2
returnPriv=$3 returnPriv=$3
amount=$4 amount=$4
resp=$(curl -ksd '{"method":"ticket.CreateBindMiner","params":[{"bindAddr":"'"$minerAddr"'", "originAddr":"'"$returnAddr"'", "amount":'"$amount"', "checkBalance":true}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"ticket.CreateBindMiner","params":[{"bindAddr":"'"$minerAddr"'", "originAddr":"'"$returnAddr"'", "amount":'"$amount"', "checkBalance":true}]}'
ok=$(echo "${resp}" | jq -r ".error") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME" ".result.txHex"
[[ $ok == null ]] chain33_SignAndSendTx "$RETURN_RESP" "${returnPriv}" ${MAIN_HTTP}
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result.txHex")
chain33_SignRawTx "${rawTx}" "${returnPriv}" ${MAIN_HTTP}
} }
ticket_SetAutoMining() { ticket_SetAutoMining() {
flag=$1 flag=$1
resp=$(curl -ksd '{"method":"ticket.SetAutoMining","params":[{"flag":'"$flag"'}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"ticket.SetAutoMining","params":[{"flag":'"$flag"'}]}'
ok=$(jq '(.error|not) and (.result.isOK == true)' <<<"$resp") chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.isOK == true)' "$FUNCNAME"
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_GetTicketCount() { ticket_GetTicketCount() {
resp=$(curl -ksd '{"method":"ticket.GetTicketCount","params":[{}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http '{"method":"ticket.GetTicketCount","params":[{}]}' ${MAIN_HTTP} '(.error|not) and (.result > 0)' "$FUNCNAME"
ok=$(jq '(.error|not) and (.result > 0)' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_CloseTickets() { ticket_CloseTickets() {
addr=$1 addr=$1
resp=$(curl -ksd '{"method":"ticket.CloseTickets","params":[{"minerAddress":"'"$addr"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"ticket.CloseTickets","params":[{"minerAddress":"'"$addr"'"}]}'
ok=$(jq '(.error|not)' <<<"$resp") chain33_Http "$req" ${MAIN_HTTP} '(.error|not)' "$FUNCNAME"
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_TicketInfos() { ticket_TicketInfos() {
tid=$1 tid=$1
minerAddr=$2 minerAddr=$2
returnAddr=$3 returnAddr=$3
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"TicketInfos","payload":{"ticketIds":["'"$tid"'"]}}]}'
funcName="TicketInfos" resok='(.error|not) and (.result.tickets | length > 0) and (.result.tickets[0].minerAddress == "'"$minerAddr"'") and (.result.tickets[0].returnAddress == "'"$returnAddr"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"ticketIds":["'"$tid"'"]}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.tickets | length > 0) and (.result.tickets[0].minerAddress == "'"$minerAddr"'") and (.result.tickets[0].returnAddress == "'"$returnAddr"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_TicketList() { ticket_TicketList() {
minerAddr=$1 minerAddr=$1
returnAddr=$2 returnAddr=$2
status=$3 status=$3
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"TicketList","payload":{"addr":"'"$minerAddr"'", "status":'"$status"'}}]}'
funcName="TicketList" resok='(.error|not) and (.result.tickets | length > 0) and (.result.tickets[0].minerAddress == "'"$minerAddr"'") and (.result.tickets[0].returnAddress == "'"$returnAddr"'") and (.result.tickets[0].status == '"$status"')'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"addr":"'"$minerAddr"'", "status":'"$status"'}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.tickets | length > 0) and (.result.tickets[0].minerAddress == "'"$minerAddr"'") and (.result.tickets[0].returnAddress == "'"$returnAddr"'") and (.result.tickets[0].status == '"$status"')' <<<"$resp")
[[ $ok == true ]] ticket0=$(echo "${RETURN_RESP}" | jq -r ".result.tickets[0]")
rst=$?
echo_rst "$FUNCNAME" "$rst"
ticket0=$(echo "${resp}" | jq -r ".result.tickets[0]")
echo -e "######\\n ticket[0] is $ticket0) \\n######" echo -e "######\\n ticket[0] is $ticket0) \\n######"
ticketId=$(echo "${resp}" | jq -r ".result.tickets[0].ticketId") ticketId=$(echo "${RETURN_RESP}" | jq -r ".result.tickets[0].ticketId")
echo -e "######\\n ticketId is $ticketId \\n######" echo -e "######\\n ticketId is $ticketId \\n######"
} }
ticket_MinerAddress() { ticket_MinerAddress() {
returnAddr=$1 returnAddr=$1
minerAddr=$2 minerAddr=$2
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"MinerAddress","payload":{"data":"'"$returnAddr"'"}}]}'
funcName="MinerAddress" resok='(.error|not) and (.result.data == "'"$minerAddr"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"data":"'"$returnAddr"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.data == "'"$minerAddr"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_MinerSourceList() { ticket_MinerSourceList() {
minerAddr=$1 minerAddr=$1
returnAddr=$2 returnAddr=$2
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"MinerSourceList","payload":{"data":"'"$minerAddr"'"}}]}'
funcName="MinerSourceList" resok='(.error|not) and (.result.datas | length > 0) and (.result.datas[0] == "'"$returnAddr"'")'
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"data":"'"$minerAddr"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) chain33_Http "$req" ${MAIN_HTTP} "$resok" "$FUNCNAME"
ok=$(jq '(.error|not) and (.result.datas | length > 0) and (.result.datas[0] == "'"$returnAddr"'")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
ticket_RandNumHash() { ticket_RandNumHash() {
hash=$1 hash=$1
blockNum=$2 blockNum=$2
execer="ticket" req='{"method":"Chain33.Query","params":[{"execer":"ticket","funcName":"RandNumHash","payload":{"hash":"'"$hash"'", "blockNum":'"$blockNum"'}}]}'
funcName="RandNumHash" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result.hash != null)' "$FUNCNAME"
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"hash":"'"$hash"'", "blockNum":'"$blockNum"'}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.hash != "")' <<<"$resp")
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
} }
function run_testcases() { function run_testcases() {
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
tokenAddr="1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK" tokenAddr="1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
recvAddr="1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" recvAddr="1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq"
superManager="0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc" superManager="0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc"
tokenSymbol="ABCDE" tokenSymbol="ABCDE"
token_addr="" token_addr=""
execName="token" execName="token"
txHash=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
# $2=0 means true, other false
function echo_rst() {
if [ "$2" -eq 0 ]; then
echo -e "${GRE}$1 ok${NOC}"
else
echo -e "${RED}$1 fail${NOC}"
CASE_ERR="FAIL"
fi
}
# 查询交易的执行结果 # 查询交易的执行结果
# 根据传入的规则,校验查询的结果 (参数1: 校验规则 参数2: 预期匹配结果) # 根据传入的规则,校验查询的结果 (参数1: 校验规则 参数2: 预期匹配结果)
function queryTransaction() { function queryTransaction() {
validator=$1 validator=$1
expectRes=$2 expectRes=$2
echo "txhash=${txHash}" # echo "txhash=${RAW_TX_HASH}"
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.QueryTransaction","params":[{"hash":"'"${txHash}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r "${validator}") res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.QueryTransaction","params":[{"hash":"'"${RAW_TX_HASH}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r "${validator}")
if [ "${res}" != "${expectRes}" ]; then if [ "${res}" != "${expectRes}" ]; then
return 1 return 1
else else
...@@ -43,14 +25,18 @@ function queryTransaction() { ...@@ -43,14 +25,18 @@ function queryTransaction() {
fi fi
} }
function signRawTxAndQuery() {
chain33_SignAndSendTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "$1 queryExecRes" "$?"
}
function init() { function init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")') ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara" echo "ipara=$ispara"
chain33_ImportPrivkey "${superManager}" "${tokenAddr}" "tokenAddr" "${MAIN_HTTP}" chain33_ImportPrivkey "${superManager}" "${tokenAddr}" "tokenAddr" "${MAIN_HTTP}"
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq
chain33_ImportPrivkey "0x882c963ce2afbedc2353cb417492aa9e889becd878a10f2529fc9e6c3b756128" "1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" "token1" "${main_ip}" chain33_ImportPrivkey "0x882c963ce2afbedc2353cb417492aa9e889becd878a10f2529fc9e6c3b756128" "1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" "token1" "${main_ip}"
local ACCOUNT_A="1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" local ACCOUNT_A="1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq"
...@@ -59,12 +45,10 @@ function init() { ...@@ -59,12 +45,10 @@ function init() {
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_A" 12000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip" chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip" chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0x882c963ce2afbedc2353cb417492aa9e889becd878a10f2529fc9e6c3b756128" "1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" "token1" "$para_ip" chain33_ImportPrivkey "0x882c963ce2afbedc2353cb417492aa9e889becd878a10f2529fc9e6c3b756128" "1CLrYLNhHfCfMUV7mtdqhbMSF6vGmtTvzq" "token1" "$para_ip"
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}" chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}"
...@@ -96,25 +80,16 @@ function updateConfig() { ...@@ -96,25 +80,16 @@ function updateConfig() {
echo_rst "update config create tx" 1 echo_rst "update config create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "update config queryExecRes" "$?"
} }
function token_preCreate() { function token_preCreate() {
unsignedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"token.CreateRawTokenPreCreateTx","params":[{"name": "yinhebib", "symbol": "'"${tokenSymbol}"'", "total": 100000000000, "price": 100, "category": 1,"owner":"'${tokenAddr}'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result") unsignedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"token.CreateRawTokenPreCreateTx","params":[{"name": "yinhebib", "symbol": "'"${tokenSymbol}"'", "total": 100000000000, "price": 100, "category": 1,"owner":"'${tokenAddr}'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
if [ "${unsignedTx}" == "" ]; then if [ "${unsignedTx}" == "" ]; then
echo_rst "token preCreate create tx" 1 echo_rst "token preCreate create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token preCreate queryExecRes" "$?"
} }
function token_getPreCreated() { function token_getPreCreated() {
...@@ -132,21 +107,12 @@ function token_finish() { ...@@ -132,21 +107,12 @@ function token_finish() {
return return
fi fi
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}" signRawTxAndQuery "$FUNCNAME"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token finish queryExecRes" "$?"
} }
function token_getFinishCreated() { function token_getFinishCreated() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"${execName}"'","funcName":"GetTokens","payload":{"queryAll":true,"status":1,"tokens":[],"symbolOnly":false}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.tokens" | grep "symbol") req='{"method":"Chain33.Query","params":[{"execer":"'"${execName}"'","funcName":"GetTokens","payload":{"queryAll":true,"status":1,"tokens":[],"symbolOnly":false}}]}'
chain33_Http "$req" ${MAIN_HTTP} "(.result.tokens[0].symbol != null)" "$FUNCNAME"
if [ "${res}" != "" ]; then
echo_rst "token get finishCreated create tx" 0
else
echo_rst "token get finishCreated create tx" 1
fi
} }
function token_assets() { function token_assets() {
...@@ -166,8 +132,8 @@ function token_assets() { ...@@ -166,8 +132,8 @@ function token_assets() {
else else
echo_rst "token get assets tx" 1 echo_rst "token get assets tx" 1
fi fi
} }
function token_balance() { function token_balance() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"token.GetTokenBalance","params":[{"addresses": ["'${tokenAddr}'"],"tokenSymbol":"'"${tokenSymbol}"'","execer": "'"${execName}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"token.GetTokenBalance","params":[{"addresses": ["'${tokenAddr}'"],"tokenSymbol":"'"${tokenSymbol}"'","execer": "'"${execName}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
...@@ -192,12 +158,7 @@ function token_burn() { ...@@ -192,12 +158,7 @@ function token_burn() {
echo_rst "token burn create tx" 1 echo_rst "token burn create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token burn queryExecRes" "$?"
} }
function token_mint() { function token_mint() {
...@@ -206,12 +167,7 @@ function token_mint() { ...@@ -206,12 +167,7 @@ function token_mint() {
echo_rst "token mint create tx" 1 echo_rst "token mint create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token mint queryExecRes" "$?"
} }
function token_transfer() { function token_transfer() {
unsignedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.CreateTransaction","params":[{"execer": "'"${execName}"'","actionName":"Transfer","payload": {"cointoken":"'"${tokenSymbol}"'", "amount": "1000000000", "note": "", "to": "'"${recvAddr}"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result") unsignedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.CreateTransaction","params":[{"execer": "'"${execName}"'","actionName":"Transfer","payload": {"cointoken":"'"${tokenSymbol}"'", "amount": "1000000000", "note": "", "to": "'"${recvAddr}"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
...@@ -219,12 +175,7 @@ function token_transfer() { ...@@ -219,12 +175,7 @@ function token_transfer() {
echo_rst "token transfer create tx" 1 echo_rst "token transfer create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token transfer queryExecRes" "$?"
} }
function token_sendExec() { function token_sendExec() {
...@@ -233,12 +184,7 @@ function token_sendExec() { ...@@ -233,12 +184,7 @@ function token_sendExec() {
echo_rst "token sendExec create tx" 1 echo_rst "token sendExec create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token sendExec queryExecRes" "$?"
} }
function token_withdraw() { function token_withdraw() {
...@@ -247,17 +193,11 @@ function token_withdraw() { ...@@ -247,17 +193,11 @@ function token_withdraw() {
echo_rst "token withdraw create tx" 1 echo_rst "token withdraw create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME"
chain33_SignRawTx "${unsignedTx}" "${superManager}" "${MAIN_HTTP}"
txHash=$RAW_TX_HASH
queryTransaction ".error | not" "true"
echo_rst "token withdraw queryExecRes" "$?"
} }
function run_test() { function run_test() {
local ip=$1 local ip=$1
set -x
token_preCreate token_preCreate
token_getPreCreated token_getPreCreated
...@@ -271,19 +211,16 @@ function run_test() { ...@@ -271,19 +211,16 @@ function run_test() {
token_sendExec token_sendExec
token_assets token_assets
token_withdraw token_withdraw
set +x
} }
function main() { function main() {
local ip=$1
chain33_RpcTestBegin token chain33_RpcTestBegin token
local ip=$1
MAIN_HTTP=$ip MAIN_HTTP=$ip
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_test "$ip" run_test "$ip"
chain33_RpcTestRst token "$CASE_ERR" chain33_RpcTestRst token "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
MAIN_HTTP="" MAIN_HTTP=""
CASE_ERR=""
trade_addr="" trade_addr=""
tradeAddr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" tradeAddr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
tradeBuyerAddr="1CvLe1qNaC7tCf5xmfAqJ9UJkMhtmhUKNg" tradeBuyerAddr="1CvLe1qNaC7tCf5xmfAqJ9UJkMhtmhUKNg"
...@@ -17,11 +15,7 @@ function updateConfig() { ...@@ -17,11 +15,7 @@ function updateConfig() {
echo_rst "update config create tx" 1 echo_rst "update config create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "update config queryExecRes" "$?"
} }
function token_preCreate() { function token_preCreate() {
...@@ -30,11 +24,7 @@ function token_preCreate() { ...@@ -30,11 +24,7 @@ function token_preCreate() {
echo_rst "token preCreate create tx" 1 echo_rst "token preCreate create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "token preCreate queryExecRes" "$?"
} }
function token_finish() { function token_finish() {
...@@ -43,29 +33,12 @@ function token_finish() { ...@@ -43,29 +33,12 @@ function token_finish() {
echo_rst "token finish create tx" 1 echo_rst "token finish create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "token finish queryExecRes" "$?"
} }
function token_balance() { function token_balance() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"token.GetTokenBalance","params":[{"addresses": ["'"${tradeAddr}"'"],"tokenSymbol":"'"${tokenSymbol}"'","execer": "'"${tokenExecName}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"token.GetTokenBalance","params":[{"addresses": ["'"${tradeAddr}"'"],"tokenSymbol":"'"${tokenSymbol}"'","execer": "'"${tokenExecName}"'"}]}'
chain33_Http "$req" ${MAIN_HTTP} '(.error | not) and (.result[0].addr == "'"${tradeAddr}"'") and (.result[0].balance == 1000000000000)' "$FUNCNAME"
if [ "${res}" == "" ]; then
echo_rst "token get balance tx" 1
return
fi
addr=$(echo "${res}" | jq -r ".result[0].addr")
balance=$(echo "${res}" | jq -r ".result[0].balance")
if [ "${addr}" == "${tradeAddr}" ] && [ "${balance}" -eq 1000000000000 ]; then
echo_rst "token get balance tx" 0
else
echo_rst "token get balance tx" 1
fi
} }
function token_transfer() { function token_transfer() {
...@@ -75,11 +48,7 @@ function token_transfer() { ...@@ -75,11 +48,7 @@ function token_transfer() {
echo_rst "token transfer create tx" 1 echo_rst "token transfer create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "token transfer queryExecRes" "$?"
} }
function token_sendExec() { function token_sendExec() {
...@@ -89,11 +58,7 @@ function token_sendExec() { ...@@ -89,11 +58,7 @@ function token_sendExec() {
echo_rst "token sendExec create tx" 1 echo_rst "token sendExec create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "${addr}"
chain33_SignRawTx "${unsignedTx}" "${addr}" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "token sendExec queryExecRes" "$?"
} }
function trade_createSellTx() { function trade_createSellTx() {
...@@ -102,22 +67,13 @@ function trade_createSellTx() { ...@@ -102,22 +67,13 @@ function trade_createSellTx() {
echo_rst "trade createSellTx create tx" 1 echo_rst "trade createSellTx create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "trade createSellTx queryExecRes" "$?"
} }
function trade_getSellOrder() { function trade_getSellOrder() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesSellOrder","payload":{"addr": "'"${tradeAddr}"'","token":["'"${tokenSymbol}"'"]}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) req='{"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesSellOrder","payload":{"addr": "'"${tradeAddr}"'","token":["'"${tokenSymbol}"'"]}}]}'
result=$(echo "${res}" | jq -r ".error | not") chain33_Http "$req" ${MAIN_HTTP} '(.error | not)' "$FUNCNAME"
if [ "${result}" == true ]; then sellID=$(echo "${RETURN_RESP}" | jq -r ".result.orders[0].sellID" | awk -F '-' '{print $4}')
sellID=$(echo "${res}" | jq -r ".result.orders[0].sellID" | awk -F '-' '{print $4}')
echo_rst "trade getSellOrder" 0
else
echo_rst "trade getSellOrder" 1
fi
} }
function trade_createBuyTx() { function trade_createBuyTx() {
...@@ -126,66 +82,37 @@ function trade_createBuyTx() { ...@@ -126,66 +82,37 @@ function trade_createBuyTx() {
echo_rst "trade createBuyTx create tx" 1 echo_rst "trade createBuyTx create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "0xaeef1ad76d43a2056d0dcb57d5bf1ba96471550614ab9e7f611ef9c5ca403f42"
chain33_SignRawTx "${unsignedTx}" "0xaeef1ad76d43a2056d0dcb57d5bf1ba96471550614ab9e7f611ef9c5ca403f42" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "trade createBuyTx queryExecRes" "$?"
} }
function trade_getBuyOrder() { function trade_getBuyOrder() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesBuyOrder","payload":{"addr": "'"${tradeBuyerAddr}"'","token":["'"${tokenSymbol}"'"]}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error | not") req='{"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesBuyOrder","payload":{"addr": "'"${tradeBuyerAddr}"'","token":["'"${tokenSymbol}"'"]}}]}'
if [ "${res}" == true ]; then chain33_Http "$req" ${MAIN_HTTP} '(.error | not)' "$FUNCNAME"
echo_rst "trade getBuyOrder" 0
else
echo_rst "trade getBuyOrder" 1
fi
} }
function trade_statusBuyOrder() { function trade_statusBuyOrder() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesBuyOrderWithStatus","payload":{"addr": "'"${tradeBuyerAddr}"'","status":6}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error | not") req='{"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesBuyOrderWithStatus","payload":{"addr": "'"${tradeBuyerAddr}"'","status":6}}]}'
if [ "${res}" == true ]; then chain33_Http "$req" ${MAIN_HTTP} '(.error | not)' "$FUNCNAME"
echo_rst "trade getStatusBuyOrder" 0
else
echo_rst "trade getStatusBuyOrder" 1
fi
} }
function trade_statusOrder() { function trade_statusOrder() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesOrderWithStatus","payload":{"addr": "'"${tradeAddr}"'","status":1}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error | not") req='{"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesOrderWithStatus","payload":{"addr": "'"${tradeAddr}"'","status":1}}]}'
if [ "${res}" == true ]; then chain33_Http "$req" ${MAIN_HTTP} '(.error | not)' "$FUNCNAME"
echo_rst "trade getStatusOrder" 0
else
echo_rst "trade getStatusOrder" 1
fi
} }
function trade_statusSellOrder() { function trade_statusSellOrder() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesSellOrderWithStatus","payload":{"addr": "'"${tradeAddr}"'", "status":1}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error | not") req='{"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetOnesSellOrderWithStatus","payload":{"addr": "'"${tradeAddr}"'", "status":1}}]}'
if [ "${res}" == true ]; then chain33_Http "$req" ${MAIN_HTTP} '(.error | not)' "$FUNCNAME"
echo_rst "trade getStatusSellOrder" 0
else
echo_rst "trade getStatusSellOrder" 1
fi
} }
function trade_statusTokenBuyOrder() { function trade_statusTokenBuyOrder() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetTokenBuyOrderByStatus","payload":{"tokenSymbol": "'"${tokenSymbol}"'", "count" :1 , "direction": 1,"status":6}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error | not") req='{"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetTokenBuyOrderByStatus","payload":{"tokenSymbol": "'"${tokenSymbol}"'", "count" :1 , "direction": 1,"status":6}}]}'
if [ "${res}" == true ]; then chain33_Http "$req" ${MAIN_HTTP} '(.error | not)' "$FUNCNAME"
echo_rst "trade getTokenBuyOrder" 0
else
echo_rst "trade getTokenBuyOrder" 1
fi
} }
function trade_statusTokenSellOrder() { function trade_statusTokenSellOrder() {
res=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetTokenSellOrderByStatus","payload":{"tokenSymbol": "'"${tokenSymbol}"'", "count" :1 , "direction": 1,"status":1}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".error | not") req='{"method":"Chain33.Query","params":[{"execer":"'"${tradeExecName}"'","funcName":"GetTokenSellOrderByStatus","payload":{"tokenSymbol": "'"${tokenSymbol}"'", "count" :1 , "direction": 1,"status":1}}]}'
if [ "${res}" == true ]; then chain33_Http "$req" ${MAIN_HTTP} '(.error | not)' "$FUNCNAME"
echo_rst "trade getTokenSellOrder" 0
else
echo_rst "trade getTokenSellOrder" 1
fi
} }
function trade_buyLimit() { function trade_buyLimit() {
...@@ -194,11 +121,7 @@ function trade_buyLimit() { ...@@ -194,11 +121,7 @@ function trade_buyLimit() {
echo_rst "trade buyLimit create tx" 1 echo_rst "trade buyLimit create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "0xaeef1ad76d43a2056d0dcb57d5bf1ba96471550614ab9e7f611ef9c5ca403f42"
chain33_SignRawTx "${unsignedTx}" "0xaeef1ad76d43a2056d0dcb57d5bf1ba96471550614ab9e7f611ef9c5ca403f42" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "trade buyLimit queryExecRes" "$?"
buyID=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.QueryTransaction","params":[{"hash":"'"${RAW_TX_HASH}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.receipt.logs[1].log.base.buyID" | awk -F '-' '{print $4}') buyID=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.QueryTransaction","params":[{"hash":"'"${RAW_TX_HASH}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.receipt.logs[1].log.base.buyID" | awk -F '-' '{print $4}')
} }
...@@ -208,11 +131,7 @@ function trade_sellMarket() { ...@@ -208,11 +131,7 @@ function trade_sellMarket() {
echo_rst "trade sellMarket create tx" 1 echo_rst "trade sellMarket create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "${tradeAddr}"
chain33_SignRawTx "${unsignedTx}" "${tradeAddr}" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "trade sellMarket queryExecRes" "$?"
} }
function trade_revokeBuy() { function trade_revokeBuy() {
...@@ -221,11 +140,7 @@ function trade_revokeBuy() { ...@@ -221,11 +140,7 @@ function trade_revokeBuy() {
echo_rst "trade revokeBuy create tx" 1 echo_rst "trade revokeBuy create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "trade revokeBuy queryExecRes" "$?"
} }
function trade_revoke() { function trade_revoke() {
...@@ -234,11 +149,7 @@ function trade_revoke() { ...@@ -234,11 +149,7 @@ function trade_revoke() {
echo_rst "trade revoke create tx" 1 echo_rst "trade revoke create tx" 1
return return
fi fi
signRawTxAndQuery "$FUNCNAME" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
chain33_SignRawTx "${unsignedTx}" "0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "trade revoke queryExecRes" "$?"
} }
# 查询交易的执行结果 # 查询交易的执行结果
...@@ -255,6 +166,12 @@ function queryTransaction() { ...@@ -255,6 +166,12 @@ function queryTransaction() {
fi fi
} }
function signRawTxAndQuery() {
chain33_SignAndSendTx "${unsignedTx}" "$2" "${MAIN_HTTP}"
queryTransaction ".error | not" "true"
echo_rst "$1 queryExecRes" "$?"
}
function init() { function init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")') ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara" echo "ipara=$ispara"
...@@ -274,8 +191,6 @@ function init() { ...@@ -274,8 +191,6 @@ function init() {
fi fi
local main_ip=${MAIN_HTTP//8901/8801} local main_ip=${MAIN_HTTP//8901/8801}
#main chain import pri key
#1CvLe1qNaC7tCf5xmfAqJ9UJkMhtmhUKNg
chain33_ImportPrivkey "0xaeef1ad76d43a2056d0dcb57d5bf1ba96471550614ab9e7f611ef9c5ca403f42" "1CvLe1qNaC7tCf5xmfAqJ9UJkMhtmhUKNg" "trade1" "${main_ip}" chain33_ImportPrivkey "0xaeef1ad76d43a2056d0dcb57d5bf1ba96471550614ab9e7f611ef9c5ca403f42" "1CvLe1qNaC7tCf5xmfAqJ9UJkMhtmhUKNg" "trade1" "${main_ip}"
local ACCOUNT_A="1CvLe1qNaC7tCf5xmfAqJ9UJkMhtmhUKNg" local ACCOUNT_A="1CvLe1qNaC7tCf5xmfAqJ9UJkMhtmhUKNg"
...@@ -284,12 +199,10 @@ function init() { ...@@ -284,12 +199,10 @@ function init() {
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_A" 12000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip" chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
else else
# tx fee
chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}" chain33_applyCoins "$ACCOUNT_A" 1000000000 "${main_ip}"
chain33_QueryBalance "${ACCOUNT_A}" "$main_ip" chain33_QueryBalance "${ACCOUNT_A}" "$main_ip"
local para_ip="${MAIN_HTTP}" local para_ip="${MAIN_HTTP}"
#para chain import pri key
chain33_ImportPrivkey "0xaeef1ad76d43a2056d0dcb57d5bf1ba96471550614ab9e7f611ef9c5ca403f42" "1CvLe1qNaC7tCf5xmfAqJ9UJkMhtmhUKNg" "trade1" "$para_ip" chain33_ImportPrivkey "0xaeef1ad76d43a2056d0dcb57d5bf1ba96471550614ab9e7f611ef9c5ca403f42" "1CvLe1qNaC7tCf5xmfAqJ9UJkMhtmhUKNg" "trade1" "$para_ip"
chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}" chain33_applyCoins "$ACCOUNT_A" 12000000000 "${para_ip}"
...@@ -333,14 +246,13 @@ function run_test() { ...@@ -333,14 +246,13 @@ function run_test() {
} }
function main() { function main() {
local ip=$1
chain33_RpcTestBegin trade chain33_RpcTestBegin trade
local ip=$1
MAIN_HTTP=$ip MAIN_HTTP=$ip
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_test "$MAIN_HTTP" run_test "$MAIN_HTTP"
chain33_RpcTestRst trade "$CASE_ERR" chain33_RpcTestRst trade "$CASE_ERR"
} }
......
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2128 # shellcheck disable=SC2128
# shellcheck source=/dev/null # shellcheck source=/dev/null
source ../dapp-test-common.sh source ../dapp-test-common.sh
...@@ -10,28 +9,26 @@ txhash="" ...@@ -10,28 +9,26 @@ txhash=""
function query_unfreezeID() { function query_unfreezeID() {
chain33_BlockWait 1 "$MAIN_HTTP" chain33_BlockWait 1 "$MAIN_HTTP"
# echo "req=$req"
local times=10 local times=10
while true; do while true; do
req='{"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]}' req='{"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]}'
ret=$(curl -ksd "$req" ${MAIN_HTTP}) ret=$(curl -ksd "$req" ${MAIN_HTTP})
tx=$(jq -r ".result.tx.hash" <<<"$ret") tx=$(jq -r ".result.tx.hash" <<<"$ret")
echo "====query tx= ${txhash}, return=$ret " # echo "====query tx= ${txhash}, return=$ret "
if [ "${tx}" != "${txhash}" ]; then if [ "${tx}" != "${txhash}" ]; then
chain33_BlockWait 1 "${MAIN_HTTP}" chain33_BlockWait 1 "${MAIN_HTTP}"
times=$((times - 1)) times=$((times - 1))
if [ $times -le 0 ]; then if [ $times -le 0 ]; then
echo "====query tx=$txhash failed" echo -e "${RED}====query tx=$txhash failed${NOC}"
echo "req=$req" echo "req=$req"
curl -ksd "$req" ${MAIN_HTTP} curl -ksd "$req" ${MAIN_HTTP}
exit 1 exit 1
fi fi
else else
unfreeze_id=$(jq '(.result.receipt.logs['"$uid_index"'].log.current.unfreezeID)' <<<"$ret") unfreeze_id=$(jq '(.result.receipt.logs['"$uid_index"'].log.current.unfreezeID)' <<<"$ret")
#echo "${unfreeze_id}"
unfreeze_id2=${unfreeze_id#\"mavl-unfreeze-} unfreeze_id2=${unfreeze_id#\"mavl-unfreeze-}
uid=${unfreeze_id2%\"} uid=${unfreeze_id2%\"}
echo "====query tx=$txhash success" echo -e "${GRE}====query tx=$txhash success${NOC}"
break break
fi fi
done done
...@@ -75,89 +72,51 @@ function init() { ...@@ -75,89 +72,51 @@ function init() {
function CreateRawUnfreezeCreate() { function CreateRawUnfreezeCreate() {
req='{"jsonrpc": "2.0", "method" : "unfreeze.CreateRawUnfreezeCreate" , "params":[{"startTime":10000,"assetExec":"coins","assetSymbol":"'$symbol'","totalCount":400000000,"beneficiary":"'$beneficiary'","means":"FixAmount","fixAmount": {"period":10,"amount":1000000}}]}' req='{"jsonrpc": "2.0", "method" : "unfreeze.CreateRawUnfreezeCreate" , "params":[{"startTime":10000,"assetExec":"coins","assetSymbol":"'$symbol'","totalCount":400000000,"beneficiary":"'$beneficiary'","means":"FixAmount","fixAmount": {"period":10,"amount":1000000}}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "$owner_key" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "$owner_key" "${MAIN_HTTP}"
query_unfreezeID query_unfreezeID
} }
function CreateRawUnfreezeWithdraw() { function CreateRawUnfreezeWithdraw() {
sleep 10 sleep 10
req='{"method":"unfreeze.CreateRawUnfreezeWithdraw","params":[{"unfreezeID":"'${uid}'"}]}' req='{"method":"unfreeze.CreateRawUnfreezeWithdraw","params":[{"unfreezeID":"'${uid}'"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "${beneficiary_key}" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "${beneficiary_key}" "${MAIN_HTTP}"
} }
function CreateRawUnfreezeTerminate() { function CreateRawUnfreezeTerminate() {
req='{"method":"unfreeze.CreateRawUnfreezeTerminate","params":[{"unfreezeID":"'${uid}'"}]}' req='{"method":"unfreeze.CreateRawUnfreezeTerminate","params":[{"unfreezeID":"'${uid}'"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME" ".result"
resp=$(curl -ksd "$req" "${MAIN_HTTP}") chain33_SignAndSendTx "$RETURN_RESP" "$owner_key" "${MAIN_HTTP}"
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
chain33_SignRawTx "$rawtx" "$owner_key" "${MAIN_HTTP}"
chain33_BlockWait 2 "${MAIN_HTTP}" chain33_BlockWait 2 "${MAIN_HTTP}"
} }
function GetUnfreeze() { function GetUnfreeze() {
req='{"method":"unfreeze.GetUnfreeze","params":[{"data":"'${uid}'"}]}' req='{"method":"unfreeze.GetUnfreeze","params":[{"data":"'${uid}'"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function GetUnfreezeWithdraw() { function GetUnfreezeWithdraw() {
req='{"method":"unfreeze.GetUnfreezeWithdraw","params":[{"data":"'${uid}'"}]}' req='{"method":"unfreeze.GetUnfreezeWithdraw","params":[{"data":"'${uid}'"}]}'
# echo "#request: $req" chain33_Http "$req" ${MAIN_HTTP} '(.error|not) and (.result != null)' "$FUNCNAME"
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
# echo "#resp: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
} }
function run_testcases() { function run_testcases() {
CreateRawUnfreezeCreate CreateRawUnfreezeCreate
CreateRawUnfreezeWithdraw CreateRawUnfreezeWithdraw
GetUnfreeze GetUnfreeze
GetUnfreezeWithdraw GetUnfreezeWithdraw
CreateRawUnfreezeTerminate CreateRawUnfreezeTerminate
} }
function debug_function() {
set -x
eval "$@"
set +x
}
function rpc_test() { function rpc_test() {
chain33_RpcTestBegin unfreeze chain33_RpcTestBegin unfreeze
MAIN_HTTP="$1" MAIN_HTTP="$1"
echo "main_ip=$MAIN_HTTP" echo "main_ip=$MAIN_HTTP"
init init
run_testcases run_testcases
chain33_RpcTestRst unfreeze "$CASE_ERR" chain33_RpcTestRst unfreeze "$CASE_ERR"
} }
debug_function rpc_test "$1" chain33_debug_function rpc_test "$1"
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