Commit 72cab32f authored by liuyuhang's avatar liuyuhang

push

parent 1df87d0a
#!/usr/bin/env bash
RAW_TX_HASH=""
LAST_BLOCK_HASH=""
CASE_ERR=""
#color
......@@ -156,3 +157,10 @@ chain33_GetAccounts() {
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetAccounts","params":[{}]}' -H 'content-type:text/plain;' "${MAIN_HTTP}")
echo "$resp"
}
chain33_LastBlockhash() {
local MAIN_HTTP=$1
result=$(curl -ksd '{"method":"Chain33.GetLastHeader","params":[{}]}' -H 'content-type:text/plain;' "${MAIN_HTTP}" | jq -r ".result.hash")
LAST_BLOCK_HASH=$result
echo -e "######\\n last blockhash is $LAST_BLOCK_HASH \\n######"
}
......@@ -4,22 +4,9 @@ set -e
set -o pipefail
MAIN_HTTP=""
CASE_ERR=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
# $2=0 means true, other false
echo_rst() {
if [[ $2 -eq 0 ]]; then
echo -e "${GRE}$1 ok${NOC}"
else
echo -e "${RED}$1 fail${NOC}"
CASE_ERR="err"
fi
}
# shellcheck source=/dev/null
source ../dapp-test-common.sh
lottery_addCreator_unsignedTx="0a066d616e616765123c0a3a0a0f6c6f74746572792d63726561746f721222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630c788b8f7ccbadbc0703a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32"
lottery_addCreator_unsignedTx_para="0a12757365722e702e706172612e6d616e616765123c0a3a0a0f6c6f74746572792d63726561746f721222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630a8bba1b887e7dade2b3a22314469484633317577783977356a6a733571514269474a6b4e686e71656564763157"
......@@ -28,7 +15,6 @@ lottery_creator_addr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
lottery_creator_priv="0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
gID=""
gResp=""
lottExecAddr=""
luckyNumber=""
......@@ -43,115 +29,14 @@ init() {
if [[ $ispara == true ]]; then
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_priv}"
chain33_SignRawTx "${lottery_addCreator_unsignedTx_para}" "${lottery_creator_priv}" ${MAIN_HTTP}
else
lottExecAddr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"lottery"}]}' ${MAIN_HTTP} | jq -r ".result")
chain33_SendTransaction "${lottery_addCreator_unsignedTx}" "${lottery_creator_priv}"
chain33_SignRawTx "${lottery_addCreator_unsignedTx}" "${lottery_creator_priv}" ${MAIN_HTTP}
fi
echo "lottExecAddr=$lottExecAddr"
}
function block_wait() {
if [[ $# -lt 1 ]]; then
echo "wrong block_wait params"
exit 1
fi
http="$2"
if [[ ! $http ]]; then
http=${MAIN_HTTP}
fi
cur_height=$(curl -ksd '{"method":"Chain33.GetLastHeader","params":[{}]}' -H 'content-type:text/plain;' ${http} | jq -r ".result.height")
expect=$((cur_height + ${1}))
local count=0
while true; do
new_height=$(curl -ksd '{"method":"Chain33.GetLastHeader","params":[{}]}' -H 'content-type:text/plain;' ${http} | jq -r ".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"
}
function query_tx() {
if [[ $# -lt 1 ]]; then
echo "wrong block_wait params"
exit 1
fi
http="$2"
if [[ ! $http ]]; then
http=${MAIN_HTTP}
fi
txhash="$1"
req='{"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]}'
local times=10
block_wait 1 ${http}
while true; do
ret=$(curl -ksd "$req" ${http})
tx=$(jq -r ".result.tx.hash" <<<"$ret")
if [[ ${tx} != "${1}" ]]; then
block_wait 1 ${http}
times=$((times - 1))
if [[ $times -le 0 ]]; then
echo_rst "query tx=$1" 1
exit 1
fi
else
exec_ok=$(jq '(.result.receipt.tyName == "ExecOk")' <<<"$ret")
[[ $exec_ok == true ]]
echo_rst "query tx=$1" $?
echo -e "######\\n response: $ret \\n######"
break
fi
done
}
chain33_SendToAddress() {
from=$1
to=$2
amount=$3
http=$4
note="test"
set -x
resp=$(curl -ksd '{"method":"Chain33.SendToAddress","params":[{"from":"'"$from"'","to":"'"$to"'","amount":'"$amount"',"note":"'"$note"'"}]}' -H 'content-type:text/plain;' "${http}")
ok=$(jq '(.error|not)' <<<"$resp")
set +x
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#查询交易
txhash=$(jq -r ".result.hash" <<<"$resp")
query_tx "$txhash" "$http"
}
chain33_SendTransaction() {
rawTx=$1
priv=$2
#签名交易
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")
set +x
[[ $ok == null ]]
rst=$?
echo_rst "chain33_SignRawTx" "$rst"
signTx=$(echo "${resp}" | jq -r ".result")
set -x
resp=$(curl -ksd '{"method":"Chain33.SendTransaction","params":[{"data":"'"$signTx"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(echo "${resp}" | jq -r ".error")
set +x
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#查询交易
gResp=$(jq -r ".result" <<<"$resp")
query_tx "$gResp"
}
lottery_LotteryCreate() {
#创建交易
priv=$1
......@@ -159,14 +44,15 @@ lottery_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})
ok=$(echo "${resp}" | jq -r ".error")
set +x
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${priv}"
gID="${gResp}"
chain33_SignRawTx "${rawTx}" "${priv}" ${MAIN_HTTP}
set +x
gID="${RAW_TX_HASH}"
echo "gameID $gID"
}
......@@ -180,13 +66,13 @@ lottery_LotteryBuy() {
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryBuy",
"payload":{"lotteryId":"'"$gID"'","amount":'"$amount"',"number":'"$number"',"way":'"$way"',"fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(echo "${resp}" | jq -r ".error")
set +x
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${priv}"
chain33_SignRawTx "${rawTx}" "${priv}" ${MAIN_HTTP}
set +x
}
lottery_LotteryDraw() {
......@@ -196,13 +82,13 @@ lottery_LotteryDraw() {
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryDraw",
"payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(echo "${resp}" | jq -r ".error")
set +x
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${priv}"
chain33_SignRawTx "${rawTx}" "${priv}" ${MAIN_HTTP}
set +x
}
lottery_LotteryClose() {
......@@ -212,13 +98,13 @@ lottery_LotteryClose() {
resp=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"lottery","actionName":"LotteryClose",
"payload":{"lotteryId":"'"$gID"'","fee":1000000}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(echo "${resp}" | jq -r ".error")
set +x
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result")
chain33_SendTransaction "${rawTx}" "${priv}"
chain33_SignRawTx "${rawTx}" "${priv}" ${MAIN_HTTP}
set +x
}
lottery_GetLotteryNormalInfo() {
......@@ -370,20 +256,12 @@ function run_testcases() {
gamePriv1="0x56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138"
gameAddr2="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
gamePriv2="0x2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989"
#该账户需要转账
gameAddr3="12HKLEn6g4FH39yUbHh4EVJWcFo5CXg22d"
gamePriv3="0x9d4f8ab11361be596468b265cb66946c87873d4a119713fd0c3d8302eae0a8e4"
#主链中相应账户需要转帐
M_HTTP=${MAIN_HTTP//8901/8801}
chain33_SendToAddress "${gameAddr1}" "${gameAddr3}" 300000000 "${M_HTTP}"
#平行链相应账户需要转帐
chain33_SendToAddress "${gameAddr1}" "${gameAddr3}" 300000000 "${MAIN_HTTP}"
set -x
#给游戏合约中转帐
chain33_SendToAddress "${gameAddr1}" "${lottExecAddr}" 200000000 "${MAIN_HTTP}"
chain33_SendToAddress "${gameAddr2}" "${lottExecAddr}" 200000000 "${MAIN_HTTP}"
chain33_SendToAddress "${gameAddr3}" "${lottExecAddr}" 200000000 "${MAIN_HTTP}"
chain33_SendToAddress "${gameAddr1}" "${lottExecAddr}" 500000000 "${MAIN_HTTP}"
chain33_SendToAddress "${gameAddr2}" "${lottExecAddr}" 500000000 "${MAIN_HTTP}"
set +x
#创建游戏
lottery_LotteryCreate "${lottery_creator_priv}"
......@@ -392,35 +270,35 @@ function run_testcases() {
#第一次投注
lottery_LotteryBuy "${gamePriv1}" 1 12345 1
lottery_LotteryBuy "${gamePriv2}" 1 66666 2
lottery_LotteryBuy "${gamePriv3}" 1 56789 5
lottery_LotteryBuy "${gamePriv2}" 2 66666 2
#查询
lottery_GetLotteryCurrentInfo "$gID" 2 3
lottery_GetLotteryPurchaseAddr "$gID" 3
lottery_GetLotteryPurchaseAddr "$gID" 2
lottery_GetLotteryHistoryBuyInfo "$gID" "${gameAddr1}" 1 "12345"
lottery_GetLotteryBuyRoundInfo "$gID" "${gameAddr2}" 1 1 "66666"
#第二次投注
lottery_LotteryBuy "${gamePriv1}" 1 12321 1
lottery_LotteryBuy "${gamePriv3}" 1 78987 5
lottery_LotteryBuy "${gamePriv1}" 2 12321 1
lottery_LotteryBuy "${gamePriv2}" 1 78987 5
#查询
lottery_GetLotteryCurrentInfo "$gID" 2 5
lottery_GetLotteryPurchaseAddr "$gID" 3
lottery_GetLotteryCurrentInfo "$gID" 2 6
lottery_GetLotteryPurchaseAddr "$gID" 2
lottery_GetLotteryHistoryBuyInfo "$gID" "${gameAddr1}" 2 "12321"
lottery_GetLotteryBuyRoundInfo "$gID" "${gameAddr3}" 1 2 "78987"
lottery_GetLotteryBuyRoundInfo "$gID" "${gameAddr2}" 1 2 "78987"
#游戏开奖
block_wait ${drawNum} "${M_HTTP}"
M_HTTP=${MAIN_HTTP//8901/8801}
chain33_BlockWait ${drawNum} "${M_HTTP}"
lottery_LotteryDraw "${lottery_creator_priv}"
lottery_GetLotteryCurrentInfo "$gID" 3 0
#游戏查询
lottery_GetLotteryHistoryLuckyNumber "$gID" 1 "${luckyNumber}"
lottery_GetLotteryRoundLuckyNumber "$gID" 1 "${luckyNumber}"
lottery_GetLotteryHistoryGainInfo "$gID" "${gameAddr1}" 1 2
lottery_GetLotteryHistoryGainInfo "$gID" "${gameAddr2}" 1 1
lottery_GetLotteryRoundGainInfo "$gID" "${gameAddr1}" 1 2
lottery_GetLotteryRoundGainInfo "$gID" "${gameAddr3}" 1 2
lottery_GetLotteryHistoryGainInfo "$gID" "${gameAddr1}" 1 3
lottery_GetLotteryHistoryGainInfo "$gID" "${gameAddr2}" 1 3
lottery_GetLotteryRoundGainInfo "$gID" "${gameAddr1}" 1 3
lottery_GetLotteryRoundGainInfo "$gID" "${gameAddr2}" 1 3
#关闭游戏
lottery_LotteryClose "${lottery_creator_priv}"
......
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
ticketId=""
price=$((10000 * 100000000))
ticket_CreateBindMiner() {
#创建交易
minerAddr=$1
returnAddr=$2
returnPriv=$3
amount=$4
set -x
resp=$(curl -ksd '{"method":"ticket.CreateBindMiner","params":[{"bindAddr":"'"$minerAddr"'", "originAddr":"'"$returnAddr"'", "amount":'"$amount"', "checkBalance":true}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(echo "${resp}" | jq -r ".error")
[[ $ok == null ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
#发送交易
rawTx=$(echo "${resp}" | jq -r ".result.txHex")
chain33_SignRawTx "${rawTx}" "${returnPriv}" ${MAIN_HTTP}
set +x
}
ticket_SetAutoMining() {
flag=$1
set -x
resp=$(curl -ksd '{"method":"ticket.SetAutoMining","params":[{"flag":'"$flag"'}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.isOK == true)' <<<"$resp")
set +x
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
ticket_GetTicketCount() {
set -x
resp=$(curl -ksd '{"method":"ticket.GetTicketCount","params":[{}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result > 0)' <<<"$resp")
set +x
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
ticket_CloseTickets() {
addr=$1
set -x
resp=$(curl -ksd '{"method":"ticket.CloseTickets","params":[{"minerAddress":"'"$addr"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.hashes | length > 0)' <<<"$resp")
set +x
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
ticket_TicketInfos() {
tid=$1
minerAddr=$2
returnAddr=$3
status=$4
execer="ticket"
funcName="TicketInfos"
set -x
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"ticketIds":["'"$tid"'"]}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
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")
set +x
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
ticket_TicketList() {
minerAddr=$1
returnAddr=$2
status=$3
execer="ticket"
funcName="TicketList"
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"addr":"'"$minerAddr"'", "status":'"$status"'}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
set -x
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")
set +x
ticket0=$(echo "${resp}" | jq -r ".result.tickets[0]")
echo -e "######\\n ticket[0] is $ticket0) \\n######"
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
if [[ $status == 1 ]]; then
ticketId=$(echo "${resp}" | jq -r ".result.tickets[0].ticketId")
echo -e "######\\n ticketId is $ticketId \\n######"
fi
}
ticket_MinerAddress() {
returnAddr=$1
minerAddr=$2
execer="ticket"
funcName="MinerAddress"
set -x
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"data":"'"$returnAddr"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.data == "'"$minerAddr"'")' <<<"$resp")
set +x
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
ticket_MinerSourceList() {
minerAddr=$1
returnAddr=$2
execer="ticket"
funcName="MinerSourceList"
set -x
resp=$(curl -ksd '{"method":"Chain33.Query","params":[{"execer":"'"$execer"'","funcName":"'"$funcName"'","payload":{"data":"'"$minerAddr"'"}}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
ok=$(jq '(.error|not) and (.result.datas | length > 0) and (.result.datas[0] == "'"$returnAddr"'")' <<<"$resp")
set +x
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
ticket_RandNumHash() {
hash=$1
blockNum=$2
execer="ticket"
funcName="RandNumHash"
set -x
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")
set +x
[[ $ok == true ]]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function run_testcases() {
#账户地址
minerAddr1="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
returnAddr1="1EbDHAXpoiewjPLX9uqoz38HsKqMXayZrF"
minerAddr2="12HKLEn6g4FH39yUbHh4EVJWcFo5CXg22d"
returnAddr2="1NNaYHkscJaLJ2wUrFNeh6cQXBS4TrFYeB"
returnPriv2="0x794443611e7369a57b078881445b93b754cbc9b9b8f526535ab9c6d21d29203d"
set -x
chain33_SendToAddress "${minerAddr1}" "${minerAddr2}" 100000000 "${MAIN_HTTP}"
chain33_SendToAddress "${minerAddr1}" "${returnAddr2}" $((price + 5 * 100000000)) "${MAIN_HTTP}"
set +x
ticket_SetAutoMining 0
ticket_GetTicketCount
ticket_TicketList "${minerAddr1}" "${returnAddr1}" 1
ticket_TicketInfos "${ticketId}" "${minerAddr1}" "${returnAddr1}" 1
#购票
ticket_CreateBindMiner "${minerAddr2}" "${returnAddr2}" "${returnPriv2}" ${price}
ticket_MinerAddress "${returnAddr2}" "${minerAddr2}"
ticket_MinerSourceList "${minerAddr2}" "${returnAddr2}"
#关闭
ticket_CloseTickets "${minerAddr2}"
chain33_LastBlockhash "${MAIN_HTTP}"
ticket_RandNumHash "${LAST_BLOCK_HASH}" 5
}
function main() {
MAIN_HTTP="$1"
echo "main_ip=$MAIN_HTTP"
echo "=========== # ticket rpc test start============="
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
if [[ $ispara == true ]]; then
echo "***skip ticket test on parachain***"
else
run_testcases
fi
if [[ -n $CASE_ERR ]]; then
echo -e "${RED}=============Ticket Rpc Test Fail=============${NOC}"
exit 1
else
echo -e "${GRE}=============Ticket Rpc Test Pass==============${NOC}"
fi
echo "=========== # ticket rpc test end============="
}
main "$1"
......@@ -28,10 +28,14 @@ func bindMiner(param *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) {
// CreateBindMiner 创建绑定挖矿
func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) {
if in.Amount%(10000*types.Coin) != 0 || in.Amount < 0 {
header, err := g.GetLastHeader()
if err != nil {
return nil, err
}
if in.Amount%types.GetP(header.Height).TicketPrice != 0 || in.Amount < 0 {
return nil, types.ErrAmount
}
err := address.CheckAddress(in.BindAddr)
err = address.CheckAddress(in.BindAddr)
if err != nil {
return nil, err
}
......@@ -41,7 +45,7 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner
}
if in.CheckBalance {
getBalance := &types.ReqBalance{Addresses: []string{in.OriginAddr}, Execer: "coins"}
getBalance := &types.ReqBalance{Addresses: []string{in.OriginAddr}, Execer: "coins", AssetSymbol: "bty", AssetExec: "coins"}
balances, err := g.GetCoinsAccountDB().GetBalance(g, getBalance)
if err != nil {
return nil, err
......
......@@ -22,6 +22,25 @@ import (
"google.golang.org/grpc"
)
var cfgstring = `
Title="test"
[mver.consensus]
fundKeyAddr = "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
coinReward = 18
coinDevFund = 12
ticketPrice = 10000
powLimitBits = "0x1f00ffff"
retargetAdjustmentFactor = 4
futureBlockTime = 16
ticketFrozenTime = 5
ticketWithdrawTime = 10
ticketMinerWaitTime = 2
maxTxNumber = 10000
targetTimespan = 2304
targetTimePerBlock = 16
`
func newGrpc(api *mocks.QueueProtocolAPI) *channelClient {
return &channelClient{
ChannelClient: rpctypes.ChannelClient{QueueProtocolAPI: api},
......@@ -45,6 +64,9 @@ func TestChannelClient_BindMiner(t *testing.T) {
storevalue.Values = append(storevalue.Values, accv)
api.On("StoreGet", mock.Anything).Return(storevalue, nil)
types.SetTitleOnlyForTest("test")
types.InitCfgString(cfgstring)
//var addrs = make([]string, 1)
//addrs = append(addrs, "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt")
var in = &ty.ReqBindMiner{
......
......@@ -25,12 +25,7 @@ func (c *channelClient) getTokenBalance(in *tokenty.ReqTokenBalance) ([]*types.A
case types.ExecName(tokenty.TokenX):
addrs := in.GetAddresses()
var queryAddrs []string
for _, addr := range addrs {
if err := address.CheckAddress(addr); err != nil {
addr = string(accountTokendb.AccountKey(addr))
}
queryAddrs = append(queryAddrs, addr)
}
queryAddrs = append(queryAddrs, addrs...)
accounts, err := accountTokendb.LoadAccounts(c.QueueProtocolAPI, queryAddrs)
if err != nil {
......
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