Commit e4d6c37b authored by pengjun's avatar pengjun

fix rpc error

parent a7376175
...@@ -96,6 +96,9 @@ function base_init() { ...@@ -96,6 +96,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 +143,7 @@ function start() { ...@@ -140,7 +143,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
......
...@@ -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,11 +128,10 @@ chain33_SendToAddress() { ...@@ -142,11 +128,10 @@ chain33_SendToAddress() {
chain33_SendTransaction() { chain33_SendTransaction() {
rawTx=$1 rawTx=$1
addr=$2 priv=$2
#签名交易 #签名交易
set -x set -x
resp=$(curl -ksd '{"method":"Chain33.SignRawTx","params":[{"addr":"'"$addr"'","txHex":"'"$rawTx"'","expire":"120s","fee":10000000,"index":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP}) 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 set +x
[[ $ok == null ]] [[ $ok == null ]]
...@@ -169,7 +154,7 @@ chain33_SendTransaction() { ...@@ -169,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})
...@@ -180,14 +165,14 @@ lottery_LotteryCreate() { ...@@ -180,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
...@@ -201,12 +186,12 @@ lottery_LotteryBuy() { ...@@ -201,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})
...@@ -217,12 +202,12 @@ lottery_LotteryDraw() { ...@@ -217,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})
...@@ -233,7 +218,7 @@ lottery_LotteryClose() { ...@@ -233,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() {
...@@ -380,27 +365,20 @@ lottery_GetLotteryRoundGainInfo() { ...@@ -380,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="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
#主链中相应账户需要转帐 #主链中相应账户需要转帐
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}"
...@@ -408,14 +386,14 @@ function run_testcases() { ...@@ -408,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
...@@ -423,8 +401,8 @@ function run_testcases() { ...@@ -423,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
...@@ -433,7 +411,7 @@ function run_testcases() { ...@@ -433,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
#游戏查询 #游戏查询
...@@ -445,7 +423,7 @@ function run_testcases() { ...@@ -445,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
} }
......
...@@ -202,8 +202,8 @@ Chain33_SendToAddress() { ...@@ -202,8 +202,8 @@ Chain33_SendToAddress() {
ok=$(jq '(.error|not) and (.result.hash|length==66)' <<<"$resp") ok=$(jq '(.error|not) and (.result.hash|length==66)' <<<"$resp")
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
hash=$(jq '(.result.hash)' <<<"$resp") hash=$(jq -r ".result.hash" <<<"$resp")
echo "hash=$hash" query_tx "$hash"
echo "send '$3' from '$1' to '$2' end" echo "send '$3' from '$1' to '$2' end"
} }
......
...@@ -207,8 +207,8 @@ Chain33_SendToAddress() { ...@@ -207,8 +207,8 @@ Chain33_SendToAddress() {
ok=$(jq '(.error|not) and (.result.hash|length==66)' <<<"$resp") ok=$(jq '(.error|not) and (.result.hash|length==66)' <<<"$resp")
[ "$ok" == true ] [ "$ok" == true ]
echo_rst "$FUNCNAME" "$?" echo_rst "$FUNCNAME" "$?"
hash=$(jq '(.result.hash)' <<<"$resp") hash=$(jq -r ".result.hash" <<<"$resp")
echo "hash=$hash" query_tx "$hash"
} }
init() { init() {
......
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