Commit 8687a4d2 authored by 张振华's avatar 张振华

Merge branch 'master' into guess-rpc-test

parents 3610d578 6fae0e58
#!/usr/bin/env bash
RAW_TX_HASH=""
CASE_ERR=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
echo_rst() {
if [ "$2" -eq 0 ]; then
echo -e "${GRE}$1 ok${NOC}"
elif [ "$2" -eq 2 ]; then
echo -e "${GRE}$1 not support${NOC}"
CASE_ERR="err"
echo $CASE_ERR
else
echo -e "${RED}$1 fail${NOC}"
CASE_ERR="err"
echo $CASE_ERR
fi
}
chain33_BlockWait() {
local MAIN_HTTP=$2
local req='"method":"Chain33.GetLastHeader","params":[]'
cur_height=$(curl -ksd "{$req}" "${MAIN_HTTP}" | jq ".result.height")
expect=$((cur_height + ${1}))
local count=0
while true; do
new_height=$(curl -ksd "{$req}" "${MAIN_HTTP}" | jq ".result.height")
if [ "${new_height}" -ge "${expect}" ]; then
break
fi
count=$((count + 1))
sleep 1
done
echo "wait new block $count s, cur height=$expect,old=$cur_height"
}
chain33_QueryTx() {
local MAIN_HTTP=$2
chain33_BlockWait 1 "$MAIN_HTTP"
local txhash="$1"
local req='"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]'
local times=10
while true; do
ret=$(curl -ksd "{$req}" "${MAIN_HTTP}" | jq -r ".result.tx.hash")
if [ "${ret}" != "${1}" ]; then
chain33_BlockWait 1 "$MAIN_HTTP"
times=$((times - 1))
if [ $times -le 0 ]; then
echo "====query tx=$1 failed"
curl -ksd "{$req}" "${MAIN_HTTP}"
exit 1
fi
else
RAW_TX_HASH=$txhash
echo "====query tx=$RAW_TX_HASH success"
break
fi
done
}
chain33_SendTx() {
local signedTx=$1
local MAIN_HTTP=$2
req='"method":"Chain33.SendTransaction","params":[{"token":"BTY","data":"'"$signedTx"'"}]'
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
err=$(jq '(.error)' <<<"$resp")
txhash=$(jq -r ".result" <<<"$resp")
if [ "$err" == null ]; then
chain33_QueryTx "$txhash" "$MAIN_HTTP"
else
echo "send tx error:$err"
fi
}
chain33_SendToAddress() {
local from="$1"
local to="$2"
local amount=$3
local MAIN_HTTP=$4
local req='"method":"Chain33.SendToAddress", "params":[{"from":"'"$from"'","to":"'"$to"'", "amount":'"$amount"', "note":"test\n"}]'
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
ok=$(jq '(.error|not) and (.result.hash|length==66)' <<<"$resp")
[ "$ok" == true ]
hash=$(jq -r ".result.hash" <<<"$resp")
chain33_QueryTx "$hash" "$MAIN_HTTP"
}
chain33_ImportPrivkey() {
local pri="$1"
local acc="$2"
local label="$3"
local MAIN_HTTP=$4
local req='"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'"$pri"'", "label":"'"$label"'"}]'
resp=$(curl -ksd "{$req}" "$MAIN_HTTP")
ok=$(jq '(.error|not) and (.result.label=="'"$label"'") and (.result.acc.addr == "'"$acc"'")' <<<"$resp")
[ "$ok" == true ]
}
chain33_SignRawTx() {
local txHex="$1"
local priKey="$2"
local MAIN_HTTP=$3
local req='"method":"Chain33.SignRawTx","params":[{"privkey":"'"$priKey"'","txHex":"'"$txHex"'","expire":"120s"}]'
signedTx=$(curl -ksd "{$req}" "${MAIN_HTTP}" | jq -r ".result")
if [ "$signedTx" != null ]; then
chain33_SendTx "$signedTx" "${MAIN_HTTP}"
else
echo "signedTx null error"
fi
}
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
# shellcheck disable=SC2128 # shellcheck disable=SC2128
RPC_TESTFILE=test-rpc.sh RPC_TESTFILE=test-rpc.sh
DAPP_TEST_COMMON=dapp-test-common.sh
function dapp_test_rpc() { function dapp_test_rpc() {
local ip=$1 local ip=$1
echo "============ # dapp rpc test begin =============" echo "============ # dapp rpc test begin ============="
if [ -d dapptest ]; then if [ -d dapptest ]; then
cp $DAPP_TEST_COMMON dapptest/
cd dapptest || return cd dapptest || return
dir=$(find . -maxdepth 1 -type d ! -name dapptest ! -name . | sed 's/^\.\///') dir=$(find . -maxdepth 1 -type d ! -name dapptest ! -name . | sed 's/^\.\///')
for app in $dir; do for app in $dir; do
......
...@@ -78,6 +78,9 @@ function base_init() { ...@@ -78,6 +78,9 @@ function base_init() {
sed -i $sedfix 's/^Title.*/Title="local"/g' chain33.toml sed -i $sedfix 's/^Title.*/Title="local"/g' chain33.toml
sed -i $sedfix 's/^TestNet=.*/TestNet=true/g' chain33.toml sed -i $sedfix 's/^TestNet=.*/TestNet=true/g' chain33.toml
sed -i $sedfix 's/^powLimitBits=.*/powLimitBits="0x1f2fffff"/g' chain33.toml
sed -i $sedfix 's/^targetTimePerBlock=.*/targetTimePerBlock=1/g' chain33.toml
# p2p # p2p
sed -i $sedfix 's/^seeds=.*/seeds=["chain33:13802","chain32:13802","chain31:13802"]/g' chain33.toml sed -i $sedfix 's/^seeds=.*/seeds=["chain33:13802","chain32:13802","chain31:13802"]/g' chain33.toml
#sed -i $sedfix 's/^enable=.*/enable=true/g' chain33.toml #sed -i $sedfix 's/^enable=.*/enable=true/g' chain33.toml
...@@ -96,6 +99,9 @@ function base_init() { ...@@ -96,6 +99,9 @@ function base_init() {
sed -i $sedfix 's/^nodeGroupFrozenCoins=.*/nodeGroupFrozenCoins=20/g' chain33.toml sed -i $sedfix 's/^nodeGroupFrozenCoins=.*/nodeGroupFrozenCoins=20/g' chain33.toml
# ticket
sed -i $sedfix 's/^ticketPrice =.*/ticketPrice = 10000/g' chain33.toml
} }
function start() { function start() {
...@@ -140,7 +146,7 @@ function start() { ...@@ -140,7 +146,7 @@ function start() {
${CLI} block hash -t 0 ${CLI} block hash -t 0
res=$(${CLI} block hash -t 0 | jq -r ".hash") res=$(${CLI} block hash -t 0 | jq -r ".hash")
#in case changes result in genesis change #in case changes result in genesis change
if [ "${res}" != "0xa87972dfc3510cb934cb987bcb88036f7a1ffd7dc069cb9a5f0af179895fd2e8" ]; then if [ "${res}" != "0x67c58d6ba9175313f0468ae4e0ddec946549af7748037c2fdd5d54298afd20b6" ]; then
echo "genesis hash error!" echo "genesis hash error!"
exit 1 exit 1
fi fi
...@@ -200,6 +206,7 @@ function miner() { ...@@ -200,6 +206,7 @@ function miner() {
fi fi
sleep 1 sleep 1
echo "=========== # close auto mining =============" echo "=========== # close auto mining ============="
result=$(${1} wallet auto_mine -f 0 | jq ".isok") result=$(${1} wallet auto_mine -f 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
...@@ -328,6 +335,30 @@ function transfer() { ...@@ -328,6 +335,30 @@ function transfer() {
block_wait "${1}" 1 block_wait "${1}" 1
} }
function dapp_test_address() {
echo "=========== # import private key dapptest1 mining ============="
result=$(${1} account import_key -k 56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138 -l dapptest1 | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
sleep 1
echo "=========== # import private key dapptest2 mining ============="
result=$(${1} account import_key -k 2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989 -l dapptest2 | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
sleep 1
hash=$(${1} send coins transfer -a 1500 -n transfer -t 1PUiGcbsccfxW3zuvHXZBJfznziph5miAo -k 2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989)
echo "${hash}"
block_wait "${1}" 1
}
function base_config() { function base_config() {
# sync # sync
transfer "${CLI}" transfer "${CLI}"
...@@ -337,10 +368,12 @@ function base_config() { ...@@ -337,10 +368,12 @@ function base_config() {
function rpc_test() { function rpc_test() {
if [ "$DAPP" == "" ]; then if [ "$DAPP" == "" ]; then
system_test_rpc "http://${1}:8801" system_test_rpc "http://${1}:8801"
dapp_test_address "${CLI}"
dapp_test_rpc "http://${1}:8801" dapp_test_rpc "http://${1}:8801"
fi fi
if [ "$DAPP" == "paracross" ]; then if [ "$DAPP" == "paracross" ]; then
#system_test_rpc "http://${1}:8901" system_test_rpc "http://${1}:8901"
dapp_test_address "${CLI}"
dapp_test_rpc "http://${1}:8901" dapp_test_rpc "http://${1}:8901"
fi fi
...@@ -370,7 +403,7 @@ function main() { ...@@ -370,7 +403,7 @@ function main() {
dapp_run test "${ip}" dapp_run test "${ip}"
### rpc test ### ### rpc test ###
rpc_test "${ip}" # rpc_test "${ip}"
### finish ### ### finish ###
check_docker_container check_docker_container
......
...@@ -92,7 +92,7 @@ fundKeyAddr = "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5" ...@@ -92,7 +92,7 @@ fundKeyAddr = "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
coinReward = 18 coinReward = 18
coinDevFund = 12 coinDevFund = 12
ticketPrice = 10000 ticketPrice = 10000
powLimitBits = "0x1f00ffff" powLimitBits="0x1f00ffff"
retargetAdjustmentFactor = 4 retargetAdjustmentFactor = 4
futureBlockTime = 16 futureBlockTime = 16
ticketFrozenTime = 5 #5s only for test ticketFrozenTime = 5 #5s only for test
...@@ -100,7 +100,7 @@ ticketWithdrawTime = 10 #10s only for test ...@@ -100,7 +100,7 @@ ticketWithdrawTime = 10 #10s only for test
ticketMinerWaitTime = 2 #2s only for test ticketMinerWaitTime = 2 #2s only for test
maxTxNumber = 1600 #160 maxTxNumber = 1600 #160
targetTimespan = 2304 targetTimespan = 2304
targetTimePerBlock = 16 targetTimePerBlock=16
[mver.consensus.ForkChainParamV1] [mver.consensus.ForkChainParamV1]
futureBlockTime = 15 futureBlockTime = 15
......
...@@ -438,7 +438,7 @@ func (client *commitMsgClient) getNodeStatus(start, end int64) ([]*pt.ParacrossN ...@@ -438,7 +438,7 @@ func (client *commitMsgClient) getNodeStatus(start, end int64) ([]*pt.ParacrossN
//2,如果20个块都是 commit tx的空块,20个块打包一次发送,尽量减少commit tx造成的空块 //2,如果20个块都是 commit tx的空块,20个块打包一次发送,尽量减少commit tx造成的空块
//3,如果形如xxoxx的块排列,x代表commit空块,o代表实际的块,即只要不全部是commit块,也要全部打包一起发出去 //3,如果形如xxoxx的块排列,x代表commit空块,o代表实际的块,即只要不全部是commit块,也要全部打包一起发出去
//如果=0 意味着全部是paracross commit tx,延迟发送 //如果=0 意味着全部是paracross commit tx,延迟发送
if needSentTxs == 0 && count < types.TxGroupMaxCount { if needSentTxs == 0 && len(ret) < types.TxGroupMaxCount {
plog.Debug("para commitmsg getNodeStatus all self consensus commit tx,send delay", "start", start, "end", end) plog.Debug("para commitmsg getNodeStatus all self consensus commit tx,send delay", "start", start, "end", end)
return nil, nil return nil, nil
} }
......
...@@ -244,7 +244,7 @@ function run_testcases() { ...@@ -244,7 +244,7 @@ function run_testcases() {
blackwhite_BlackwhiteTimeoutDoneTx "$gID" blackwhite_BlackwhiteTimeoutDoneTx "$gID"
#查询部分 #查询部分
block_wait 1 block_wait 3
blackwhite_GetBlackwhiteRoundInfo "$gID" blackwhite_GetBlackwhiteRoundInfo "$gID"
blackwhite_GetBlackwhiteByStatusAndAddr "$gID" "${gameAddr1}" blackwhite_GetBlackwhiteByStatusAndAddr "$gID" "${gameAddr1}"
blackwhite_GetBlackwhiteloopResult "$gID" blackwhite_GetBlackwhiteloopResult "$gID"
......
...@@ -23,48 +23,34 @@ echo_rst() { ...@@ -23,48 +23,34 @@ echo_rst() {
lottery_addCreator_unsignedTx="0a066d616e616765123c0a3a0a0f6c6f74746572792d63726561746f721222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630c788b8f7ccbadbc0703a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32" lottery_addCreator_unsignedTx="0a066d616e616765123c0a3a0a0f6c6f74746572792d63726561746f721222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630c788b8f7ccbadbc0703a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32"
lottery_addCreator_unsignedTx_para="0a12757365722e702e706172612e6d616e616765123c0a3a0a0f6c6f74746572792d63726561746f721222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630a8bba1b887e7dade2b3a22314469484633317577783977356a6a733571514269474a6b4e686e71656564763157" lottery_addCreator_unsignedTx_para="0a12757365722e702e706172612e6d616e616765123c0a3a0a0f6c6f74746572792d63726561746f721222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630a8bba1b887e7dade2b3a22314469484633317577783977356a6a733571514269474a6b4e686e71656564763157"
lottery_creator_addr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" lottery_creator_addr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
lottery_creator_priv="0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
gID="" gID=""
gResp="" gResp=""
glAddr=""
gameAddr1=""
gameAddr2=""
gameAddr3=""
lottExecAddr="" lottExecAddr=""
luckyNumber=""
purNum=30 purNum=30
drawNum=40 drawNum=40
opRatio=5 opRatio=5
devRatio=5 devRatio=5
luckyNumber=""
init() { init() {
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
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_SendTransaction "${lottery_addCreator_unsignedTx_para}" "${lottery_creator_addr}" chain33_SendTransaction "${lottery_addCreator_unsignedTx_para}" "${lottery_creator_priv}"
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_SendTransaction "${lottery_addCreator_unsignedTx}" "${lottery_creator_addr}" chain33_SendTransaction "${lottery_addCreator_unsignedTx}" "${lottery_creator_priv}"
fi fi
echo "lottExecAddr=$lottExecAddr" echo "lottExecAddr=$lottExecAddr"
} }
chain33_NewAccount() {
label=$1
result=$(curl -ksd '{"method":"Chain33.NewAccount","params":[{"label":"'"$label"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.acc.addr")
[[ $result != "" ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
glAddr=$result
echo "$glAddr"
}
function block_wait() { function block_wait() {
if [[ $# -lt 1 ]]; then if [[ $# -lt 1 ]]; then
echo "wrong block_wait params" echo "wrong block_wait params"
...@@ -142,10 +128,12 @@ chain33_SendToAddress() { ...@@ -142,10 +128,12 @@ chain33_SendToAddress() {
chain33_SendTransaction() { chain33_SendTransaction() {
rawTx=$1 rawTx=$1
addr=$2 priv=$2
#签名交易 #签名交易
resp=$(curl -ksd '{"method":"Chain33.SignRawTx","params":[{"addr":"'"$addr"'","txHex":"'"$rawTx"'","expire":"120s","fee":10000000,"index":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) set -x
resp=$(curl -ksd '{"method":"Chain33.SignRawTx","params":[{"privkey":"'"$priv"'","txHex":"'"$rawTx"'","expire":"120s","fee":10000000,"index":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(echo "${resp}" | jq -r ".error") ok=$(echo "${resp}" | jq -r ".error")
set +x
[[ $ok == null ]] [[ $ok == null ]]
rst=$? rst=$?
echo_rst "chain33_SignRawTx" "$rst" echo_rst "chain33_SignRawTx" "$rst"
...@@ -166,7 +154,7 @@ chain33_SendTransaction() { ...@@ -166,7 +154,7 @@ chain33_SendTransaction() {
lottery_LotteryCreate() { lottery_LotteryCreate() {
#创建交易 #创建交易
addr=$1 priv=$1
set -x set -x
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryCreate", resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryCreate",
"payload":{"purBlockNum":'"$purNum"',"drawBlockNum":'"$drawNum"', "opRewardRatio":'"$opRatio"',"devRewardRatio":'"$devRatio"',"fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) "payload":{"purBlockNum":'"$purNum"',"drawBlockNum":'"$drawNum"', "opRewardRatio":'"$opRatio"',"devRewardRatio":'"$devRatio"',"fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
...@@ -177,14 +165,14 @@ lottery_LotteryCreate() { ...@@ -177,14 +165,14 @@ lottery_LotteryCreate() {
echo_rst "$FUNCNAME" "$rst" echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${addr}" chain33_SendTransaction "${rawTx}" "${priv}"
gID="${gResp}" gID="${gResp}"
echo "gameID $gID" echo "gameID $gID"
} }
lottery_LotteryBuy() { lottery_LotteryBuy() {
#创建交易 #创建交易
addr=$1 priv=$1
amount=$2 amount=$2
number=$3 number=$3
way=$4 way=$4
...@@ -198,12 +186,12 @@ lottery_LotteryBuy() { ...@@ -198,12 +186,12 @@ lottery_LotteryBuy() {
echo_rst "$FUNCNAME" "$rst" echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${addr}" chain33_SendTransaction "${rawTx}" "${priv}"
} }
lottery_LotteryDraw() { lottery_LotteryDraw() {
#创建交易 #创建交易
addr=$1 priv=$1
set -x set -x
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryDraw", resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryDraw",
"payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) "payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
...@@ -214,12 +202,12 @@ lottery_LotteryDraw() { ...@@ -214,12 +202,12 @@ lottery_LotteryDraw() {
echo_rst "$FUNCNAME" "$rst" echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${addr}" chain33_SendTransaction "${rawTx}" "${priv}"
} }
lottery_LotteryClose() { lottery_LotteryClose() {
#创建交易 #创建交易
addr=$1 priv=$1
set -x set -x
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryClose", resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryClose",
"payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) "payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
...@@ -230,7 +218,7 @@ lottery_LotteryClose() { ...@@ -230,7 +218,7 @@ lottery_LotteryClose() {
echo_rst "$FUNCNAME" "$rst" echo_rst "$FUNCNAME" "$rst"
#发送交易 #发送交易
rawTx=$(echo "${resp}" | jq -r ".result") rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${addr}" chain33_SendTransaction "${rawTx}" "${priv}"
} }
lottery_GetLotteryNormalInfo() { lottery_GetLotteryNormalInfo() {
...@@ -377,27 +365,20 @@ lottery_GetLotteryRoundGainInfo() { ...@@ -377,27 +365,20 @@ lottery_GetLotteryRoundGainInfo() {
} }
function run_testcases() { function run_testcases() {
#先创建账户地址 #账户地址
chain33_NewAccount "lottery111" gameAddr1="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
gameAddr1="${glAddr}" gamePriv1="0x56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138"
chain33_NewAccount "lottery222" gameAddr2="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
gameAddr2="${glAddr}" gamePriv2="0x2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989"
chain33_NewAccount "lottery333" #该账户需要转账
gameAddr3="${glAddr}" gameAddr3="12HKLEn6g4FH39yUbHh4EVJWcFo5CXg22d"
gamePriv3="0x9d4f8ab11361be596468b265cb66946c87873d4a119713fd0c3d8302eae0a8e4"
#给每个账户分别转帐
origAddr="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
#主链中相应账户需要转帐 #主链中相应账户需要转帐
M_HTTP=${MAIN_HTTP//8901/8801} M_HTTP=${MAIN_HTTP//8901/8801}
chain33_SendToAddress "${origAddr}" "${gameAddr1}" 300000000 "${M_HTTP}" chain33_SendToAddress "${gameAddr1}" "${gameAddr3}" 300000000 "${M_HTTP}"
chain33_SendToAddress "${origAddr}" "${gameAddr2}" 300000000 "${M_HTTP}"
chain33_SendToAddress "${origAddr}" "${gameAddr3}" 300000000 "${M_HTTP}"
#平行链相应账户需要转帐 #平行链相应账户需要转帐
chain33_SendToAddress "${origAddr}" "${gameAddr1}" 300000000 "${MAIN_HTTP}" chain33_SendToAddress "${gameAddr1}" "${gameAddr3}" 300000000 "${MAIN_HTTP}"
chain33_SendToAddress "${origAddr}" "${gameAddr2}" 300000000 "${MAIN_HTTP}"
chain33_SendToAddress "${origAddr}" "${gameAddr3}" 300000000 "${MAIN_HTTP}"
#给游戏合约中转帐 #给游戏合约中转帐
chain33_SendToAddress "${gameAddr1}" "${lottExecAddr}" 200000000 "${MAIN_HTTP}" chain33_SendToAddress "${gameAddr1}" "${lottExecAddr}" 200000000 "${MAIN_HTTP}"
...@@ -405,14 +386,14 @@ function run_testcases() { ...@@ -405,14 +386,14 @@ function run_testcases() {
chain33_SendToAddress "${gameAddr3}" "${lottExecAddr}" 200000000 "${MAIN_HTTP}" chain33_SendToAddress "${gameAddr3}" "${lottExecAddr}" 200000000 "${MAIN_HTTP}"
#创建游戏 #创建游戏
lottery_LotteryCreate "${lottery_creator_addr}" lottery_LotteryCreate "${lottery_creator_priv}"
lottery_GetLotteryNormalInfo "$gID" "${lottery_creator_addr}" lottery_GetLotteryNormalInfo "$gID" "${lottery_creator_addr}"
lottery_GetLotteryCurrentInfo "$gID" 1 0 lottery_GetLotteryCurrentInfo "$gID" 1 0
#第一次投注 #第一次投注
lottery_LotteryBuy "${gameAddr1}" 1 12345 1 lottery_LotteryBuy "${gamePriv1}" 1 12345 1
lottery_LotteryBuy "${gameAddr2}" 1 66666 2 lottery_LotteryBuy "${gamePriv2}" 1 66666 2
lottery_LotteryBuy "${gameAddr3}" 1 56789 5 lottery_LotteryBuy "${gamePriv3}" 1 56789 5
#查询 #查询
lottery_GetLotteryCurrentInfo "$gID" 2 3 lottery_GetLotteryCurrentInfo "$gID" 2 3
lottery_GetLotteryPurchaseAddr "$gID" 3 lottery_GetLotteryPurchaseAddr "$gID" 3
...@@ -420,8 +401,8 @@ function run_testcases() { ...@@ -420,8 +401,8 @@ function run_testcases() {
lottery_GetLotteryBuyRoundInfo "$gID" "${gameAddr2}" 1 1 "66666" lottery_GetLotteryBuyRoundInfo "$gID" "${gameAddr2}" 1 1 "66666"
#第二次投注 #第二次投注
lottery_LotteryBuy "${gameAddr1}" 1 12321 1 lottery_LotteryBuy "${gamePriv1}" 1 12321 1
lottery_LotteryBuy "${gameAddr3}" 1 78987 5 lottery_LotteryBuy "${gamePriv3}" 1 78987 5
#查询 #查询
lottery_GetLotteryCurrentInfo "$gID" 2 5 lottery_GetLotteryCurrentInfo "$gID" 2 5
lottery_GetLotteryPurchaseAddr "$gID" 3 lottery_GetLotteryPurchaseAddr "$gID" 3
...@@ -430,7 +411,7 @@ function run_testcases() { ...@@ -430,7 +411,7 @@ function run_testcases() {
#游戏开奖 #游戏开奖
block_wait ${drawNum} "${M_HTTP}" block_wait ${drawNum} "${M_HTTP}"
lottery_LotteryDraw "${lottery_creator_addr}" lottery_LotteryDraw "${lottery_creator_priv}"
lottery_GetLotteryCurrentInfo "$gID" 3 0 lottery_GetLotteryCurrentInfo "$gID" 3 0
#游戏查询 #游戏查询
...@@ -442,7 +423,7 @@ function run_testcases() { ...@@ -442,7 +423,7 @@ function run_testcases() {
lottery_GetLotteryRoundGainInfo "$gID" "${gameAddr3}" 1 2 lottery_GetLotteryRoundGainInfo "$gID" "${gameAddr3}" 1 2
#关闭游戏 #关闭游戏
lottery_LotteryClose "${lottery_creator_addr}" lottery_LotteryClose "${lottery_creator_priv}"
lottery_GetLotteryCurrentInfo "$gID" 4 0 lottery_GetLotteryCurrentInfo "$gID" 4 0
} }
......
...@@ -108,6 +108,8 @@ searchHashMatchedBlockDepth=10000 ...@@ -108,6 +108,8 @@ searchHashMatchedBlockDepth=10000
genesisAmount=100000000 genesisAmount=100000000
#主链支持平行链共识tx分叉高度,需要和主链保持严格一致 #主链支持平行链共识tx分叉高度,需要和主链保持严格一致
MainForkParacrossCommitTx=-1 MainForkParacrossCommitTx=-1
#平行链自共识开启对应的主链高度,需要大于等于MainForkParacrossCommitTx
MainParaSelfConsensusForkHeight=-1
[store] [store]
name="mavl" name="mavl"
...@@ -154,7 +156,7 @@ tokenApprs = [ ...@@ -154,7 +156,7 @@ tokenApprs = [
] ]
[exec.sub.paracross] [exec.sub.paracross]
#平行链自共识停止n个后,超级账户可以直接参与投票 #平行链自共识停止n个空块的对应主链高度后,超级账户可以直接参与投票
paraConsensusStopBlocks=100 paraConsensusStopBlocks=100
[pprof] [pprof]
......
...@@ -38,7 +38,7 @@ function para_set_toml() { ...@@ -38,7 +38,7 @@ function para_set_toml() {
sed -i $xsedfix 's/^emptyBlockInterval=.*/emptyBlockInterval=4/g' "${1}" sed -i $xsedfix 's/^emptyBlockInterval=.*/emptyBlockInterval=4/g' "${1}"
sed -i $xsedfix '/^emptyBlockInterval=.*/a MainBlockHashForkHeight=1' "${1}" sed -i $xsedfix '/^emptyBlockInterval=.*/a MainBlockHashForkHeight=1' "${1}"
sed -i $xsedfix '/^emptyBlockInterval=.*/a MainParaSelfConsensusForkHeight=50' "${1}" sed -i $xsedfix 's/^MainParaSelfConsensusForkHeight=.*/MainParaSelfConsensusForkHeight=50/g' "${1}"
sed -i $xsedfix 's/^MainForkParacrossCommitTx=.*/MainForkParacrossCommitTx=1/g' "${1}" sed -i $xsedfix 's/^MainForkParacrossCommitTx=.*/MainForkParacrossCommitTx=1/g' "${1}"
# rpc # rpc
...@@ -61,6 +61,10 @@ function para_set_wallet() { ...@@ -61,6 +61,10 @@ function para_set_wallet() {
para_import_key "${PARA_CLI}" "0x4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" "test" para_import_key "${PARA_CLI}" "0x4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01" "test"
#1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY #1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY
para_import_key "${PARA_CLI}" "0x9c451df9e5cb05b88b28729aeaaeb3169a2414097401fcb4c79c1971df734588" "relay" para_import_key "${PARA_CLI}" "0x9c451df9e5cb05b88b28729aeaaeb3169a2414097401fcb4c79c1971df734588" "relay"
#1PUiGcbsccfxW3zuvHXZBJfznziph5miAo
para_import_key "${PARA_CLI}" "0x56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" "dapptest1"
#1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX
para_import_key "${PARA_CLI}" "0x2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" "dapptest2"
#super node behalf test #super node behalf test
#1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj #1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj
...@@ -117,6 +121,8 @@ function para_transfer() { ...@@ -117,6 +121,8 @@ function para_transfer() {
#relay rpc test #relay rpc test
para_transfer2account "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" para_transfer2account "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
para_transfer2account "1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY" para_transfer2account "1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY"
para_transfer2account "1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
para_transfer2account "1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
block_wait "${CLI}" 2 block_wait "${CLI}" 2
echo "=========== # main chain send to paracross =============" echo "=========== # main chain send to paracross ============="
...@@ -597,6 +603,7 @@ function para_nodegroup_behalf_quit_test() { ...@@ -597,6 +603,7 @@ function para_nodegroup_behalf_quit_test() {
${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b ${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b
${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4 ${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4
${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x9c451df9e5cb05b88b28729aeaaeb3169a2414097401fcb4c79c1971df734588
hash=$(${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115) hash=$(${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115)
echo "${hash}" echo "${hash}"
query_tx "${PARA_CLI}" "${hash}" query_tx "${PARA_CLI}" "${hash}"
...@@ -663,6 +670,7 @@ function para_nodemanage_test() { ...@@ -663,6 +670,7 @@ function para_nodemanage_test() {
echo "=========== # para chain node vote quit =============" echo "=========== # para chain node vote quit ============="
${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b ${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b
${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4 ${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4
${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x9c451df9e5cb05b88b28729aeaaeb3169a2414097401fcb4c79c1971df734588
hash=$(${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115) hash=$(${PARA_CLI} send para node -o vote -a 1E5saiXVb9mW8wcWUUZjsHJPZs5GmdzuSY -v yes -k 0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115)
echo "${hash}" echo "${hash}"
query_tx "${PARA_CLI}" "${hash}" query_tx "${PARA_CLI}" "${hash}"
...@@ -718,6 +726,7 @@ function para_nodemanage_test() { ...@@ -718,6 +726,7 @@ function para_nodemanage_test() {
echo "=========== # para chain node vote quit =============" echo "=========== # para chain node vote quit ============="
${PARA_CLI} send para node -o vote -a 1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB -v yes -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b ${PARA_CLI} send para node -o vote -a 1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB -v yes -k 0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b
${PARA_CLI} send para node -o vote -a 1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB -v yes -k 0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4 ${PARA_CLI} send para node -o vote -a 1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB -v yes -k 0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4
${PARA_CLI} send para node -o vote -a 1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB -v yes -k 0x794443611e7369a57b078881445b93b754cbc9b9b8f526535ab9c6d21d29203d
hash=$(${PARA_CLI} send para node -o vote -a 1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB -v yes -k 0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115) hash=$(${PARA_CLI} send para node -o vote -a 1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB -v yes -k 0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115)
echo "${hash}" echo "${hash}"
query_tx "${PARA_CLI}" "${hash}" query_tx "${PARA_CLI}" "${hash}"
......
...@@ -332,7 +332,7 @@ func nodeGroupApply(cmd *cobra.Command, args []string) { ...@@ -332,7 +332,7 @@ func nodeGroupApply(cmd *cobra.Command, args []string) {
payload := &pt.ParaNodeGroupConfig{Op: op, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4} payload := &pt.ParaNodeGroupConfig{Op: op, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pt.ParaX), Execer: types.ExecName(pt.ParaX),
ActionName: "NodeGroupApply", ActionName: "NodeGroupConfig",
Payload: types.MustPBToJSON(payload), Payload: types.MustPBToJSON(payload),
} }
...@@ -446,7 +446,7 @@ func paraInfo(cmd *cobra.Command, args []string) { ...@@ -446,7 +446,7 @@ func paraInfo(cmd *cobra.Command, args []string) {
Title: title, Title: title,
Height: height, Height: height,
} }
var res pt.RespParacrossDone var res pt.ParacrossHeightStatusRsp
ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.GetTitleHeight", params, &res) ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.GetTitleHeight", params, &res)
ctx.Run() ctx.Run()
} }
......
...@@ -225,13 +225,9 @@ func hasCommited(addrs []string, addr string) (bool, int) { ...@@ -225,13 +225,9 @@ func hasCommited(addrs []string, addr string) (bool, int) {
} }
func getDappForkHeight(fork string) int64 { func getDappForkHeight(fork string) int64 {
paraConfigFork := ""
if fork == pt.ForkCommitTx {
paraConfigFork = "MainForkParacrossCommitTx"
}
var forkHeight int64 var forkHeight int64
if types.IsPara() { if types.IsPara() {
forkHeight = types.Conf("config.consensus.sub.para").GInt(paraConfigFork) forkHeight = types.Conf("config.consensus.sub.para").GInt("MainForkParacrossCommitTx")
if forkHeight <= 0 { if forkHeight <= 0 {
forkHeight = types.MaxHeight forkHeight = types.MaxHeight
} }
...@@ -348,6 +344,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -348,6 +344,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
} }
if a.exec.GetMainHeight() >= getDappForkHeight(pt.ForkCommitTx) { if a.exec.GetMainHeight() >= getDappForkHeight(pt.ForkCommitTx) {
stat.MainHeight = commit.Status.MainBlockHeight stat.MainHeight = commit.Status.MainBlockHeight
stat.MainHash = commit.Status.MainBlockHash
} }
receipt = makeCommitReceipt(a.fromaddr, commit, nil, stat) receipt = makeCommitReceipt(a.fromaddr, commit, nil, stat)
} else { } else {
...@@ -388,8 +385,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -388,8 +385,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
} }
//add commit done receipt //add commit done receipt
receiptDone := makeDoneReceipt(a.fromaddr, commit, stat, int32(most), int32(commitCount), int32(len(nodes))) receiptDone := makeDoneReceipt(a.fromaddr, commit, stat, int32(most), int32(commitCount), int32(len(nodes)))
receipt.KV = append(receipt.KV, receiptDone.KV...) receipt = mergeReceipt(receipt, receiptDone)
receipt.Logs = append(receipt.Logs, receiptDone.Logs...)
//平行连进行奖励分配,考虑可能的失败,需要在保存共识高度等数据之前处理 //平行连进行奖励分配,考虑可能的失败,需要在保存共识高度等数据之前处理
if types.IsPara() { if types.IsPara() {
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db" dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types" pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
...@@ -22,6 +23,31 @@ func (p *Paracross) Query_GetTitle(in *types.ReqString) (types.Message, error) { ...@@ -22,6 +23,31 @@ func (p *Paracross) Query_GetTitle(in *types.ReqString) (types.Message, error) {
return p.paracrossGetHeight(in.GetData()) return p.paracrossGetHeight(in.GetData())
} }
// Query_GetTitleHeight query paracross status with title and height
func (p *Paracross) Query_GetTitleHeight(in *pt.ReqParacrossTitleHeight) (types.Message, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
stat, err := p.paracrossGetStateTitleHeight(in.Title, in.Height)
if err != nil {
clog.Error("paracross.GetTitleHeight", "title", title, "height", in.Height, "err", err.Error())
return nil, err
}
status := stat.(*pt.ParacrossHeightStatus)
res := &pt.ParacrossHeightStatusRsp{
Status: status.Status,
Title: status.Title,
Height: status.Height,
MainHeight: status.MainHeight,
MainHash: common.ToHex(status.MainHash),
}
for i, addr := range status.Details.Addrs {
res.CommitAddrs = append(res.CommitAddrs, addr)
res.CommitBlockHash = append(res.CommitBlockHash, common.ToHex(status.Details.BlockHash[i]))
}
return res, nil
}
// Query_GetTitleByHash query paracross title by block hash // Query_GetTitleByHash query paracross title by block hash
func (p *Paracross) Query_GetTitleByHash(in *pt.ReqParacrossTitleHash) (types.Message, error) { func (p *Paracross) Query_GetTitleByHash(in *pt.ReqParacrossTitleHash) (types.Message, error) {
if in == nil { if in == nil {
...@@ -99,8 +125,8 @@ func (p *Paracross) Query_ListTitles(in *types.ReqNil) (types.Message, error) { ...@@ -99,8 +125,8 @@ func (p *Paracross) Query_ListTitles(in *types.ReqNil) (types.Message, error) {
return p.paracrossListTitles() return p.paracrossListTitles()
} }
// Query_GetTitleHeight query title height // Query_GetDoneTitleHeight query title height
func (p *Paracross) Query_GetTitleHeight(in *pt.ReqParacrossTitleHeight) (types.Message, error) { func (p *Paracross) Query_GetDoneTitleHeight(in *pt.ReqParacrossTitleHeight) (types.Message, error) {
if in == nil { if in == nil {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
......
...@@ -163,6 +163,18 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) ...@@ -163,6 +163,18 @@ func (a *action) nodeJoin(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return nil, errors.Wrapf(pt.ErrParaNodeAddrExisted, "nodeAddr existed:%s", config.Addr) return nil, errors.Wrapf(pt.ErrParaNodeAddrExisted, "nodeAddr existed:%s", config.Addr)
} }
nodeGroupStatus, err := getNodeGroupStatus(a.db, config.Title)
if err != nil {
return nil, errors.Wrapf(pt.ErrParaNodeGroupNotSet, "nodegroup not exist:%s", config.Title)
}
if config.CoinsFrozen < nodeGroupStatus.CoinsFrozen {
clog.Error("nodeJoin coinfrozen not enough", "title", config.Title, "addr", config.Addr,
"config", config.CoinsFrozen, "nodegroupConfig", nodeGroupStatus.CoinsFrozen)
return nil, errors.Wrapf(pt.ErrParaNodeGroupFrozenCoinsNotEnough,
"coinFrozen not enough:%d,expected:%d", config.CoinsFrozen, nodeGroupStatus.CoinsFrozen)
}
receipt := &types.Receipt{Ty: types.ExecOk} receipt := &types.Receipt{Ty: types.ExecOk}
if !types.IsPara() { if !types.IsPara() {
r, err := a.nodeGroupCoinsFrozen(a.fromaddr, config.CoinsFrozen, 1) r, err := a.nodeGroupCoinsFrozen(a.fromaddr, config.CoinsFrozen, 1)
...@@ -223,9 +235,16 @@ func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) ...@@ -223,9 +235,16 @@ func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return nil, err return nil, err
} }
//代替别人退出或者自己退出都允许,但代替别人退出时候创建账户也必须匹配
if a.fromaddr != stat.FromAddr && a.fromaddr != config.Addr {
clog.Error("nodeaccount.nodeQuit wrong addr", "createAddr", stat.FromAddr, "confAddr", config.Addr, "fromAddr", a.fromaddr)
return nil, types.ErrNotAllow
}
if stat.Status == pt.ParacrossNodeQuiting || stat.Status == pt.ParacrossNodeQuited { if stat.Status == pt.ParacrossNodeQuiting || stat.Status == pt.ParacrossNodeQuited {
clog.Error("nodeaccount.nodeQuit wrong status", "status", stat) clog.Error("nodeaccount.nodeQuit wrong status", "status", stat)
return nil, errors.Wrapf(pt.ErrParaUnSupportNodeOper, "nodeAddr %s was quit status:%d", a.fromaddr, stat.Status) return nil, errors.Wrapf(pt.ErrParaUnSupportNodeOper, "nodeAddr %s was quit status:%d", config.Addr, stat.Status)
} }
if stat.Status == pt.ParacrossNodeAdded { if stat.Status == pt.ParacrossNodeAdded {
...@@ -233,12 +252,12 @@ func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) ...@@ -233,12 +252,12 @@ func (a *action) nodeQuit(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "getNodes for title:%s", config.Title) return nil, errors.Wrapf(err, "getNodes for title:%s", config.Title)
} }
if !validNode(a.fromaddr, nodes) { if !validNode(config.Addr, nodes) {
return nil, errors.Wrapf(pt.ErrParaNodeAddrNotExisted, "nodeAddr not existed:%s", a.fromaddr) return nil, errors.Wrapf(pt.ErrParaNodeAddrNotExisted, "nodeAddr not existed:%s", config.Addr)
} }
//不允许最后一个账户退出 //不允许最后一个账户退出
if len(nodes) == 1 { if len(nodes) == 1 {
return nil, errors.Wrapf(pt.ErrParaNodeGroupLastAddr, "nodeAddr last one:%s", a.fromaddr) return nil, errors.Wrapf(pt.ErrParaNodeGroupLastAddr, "nodeAddr last one:%s", config.Addr)
} }
} }
...@@ -354,21 +373,6 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) ...@@ -354,21 +373,6 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return nil, errors.Wrapf(pt.ErrNodeNotForTheTitle, "not validNode:%s", a.fromaddr) return nil, errors.Wrapf(pt.ErrNodeNotForTheTitle, "not validNode:%s", a.fromaddr)
} }
if a.fromaddr == config.Addr {
return nil, errors.Wrapf(pt.ErrParaNodeVoteSelf, "not allow to vote self:%s", a.fromaddr)
}
// 如果投票账户是group账户,需计算此账户之外的投票
if validNode(config.Addr, nodes) {
temp := make(map[string]struct{})
for k := range nodes {
if k != config.Addr {
temp[k] = struct{}{}
}
}
nodes = temp
}
stat, err := getNodeAddr(a.db, config.Title, config.Addr) stat, err := getNodeAddr(a.db, config.Title, config.Addr)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -422,6 +426,14 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error) ...@@ -422,6 +426,14 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return nil, err return nil, err
} }
stat.Status = pt.ParacrossNodeQuited stat.Status = pt.ParacrossNodeQuited
if !types.IsPara() {
r, err := a.nodeGroupCoinsActive(stat.FromAddr, stat.CoinsFrozen, 1)
if err != nil {
return nil, err
}
receiptGroup.KV = append(receiptGroup.KV, r.KV...)
receiptGroup.Logs = append(receiptGroup.Logs, r.Logs...)
}
} }
} else { } else {
if stat.Status == pt.ParacrossNodeAdding { if stat.Status == pt.ParacrossNodeAdding {
...@@ -512,6 +524,10 @@ func (a *action) checkConfig(title string) error { ...@@ -512,6 +524,10 @@ func (a *action) checkConfig(title string) error {
} }
func getAddrGroup(addr string) []string { func getAddrGroup(addr string) []string {
addr = strings.Trim(addr, " ")
if addr == "" {
return nil
}
if strings.Contains(addr, ",") { if strings.Contains(addr, ",") {
repeats := make(map[string]bool) repeats := make(map[string]bool)
var addrs []string var addrs []string
...@@ -521,7 +537,7 @@ func getAddrGroup(addr string) []string { ...@@ -521,7 +537,7 @@ func getAddrGroup(addr string) []string {
ss := strings.Split(s, ",") ss := strings.Split(s, ",")
for _, v := range ss { for _, v := range ss {
v = strings.Trim(v, " ") v = strings.Trim(v, " ")
if !repeats[v] { if v != "" && !repeats[v] {
addrs = append(addrs, v) addrs = append(addrs, v)
repeats[v] = true repeats[v] = true
} }
...@@ -562,7 +578,7 @@ func (a *action) nodeGroupCoinsFrozen(createAddr string, configCoinsFrozen int64 ...@@ -562,7 +578,7 @@ func (a *action) nodeGroupCoinsFrozen(createAddr string, configCoinsFrozen int64
r, err := a.coinsAccount.ExecFrozen(createAddr, realExecAddr, nodeCounts*configCoinsFrozen) r, err := a.coinsAccount.ExecFrozen(createAddr, realExecAddr, nodeCounts*configCoinsFrozen)
if err != nil { if err != nil {
clog.Error("node group apply", "addr", createAddr, "realExec", realExec, "realAddr", realExecAddr, "amount", configCoinsFrozen) clog.Error("node group apply", "addr", createAddr, "realExec", realExec, "realAddr", realExecAddr, "amount", nodeCounts*configCoinsFrozen)
return nil, err return nil, err
} }
...@@ -607,6 +623,11 @@ func (a *action) nodeGroupApply(config *pt.ParaNodeGroupConfig) (*types.Receipt, ...@@ -607,6 +623,11 @@ func (a *action) nodeGroupApply(config *pt.ParaNodeGroupConfig) (*types.Receipt,
} }
addrs := getAddrGroup(config.Addrs) addrs := getAddrGroup(config.Addrs)
if len(addrs) == 0 {
clog.Error("node group apply addrs null", "addrs", config.Addrs)
return nil, types.ErrInvalidParam
}
receipt := &types.Receipt{Ty: types.ExecOk} receipt := &types.Receipt{Ty: types.ExecOk}
//main chain //main chain
if !types.IsPara() { if !types.IsPara() {
...@@ -639,7 +660,7 @@ func (a *action) nodeGroupQuit(config *pt.ParaNodeGroupConfig) (*types.Receipt, ...@@ -639,7 +660,7 @@ func (a *action) nodeGroupQuit(config *pt.ParaNodeGroupConfig) (*types.Receipt,
if err != nil { if err != nil {
return nil, err return nil, err
} }
if status != nil && status.Status != pt.ParacrossNodeGroupApply { if status.Status != pt.ParacrossNodeGroupApply {
clog.Error("node group apply exist", "status", status.Status) clog.Error("node group apply exist", "status", status.Status)
return nil, pt.ErrParaNodeGroupStatusWrong return nil, pt.ErrParaNodeGroupStatusWrong
} }
...@@ -727,6 +748,10 @@ func (a *action) nodeGroupApprove(config *pt.ParaNodeGroupConfig) (*types.Receip ...@@ -727,6 +748,10 @@ func (a *action) nodeGroupApprove(config *pt.ParaNodeGroupConfig) (*types.Receip
return nil, pt.ErrParaNodeGroupStatusWrong return nil, pt.ErrParaNodeGroupStatusWrong
} }
if status.CoinsFrozen < config.CoinsFrozen {
clog.Error("node group approve not apply status", "status", status.Status)
return nil, pt.ErrParaNodeGroupFrozenCoinsNotEnough
}
applyAddrs, err := checkNodeGroupAddrsMatch(status.ApplyAddr, config.Addrs) applyAddrs, err := checkNodeGroupAddrsMatch(status.ApplyAddr, config.Addrs)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -796,7 +821,8 @@ func (a *action) NodeGroupConfig(config *pt.ParaNodeGroupConfig) (*types.Receipt ...@@ -796,7 +821,8 @@ func (a *action) NodeGroupConfig(config *pt.ParaNodeGroupConfig) (*types.Receipt
return nil, pt.ErrInvalidTitle return nil, pt.ErrInvalidTitle
} }
if len(config.Addrs) == 0 { s := strings.Trim(config.Addrs, " ")
if len(s) == 0 {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
...@@ -832,9 +858,6 @@ func (a *action) NodeConfig(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro ...@@ -832,9 +858,6 @@ func (a *action) NodeConfig(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
return a.nodeJoin(config) return a.nodeJoin(config)
} else if config.Op == pt.ParaNodeQuit { } else if config.Op == pt.ParaNodeQuit {
if config.Addr != a.fromaddr {
return nil, types.ErrFromAddr
}
return a.nodeQuit(config) return a.nodeQuit(config)
} else if config.Op == pt.ParaNodeVote { } else if config.Op == pt.ParaNodeVote {
......
...@@ -306,3 +306,27 @@ func TestNodeManageSuite(t *testing.T) { ...@@ -306,3 +306,27 @@ func TestNodeManageSuite(t *testing.T) {
func (suite *NodeManageTestSuite) TearDownSuite() { func (suite *NodeManageTestSuite) TearDownSuite() {
} }
func TestGetAddrGroup(t *testing.T) {
addrs := " 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4, 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR, 1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k, ,,, 1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs , "
retAddrs := getAddrGroup(addrs)
expectAddrs := []string{"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4", "1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR", "1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k", "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"}
assert.Equal(t, expectAddrs, retAddrs)
addrs = " 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4 , , "
retAddrs = getAddrGroup(addrs)
expectAddrs = []string{"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}
assert.Equal(t, expectAddrs, retAddrs)
addrs = " , "
ret := getAddrGroup(addrs)
assert.Equal(t, []string(nil), ret)
assert.Equal(t, 0, len(ret))
addrs = " "
ret = getAddrGroup(addrs)
assert.Equal(t, []string(nil), ret)
assert.Equal(t, 0, len(ret))
}
...@@ -20,6 +20,18 @@ message ParacrossHeightStatus { ...@@ -20,6 +20,18 @@ message ParacrossHeightStatus {
int64 height = 3; int64 height = 3;
ParacrossStatusDetails details = 4; ParacrossStatusDetails details = 4;
int64 mainHeight = 5; int64 mainHeight = 5;
bytes mainHash = 6;
}
message ParacrossHeightStatusRsp {
int32 status = 1;
string title = 2;
int64 height = 3;
int64 mainHeight = 4;
string mainHash = 5;
repeated string commitAddrs = 6;
repeated string commitBlockHash = 7;
} }
message ParacrossStatus { message ParacrossStatus {
...@@ -263,7 +275,8 @@ message ParacrossAsset { ...@@ -263,7 +275,8 @@ message ParacrossAsset {
service paracross { service paracross {
rpc GetTitle(ReqString) returns (ParacrossConsensusStatus) {} rpc GetTitle(ReqString) returns (ParacrossConsensusStatus) {}
rpc ListTitles(ReqNil) returns (RespParacrossTitles) {} rpc ListTitles(ReqNil) returns (RespParacrossTitles) {}
rpc GetTitleHeight(ReqParacrossTitleHeight) returns (RespParacrossDone) {} rpc GetDoneTitleHeight(ReqParacrossTitleHeight) returns (RespParacrossDone) {}
rpc GetTitleHeight(ReqParacrossTitleHeight) returns (ParacrossHeightStatusRsp) {}
rpc GetAssetTxResult(ReqHash) returns (ParacrossAsset) {} rpc GetAssetTxResult(ReqHash) returns (ParacrossAsset) {}
rpc IsSync(ReqNil) returns (IsCaughtUp) {} rpc IsSync(ReqNil) returns (IsCaughtUp) {}
} }
\ No newline at end of file
...@@ -72,12 +72,12 @@ func (c *Jrpc) ListTitles(req *types.ReqNil, result *interface{}) error { ...@@ -72,12 +72,12 @@ func (c *Jrpc) ListTitles(req *types.ReqNil, result *interface{}) error {
return err return err
} }
func (c *channelClient) GetTitleHeight(ctx context.Context, req *pt.ReqParacrossTitleHeight) (*pt.RespParacrossDone, error) { func (c *channelClient) GetTitleHeight(ctx context.Context, req *pt.ReqParacrossTitleHeight) (*pt.ParacrossHeightStatusRsp, error) {
data, err := c.Query(pt.GetExecName(), "GetTitleHeight", req) data, err := c.Query(pt.GetExecName(), "GetTitleHeight", req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if resp, ok := data.(*pt.RespParacrossDone); ok { if resp, ok := data.(*pt.ParacrossHeightStatusRsp); ok {
return resp, nil return resp, nil
} }
return nil, types.ErrDecode return nil, types.ErrDecode
...@@ -93,6 +93,17 @@ func (c *Jrpc) GetTitleHeight(req *pt.ReqParacrossTitleHeight, result *interface ...@@ -93,6 +93,17 @@ func (c *Jrpc) GetTitleHeight(req *pt.ReqParacrossTitleHeight, result *interface
return err return err
} }
func (c *channelClient) GetDoneTitleHeight(ctx context.Context, req *pt.ReqParacrossTitleHeight) (*pt.RespParacrossDone, error) {
data, err := c.Query(pt.GetExecName(), "GetDoneTitleHeight", req)
if err != nil {
return nil, err
}
if resp, ok := data.(*pt.RespParacrossDone); ok {
return resp, nil
}
return nil, types.ErrDecode
}
func (c *channelClient) GetAssetTxResult(ctx context.Context, req *types.ReqHash) (*pt.ParacrossAsset, error) { func (c *channelClient) GetAssetTxResult(ctx context.Context, req *types.ReqHash) (*pt.ParacrossAsset, error) {
data, err := c.Query(pt.GetExecName(), "GetAssetTxResult", req) data, err := c.Query(pt.GetExecName(), "GetAssetTxResult", req)
if err != nil { if err != nil {
......
...@@ -77,17 +77,27 @@ func TestChannelClient_GetTitleHeight(t *testing.T) { ...@@ -77,17 +77,27 @@ func TestChannelClient_GetTitleHeight(t *testing.T) {
client := newGrpc(api) client := newGrpc(api)
client.Init("paracross", nil, nil, nil) client.Init("paracross", nil, nil, nil)
req := &pt.ReqParacrossTitleHeight{} req := &pt.ReqParacrossTitleHeight{}
api.On("Query", pt.GetExecName(), "GetTitleHeight", req).Return(&pt.RespParacrossDone{}, nil) api.On("Query", pt.GetExecName(), "GetTitleHeight", req).Return(&pt.ParacrossHeightStatusRsp{}, nil)
_, err := client.GetTitleHeight(context.Background(), req) _, err := client.GetTitleHeight(context.Background(), req)
assert.Nil(t, err) assert.Nil(t, err)
} }
func TestChannelClient_GetTitleDoneHeight(t *testing.T) {
api := new(mocks.QueueProtocolAPI)
client := newGrpc(api)
client.Init("paracross", nil, nil, nil)
req := &pt.ReqParacrossTitleHeight{}
api.On("Query", pt.GetExecName(), "GetDoneTitleHeight", req).Return(&pt.RespParacrossDone{}, nil)
_, err := client.GetDoneTitleHeight(context.Background(), req)
assert.Nil(t, err)
}
func TestJrpc_GetTitleHeight(t *testing.T) { func TestJrpc_GetTitleHeight(t *testing.T) {
api := new(mocks.QueueProtocolAPI) api := new(mocks.QueueProtocolAPI)
j := newJrpc(api) j := newJrpc(api)
req := &pt.ReqParacrossTitleHeight{} req := &pt.ReqParacrossTitleHeight{}
var result interface{} var result interface{}
api.On("Query", pt.GetExecName(), "GetTitleHeight", req).Return(&pt.RespParacrossDone{}, nil) api.On("Query", pt.GetExecName(), "GetTitleHeight", req).Return(&pt.ParacrossHeightStatusRsp{}, nil)
err := j.GetTitleHeight(req, &result) err := j.GetTitleHeight(req, &result)
assert.Nil(t, err) assert.Nil(t, err)
} }
......
...@@ -7,6 +7,7 @@ package types ...@@ -7,6 +7,7 @@ package types
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/log/log15" "github.com/33cn/chain33/common/log/log15"
...@@ -177,6 +178,7 @@ func createRawCommitTx(status *ParacrossNodeStatus, name string, fee int64) (*ty ...@@ -177,6 +178,7 @@ func createRawCommitTx(status *ParacrossNodeStatus, name string, fee int64) (*ty
// CreateRawNodeConfigTx create raw tx for node config // CreateRawNodeConfigTx create raw tx for node config
func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, error) { func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, error) {
config.Title = types.GetTitle() config.Title = types.GetTitle()
config.Addr = strings.Trim(config.Addr, " ")
action := &ParacrossAction{ action := &ParacrossAction{
Ty: ParacrossActionNodeConfig, Ty: ParacrossActionNodeConfig,
......
This diff is collapsed.
...@@ -64,9 +64,9 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo { ...@@ -64,9 +64,9 @@ func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
TyLogParaNodeConfig: {Ty: reflect.TypeOf(ReceiptParaNodeConfig{}), Name: "LogParaNodeConfig"}, TyLogParaNodeConfig: {Ty: reflect.TypeOf(ReceiptParaNodeConfig{}), Name: "LogParaNodeConfig"},
TyLogParaNodeGroupUpdate: {Ty: reflect.TypeOf(types.ReceiptConfig{}), Name: "LogParaNodeGroupUpdate"}, TyLogParaNodeGroupUpdate: {Ty: reflect.TypeOf(types.ReceiptConfig{}), Name: "LogParaNodeGroupUpdate"},
TyLogParaNodeVoteDone: {Ty: reflect.TypeOf(ReceiptParaNodeVoteDone{}), Name: "LogParaNodeVoteDone"}, TyLogParaNodeVoteDone: {Ty: reflect.TypeOf(ReceiptParaNodeVoteDone{}), Name: "LogParaNodeVoteDone"},
TyLogParaNodeGroupApply: {Ty: reflect.TypeOf(ReceiptParaNodeConfig{}), Name: "LogParaNodeGroupApply"}, TyLogParaNodeGroupApply: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupApply"},
TyLogParaNodeGroupApprove: {Ty: reflect.TypeOf(ReceiptParaNodeConfig{}), Name: "LogParaNodeGroupApprove"}, TyLogParaNodeGroupApprove: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupApprove"},
TyLogParaNodeGroupQuit: {Ty: reflect.TypeOf(ReceiptParaNodeConfig{}), Name: "LogParaNodeGroupQuit"}, TyLogParaNodeGroupQuit: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupQuit"},
} }
} }
...@@ -126,7 +126,7 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types. ...@@ -126,7 +126,7 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
return CreateRawNodeConfigTx(&param) return CreateRawNodeConfigTx(&param)
} else if action == "NodeGroupApply" { } else if action == "NodeGroupConfig" {
if !types.IsPara() { if !types.IsPara() {
return nil, types.ErrNotSupport return nil, types.ErrNotSupport
} }
......
all:
chmod +x ./build.sh
./build.sh $(OUT) $(FLAG)
#!/bin/sh
strpwd=$(pwd)
strcmd=${strpwd##*dapp/}
strapp=${strcmd%/cmd*}
OUT_DIR="${1}/$strapp"
#FLAG=$2
mkdir -p "${OUT_DIR}"
cp ./build/* "${OUT_DIR}"
OUT_TESTDIR="${1}/dapptest/$strapp"
mkdir -p "${OUT_TESTDIR}"
cp ./build/test-rpc.sh "${OUT_TESTDIR}"
#!/usr/bin/env bash
# shellcheck disable=SC2128
set -e
set -o pipefail
MAIN_HTTP=""
GAME_ID=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh
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")
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" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
echo "========== # pokerbull play tx end =========="
chain33_BlockWait 1 ${MAIN_HTTP}
}
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")
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" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
echo "========== # pokerbull quit tx end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
}
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")
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" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" ${MAIN_HTTP}
echo "========== # pokerbull continue tx end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
}
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")
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" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
GAME_ID=$RAW_TX_HASH
echo "========== # pokerbull start tx end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
}
pokerbull_QueryResult() {
echo "========== # pokerbull query result begin =========="
local req='"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]'
data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
ok=$(jq '(.game.gameId == "$GAME_ID")' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
data=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByAddr","payload":{"addr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}}]}' ${MAIN_HTTP} | jq -r ".result")
[ "$data" != null ]
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() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara"
if [ "$ispara" == true ]; then
pokerbull_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.pokerbull"}]}' ${MAIN_HTTP} | jq -r ".result")
else
pokerbull_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"pokerbull"}]}' ${MAIN_HTTP} | jq -r ".result")
fi
local from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000 ${MAIN_HTTP}
from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
chain33_SendToAddress "$from" "$pokerbull_addr" 10000000000 ${MAIN_HTTP}
chain33_BlockWait 1 "${MAIN_HTTP}"
}
function run_test() {
pokerbull_StartRawTx
pokerbull_ContinueRawTx
pokerbull_QuitRawTx
pokerbull_PlayRawTx
pokerbull_QueryResult
}
function main() {
MAIN_HTTP="$1"
echo "=========== # pokerbull rpc test ============="
echo "ip=$MAIN_HTTP"
init
run_test
if [ -n "$CASE_ERR" ]; then
echo -e "${RED}=============Pokerbull Rpc Test Fail=============${NOC}"
exit 1
else
echo -e "${GRE}=============Pokerbull Rpc Test Pass==============${NOC}"
fi
}
main "$1"
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package commands package cmd
import ( import (
"fmt" "fmt"
......
...@@ -6,7 +6,7 @@ package pokerbull ...@@ -6,7 +6,7 @@ package pokerbull
import ( import (
"github.com/33cn/chain33/pluginmgr" "github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/pokerbull/commands" "github.com/33cn/plugin/plugin/dapp/pokerbull/cmd"
"github.com/33cn/plugin/plugin/dapp/pokerbull/executor" "github.com/33cn/plugin/plugin/dapp/pokerbull/executor"
"github.com/33cn/plugin/plugin/dapp/pokerbull/types" "github.com/33cn/plugin/plugin/dapp/pokerbull/types"
) )
...@@ -16,6 +16,6 @@ func init() { ...@@ -16,6 +16,6 @@ func init() {
Name: types.PokerBullX, Name: types.PokerBullX,
ExecName: executor.GetName(), ExecName: executor.GetName(),
Exec: executor.Init, Exec: executor.Init,
Cmd: commands.PokerBullCmd, Cmd: cmd.PokerBullCmd,
}) })
} }
all:
chmod +x ./build.sh
./build.sh $(OUT) $(FLAG)
\ No newline at end of file
#!/bin/sh
strpwd=$(pwd)
strcmd=${strpwd##*dapp/}
strapp=${strcmd%/cmd*}
OUT_DIR="${1}/$strapp"
#FLAG=$2
mkdir -p "${OUT_DIR}"
cp ./build/* "${OUT_DIR}"
OUT_TESTDIR="${1}/dapptest/$strapp"
mkdir -p "${OUT_TESTDIR}"
cp ./build/test-rpc.sh "${OUT_TESTDIR}"
#!/usr/bin/env bash
# shellcheck disable=SC2128
set -e
set -o pipefail
MAIN_HTTP=""
# shellcheck source=/dev/null
source ../dapp-test-common.sh
retrieve_Backup() {
echo "========== # retrieve backup begin =========="
local req='"method":"retrieve.CreateRawRetrieveBackupTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo","delayPeriod": 61}]'
tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
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" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
echo "========== # retrieve backup end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
}
retrieve_Prepare() {
echo "========== # retrieve prepare begin =========="
local req='"method":"retrieve.CreateRawRetrievePrepareTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}]'
tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
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" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" ${MAIN_HTTP}
echo "========== # retrieve prepare end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
}
retrieve_Perform() {
echo "========== # retrieve perform begin =========="
local req='"method":"retrieve.CreateRawRetrievePerformTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}]'
tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
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" "2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989" ${MAIN_HTTP}
echo "========== # retrieve perform end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
}
retrieve_Cancel() {
echo "========== # retrieve cancel begin =========="
local req='"method":"retrieve.CreateRawRetrieveCancelTx","params":[{"backupAddr":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX","defaultAddr":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}]'
tx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
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" "56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138" ${MAIN_HTTP}
echo "========== # retrieve cancel end =========="
chain33_BlockWait 1 "${MAIN_HTTP}"
}
retrieve_QueryResult() {
echo "========== # retrieve query result begin =========="
local status=$1
local req='"method":"Chain33.Query","params":[{"execer":"retrieve","funcName":"GetRetrieveInfo","payload":{"backupAddress":"1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX", "defaultAddress":"1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"}}]'
data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
ok=$(jq '(.status == '"$status"')' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
echo "========== # retrieve query result end =========="
}
init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara"
if [ "$ispara" == true ]; then
retrieve_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.retrieve"}]}' ${MAIN_HTTP} | jq -r ".result")
else
retrieve_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"retrieve"}]}' ${MAIN_HTTP} | jq -r ".result")
fi
local from="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
chain33_SendToAddress "$from" "$retrieve_addr" 1000000000 ${MAIN_HTTP}
from="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
chain33_SendToAddress "$from" "$retrieve_addr" 1000000000 ${MAIN_HTTP}
chain33_BlockWait 1 "${MAIN_HTTP}"
}
function run_test() {
retrieve_Backup
retrieve_QueryResult 1
retrieve_Prepare
retrieve_QueryResult 2
retrieve_Cancel
retrieve_QueryResult 4
retrieve_Backup
retrieve_QueryResult 1
retrieve_Prepare
retrieve_QueryResult 2
sleep 61
retrieve_Perform
retrieve_QueryResult 3
}
function main() {
MAIN_HTTP="$1"
echo "=========== # retrieve rpc test ============="
echo "ip=$MAIN_HTTP"
init
run_test
if [ -n "$CASE_ERR" ]; then
echo -e "${RED}=============retrieve Rpc Test Fail=============${NOC}"
exit 1
else
echo -e "${GRE}=============retrieve Rpc Test Pass==============${NOC}"
fi
}
main "$1"
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package commands package cmd
import ( import (
"fmt" "fmt"
......
...@@ -6,7 +6,7 @@ package retrieve ...@@ -6,7 +6,7 @@ package retrieve
import ( import (
"github.com/33cn/chain33/pluginmgr" "github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/retrieve/commands" "github.com/33cn/plugin/plugin/dapp/retrieve/cmd"
"github.com/33cn/plugin/plugin/dapp/retrieve/executor" "github.com/33cn/plugin/plugin/dapp/retrieve/executor"
"github.com/33cn/plugin/plugin/dapp/retrieve/rpc" "github.com/33cn/plugin/plugin/dapp/retrieve/rpc"
"github.com/33cn/plugin/plugin/dapp/retrieve/types" "github.com/33cn/plugin/plugin/dapp/retrieve/types"
...@@ -17,7 +17,7 @@ func init() { ...@@ -17,7 +17,7 @@ func init() {
Name: types.RetrieveX, Name: types.RetrieveX,
ExecName: executor.GetName(), ExecName: executor.GetName(),
Exec: executor.Init, Exec: executor.Init,
Cmd: commands.RetrieveCmd, Cmd: cmd.RetrieveCmd,
RPC: rpc.Init, RPC: rpc.Init,
}) })
} }
...@@ -16,7 +16,7 @@ func (c *channelClient) Backup(ctx context.Context, v *rt.BackupRetrieve) (*type ...@@ -16,7 +16,7 @@ func (c *channelClient) Backup(ctx context.Context, v *rt.BackupRetrieve) (*type
Ty: rt.RetrieveActionBackup, Ty: rt.RetrieveActionBackup,
Value: &rt.RetrieveAction_Backup{Backup: v}, Value: &rt.RetrieveAction_Backup{Backup: v},
} }
tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(backup)) tx, err := types.CreateFormatTx(types.ExecName(rt.RetrieveX), types.Encode(backup))
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -29,7 +29,7 @@ func (c *channelClient) Prepare(ctx context.Context, v *rt.PrepareRetrieve) (*ty ...@@ -29,7 +29,7 @@ func (c *channelClient) Prepare(ctx context.Context, v *rt.PrepareRetrieve) (*ty
Ty: rt.RetrieveActionPrepare, Ty: rt.RetrieveActionPrepare,
Value: &rt.RetrieveAction_Prepare{Prepare: v}, Value: &rt.RetrieveAction_Prepare{Prepare: v},
} }
tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(prepare)) tx, err := types.CreateFormatTx(types.ExecName(rt.RetrieveX), types.Encode(prepare))
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -43,7 +43,7 @@ func (c *channelClient) Perform(ctx context.Context, v *rt.PerformRetrieve) (*ty ...@@ -43,7 +43,7 @@ func (c *channelClient) Perform(ctx context.Context, v *rt.PerformRetrieve) (*ty
Ty: rt.RetrieveActionPerform, Ty: rt.RetrieveActionPerform,
Value: &rt.RetrieveAction_Perform{Perform: v}, Value: &rt.RetrieveAction_Perform{Perform: v},
} }
tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(perform)) tx, err := types.CreateFormatTx(types.ExecName(rt.RetrieveX), types.Encode(perform))
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -56,7 +56,7 @@ func (c *channelClient) Cancel(ctx context.Context, v *rt.CancelRetrieve) (*type ...@@ -56,7 +56,7 @@ func (c *channelClient) Cancel(ctx context.Context, v *rt.CancelRetrieve) (*type
Ty: rt.RetrieveActionCancel, Ty: rt.RetrieveActionCancel,
Value: &rt.RetrieveAction_Cancel{Cancel: v}, Value: &rt.RetrieveAction_Cancel{Cancel: v},
} }
tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(cancel)) tx, err := types.CreateFormatTx(types.ExecName(rt.RetrieveX), types.Encode(cancel))
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -15,15 +15,15 @@ cmd目录下有两个文件Makefile和build.sh 负责在make时候把build里面 ...@@ -15,15 +15,15 @@ cmd目录下有两个文件Makefile和build.sh 负责在make时候把build里面
也可以通过dapp参数关键字all来run所有的dapp, all模式会自动删除pass的dapp的资源 也可以通过dapp参数关键字all来run所有的dapp, all模式会自动删除pass的dapp的资源
1. make docker-compose [PROJ=xx] [DAPP=xx] 1. make docker-compose [proj=xx] [dapp=xx]
1. 如果PROJ 和DAPP都不设置如 make docker-compose, 只会run 系统的test case,不会run任何dapp 1. 如果proj 和dapp都不设置如 make docker-compose, 只会run 系统的test case,不会run任何dapp
1. 如果PROJ不设置,系统会缺省采用build关键字作为docker-compose的service工程名,如果设置以设置为准, 1. 如果proj不设置,系统会缺省采用build关键字作为docker-compose的service工程名,如果设置以设置为准,
不同PROJ可以实现docker compose 并行 不同proj可以实现docker compose 并行
1. 如果DAPP不设置,则不run任何dapp,如果设置,则只run 指定的dapp,run结束后需要手动 make docker-compose-down DAPP=xx释放 1. 如果dapp不设置,则不run任何dapp,如果设置,则只run 指定的dapp,run结束后需要手动 make docker-compose-down dapp=xx释放
1. 如果DAPP=all 或者ALL, 则run 所有提供testcase的dapp 1. 如果dapp=all 或者ALL, 则run 所有提供testcase的dapp
1. make docker-compose down [PROJ=xx] [DAPP=xx] 1. make docker-compose down [proj=xx] [dapp=xx]
负责clean make docker-compose 或make fork-test 创建了的docker资源, PROJ 和DAPP规则同上 负责clean make docker-compose 或make fork-test 创建了的docker资源, proj 和dapp规则同上
1. make fork-test [PROJ=xx] [DAPP=xx] 分叉测试 1. make fork-test [proj=xx] [dapp=xx] 分叉测试
1. 规则同make docker-compose 1. 规则同make docker-compose
......
all:
chmod +x ./build.sh
./build.sh $(OUT) $(FLAG)
\ No newline at end of file
#!/usr/bin/env bash
strpwd=$(pwd)
strcmd=${strpwd##*dapp/}
strapp=${strcmd%/cmd*}
OUT_DIR="${1}/$strapp"
#FLAG=$2
mkdir -p "${OUT_DIR}"
cp ./build/* "${OUT_DIR}"
OUT_TESTDIR="${1}/dapptest/$strapp"
mkdir -p "${OUT_TESTDIR}"
cp ./build/test-rpc.sh "${OUT_TESTDIR}"
This diff is collapsed.
...@@ -47,19 +47,23 @@ func (mem *Mempool) SetQueueClient(client queue.Client) { ...@@ -47,19 +47,23 @@ func (mem *Mempool) SetQueueClient(client queue.Client) {
go func() { go func() {
defer mem.wg.Done() defer mem.wg.Done()
for msg := range client.Recv() { for msg := range client.Recv() {
var err error
var reply interface{}
switch msg.Ty { switch msg.Ty {
case types.EventTx: case types.EventTx:
mlog.Info("Receive msg from para mempool") mlog.Info("Receive msg from para mempool")
tx := msg.GetData().(*types.Transaction) tx := msg.GetData().(*types.Transaction)
reply, err := mem.mainGrpcCli.SendTransaction(context.Background(), tx) reply, err = mem.mainGrpcCli.SendTransaction(context.Background(), tx)
if err != nil { case types.EventGetProperFee:
msg.Reply(client.NewMessage(mem.key, types.EventReply, err)) reply, err = mem.mainGrpcCli.GetProperFee(context.Background(), &types.ReqNil{})
} else {
msg.Reply(client.NewMessage(mem.key, types.EventReply, reply))
}
default: default:
msg.Reply(client.NewMessage(mem.key, types.EventReply, types.ErrActionNotSupport)) msg.Reply(client.NewMessage(mem.key, types.EventReply, types.ErrActionNotSupport))
} }
if err != nil {
msg.Reply(client.NewMessage(mem.key, types.EventReply, err))
} else {
msg.Reply(client.NewMessage(mem.key, types.EventReply, reply))
}
} }
}() }()
} }
......
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