Commit 0800adce authored by mdj33's avatar mdj33 Committed by vipwzw

clean rpc test query func

parent ad01c9ce
...@@ -8,7 +8,7 @@ IS_PARA=false ...@@ -8,7 +8,7 @@ IS_PARA=false
source ../dapp-test-common.sh source ../dapp-test-common.sh
paracross_GetBlock2MainInfo() { paracross_GetBlock2MainInfo() {
chain33_Http '{"method":"paracross.GetBlock2MainInfo","params":[{"start":1,"end":3}]}' ${UNIT_HTTP} "(.result.items[1].height == 2)" "$FUNCNAME" chain33_Http '{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName": "GetBlock2MainInfo", "payload" : {"start":1,"end":3}}]}' ${UNIT_HTTP} '(.result.items[1].height == "2")' "$FUNCNAME"
} }
function paracross_QueryParaBalance() { function paracross_QueryParaBalance() {
...@@ -182,29 +182,29 @@ function paracross_IsSync() { ...@@ -182,29 +182,29 @@ function paracross_IsSync() {
function paracross_ListTitles() { function paracross_ListTitles() {
local main_ip=${UNIT_HTTP//8901/8801} local main_ip=${UNIT_HTTP//8901/8801}
chain33_Http '{"method":"paracross.ListTitles","params":[]}' ${main_ip} '(.error|not) and (.result| [has("titles"),true])' "$FUNCNAME" chain33_Http '{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName": "ListTitles", "payload" : {}}]}' ${main_ip} '(.error|not) and (.result| [has("titles"),true])' "$FUNCNAME"
} }
function paracross_GetHeight() { function paracross_GetHeight() {
if [ "$IS_PARA" == "true" ]; then if [ "$IS_PARA" == "true" ]; then
chain33_Http '{"method":"paracross.GetHeight","params":[]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("consensHeight"),true])' "$FUNCNAME" chain33_Http '{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName": "GetHeight", "payload" : {}}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("consensHeight"),true])' "$FUNCNAME"
fi fi
} }
function paracross_GetNodeGroupAddrs() { function paracross_GetNodeGroupAddrs() {
chain33_Http '{"method":"paracross.GetNodeGroupAddrs","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("key","value"),true])' "$FUNCNAME" chain33_Http '{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetNodeGroupAddrs","payload":{"title":"user.p.para."}}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("key","value"),true])' "$FUNCNAME"
} }
function paracross_GetNodeGroupStatus() { function paracross_GetNodeGroupStatus() {
chain33_Http '{"method":"paracross.GetNodeGroupStatus","params":[{"title":"user.p.para."}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME" chain33_Http '{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetNodeGroupStatus","payload":{"title":"user.p.para."}}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME"
} }
function paracross_ListNodeGroupStatus() { function paracross_ListNodeGroupStatus() {
chain33_Http '{"method":"paracross.ListNodeGroupStatus","params":[{"title":"user.p.para.","status":2}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME" chain33_Http '{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"ListNodeGroupStatus","payload":{"title":"user.p.para.","status":2}}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME"
} }
function paracross_ListNodeStatus() { function paracross_ListNodeStatus() {
chain33_Http '{"method":"paracross.ListNodeStatus","params":[{"title":"user.p.para.","status":4}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME" chain33_Http '{"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"ListNodeStatusInfo","payload":{"title":"user.p.para.","status":4}}]}' ${UNIT_HTTP} '(.error|not) and (.result| [has("status"),true])' "$FUNCNAME"
} }
para_test_addr="1MAuE8QSbbech3bVKK2JPJJxYxNtT95oSU" para_test_addr="1MAuE8QSbbech3bVKK2JPJJxYxNtT95oSU"
...@@ -372,7 +372,7 @@ function paracross_testTxGroup() { ...@@ -372,7 +372,7 @@ function paracross_testTxGroup() {
paracross_testSelfConsensStages() { paracross_testSelfConsensStages() {
local para_ip=$1 local para_ip=$1
req='"method":"paracross.GetHeight","params":[]' req='"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName": "GetHeight", "payload" : {}}]'
resp=$(curl -ksd "{$req}" "${para_ip}") resp=$(curl -ksd "{$req}" "${para_ip}")
err=$(jq '(.error)' <<<"$resp") err=$(jq '(.error)' <<<"$resp")
if [ "$err" != null ]; then if [ "$err" != null ]; then
...@@ -388,7 +388,7 @@ paracross_testSelfConsensStages() { ...@@ -388,7 +388,7 @@ paracross_testSelfConsensStages() {
chain33_SignAndSendTx "$rawtx" "$para_test_prikey" "${para_ip}" chain33_SignAndSendTx "$rawtx" "$para_test_prikey" "${para_ip}"
echo "get stage apply id" echo "get stage apply id"
req='"method":"paracross.ListSelfStages","params":[{"status":1,"count":1}]' req='"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"ListSelfStages","payload":{"status":1,"count":1}}]'
resp=$(curl -ksd "{$req}" "${para_ip}") resp=$(curl -ksd "{$req}" "${para_ip}")
echo "$resp" echo "$resp"
id=$(jq -r ".result.stageInfo[0].id" <<<"$resp") id=$(jq -r ".result.stageInfo[0].id" <<<"$resp")
...@@ -413,22 +413,22 @@ paracross_testSelfConsensStages() { ...@@ -413,22 +413,22 @@ paracross_testSelfConsensStages() {
chain33_SignAndSendTx "$rawtx" "$NL_PRI" "${para_ip}" "111s" chain33_SignAndSendTx "$rawtx" "$NL_PRI" "${para_ip}" "111s"
echo "query status" echo "query status"
req='"method":"paracross.ListSelfStages","params":[{"status":3,"count":1}]' req='"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"ListSelfStages","payload":{"status":3,"count":1}}]'
resp=$(curl -ksd "{$req}" "${para_ip}") resp=$(curl -ksd "{$req}" "${para_ip}")
echo "$resp" echo "$resp"
ok1=$(jq '(.error|not) and (.result| [has("id"),true])' <<<"$resp") ok1=$(jq '(.error|not) and (.result| [has("id"),true])' <<<"$resp")
req='"method":"paracross.GetSelfConsStages","params":[]' req='"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetSelfConsStages","payload":{}}]'
resp=$(curl -ksd "{$req}" "${para_ip}") resp=$(curl -ksd "{$req}" "${para_ip}")
echo "$resp" echo "$resp"
ok2=$(jq '(.error|not) and (.result| [has("startHeight"),true])' <<<"$resp") ok2=$(jq '(.error|not) and (.result| [has("startHeight"),true])' <<<"$resp")
req='"method":"paracross.GetSelfConsOneStage","params":[{"data":1000}]' req='"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetSelfConsOneStage","payload":{"data":1000}}]'
resp=$(curl -ksd "{$req}" "${para_ip}") resp=$(curl -ksd "{$req}" "${para_ip}")
echo "$resp" echo "$resp"
ok3=$(jq '(.error|not) and (.result.enable==1)' <<<"$resp") ok3=$(jq '(.error|not) and (.result.enable==1)' <<<"$resp")
req='"method":"paracross.GetSelfConsOneStage","params":[{"data":'"$newHeight"'}]' req='"method":"Chain33.Query","params":[{ "execer":"paracross", "funcName":"GetSelfConsOneStage","payload":{"data":'"$newHeight"'}}]'
resp=$(curl -ksd "{$req}" "${para_ip}") resp=$(curl -ksd "{$req}" "${para_ip}")
echo "$resp" echo "$resp"
ok4=$(jq '(.error|not) and (.result.enable==2)' <<<"$resp") ok4=$(jq '(.error|not) and (.result.enable==2)' <<<"$resp")
......
This diff is collapsed.
...@@ -28,6 +28,10 @@ func (p *Paracross) Query_GetTitleHeight(in *pt.ReqParacrossTitleHeight) (types. ...@@ -28,6 +28,10 @@ func (p *Paracross) Query_GetTitleHeight(in *pt.ReqParacrossTitleHeight) (types.
if in == nil { if in == nil {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
cfg := p.GetAPI().GetConfig()
if cfg.IsPara() {
in.Title = cfg.GetTitle()
}
stat, err := p.paracrossGetStateTitleHeight(in.Title, in.Height) stat, err := p.paracrossGetStateTitleHeight(in.Title, in.Height)
if err != nil { if err != nil {
clog.Error("paracross.GetTitleHeight", "title", title, "height", in.Height, "err", err.Error()) clog.Error("paracross.GetTitleHeight", "title", title, "height", in.Height, "err", err.Error())
...@@ -63,13 +67,20 @@ func (p *Paracross) Query_GetTitleByHash(in *pt.ReqParacrossTitleHash) (types.Me ...@@ -63,13 +67,20 @@ func (p *Paracross) Query_GetTitleByHash(in *pt.ReqParacrossTitleHash) (types.Me
//Query_GetNodeGroupAddrs get node group addrs //Query_GetNodeGroupAddrs get node group addrs
func (p *Paracross) Query_GetNodeGroupAddrs(in *pt.ReqParacrossNodeInfo) (types.Message, error) { func (p *Paracross) Query_GetNodeGroupAddrs(in *pt.ReqParacrossNodeInfo) (types.Message, error) {
if in == nil || in.GetTitle() == "" { if in == nil {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
cfg := p.GetAPI().GetConfig()
if cfg.IsPara() {
in.Title = cfg.GetTitle()
} else if in.Title == "" {
return nil, errors.Wrap(types.ErrInvalidParam, "title is null")
}
ret, key, err := getConfigNodes(p.GetStateDB(), in.GetTitle()) ret, key, err := getConfigNodes(p.GetStateDB(), in.GetTitle())
if err != nil { if err != nil {
return nil, errors.Cause(err) return nil, err
} }
var nodes []string var nodes []string
for k := range ret { for k := range ret {
...@@ -83,9 +94,16 @@ func (p *Paracross) Query_GetNodeGroupAddrs(in *pt.ReqParacrossNodeInfo) (types. ...@@ -83,9 +94,16 @@ func (p *Paracross) Query_GetNodeGroupAddrs(in *pt.ReqParacrossNodeInfo) (types.
//Query_GetNodeAddrInfo get specific node addr info //Query_GetNodeAddrInfo get specific node addr info
func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Message, error) { func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Message, error) {
if in == nil || in.Title == "" || in.Addr == "" { if in == nil || in.Addr == "" {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
cfg := p.GetAPI().GetConfig()
if cfg.IsPara() {
in.Title = cfg.GetTitle()
} else if in.Title == "" {
return nil, types.ErrInvalidParam
}
stat, err := getNodeAddr(p.GetStateDB(), in.Title, in.Addr) stat, err := getNodeAddr(p.GetStateDB(), in.Title, in.Addr)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -94,7 +112,7 @@ func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Me ...@@ -94,7 +112,7 @@ func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Me
if err != nil { if err != nil {
return nil, err return nil, err
} }
cfg := p.GetAPI().GetConfig()
if pt.IsParaForkHeight(cfg, mainHeight, pt.ForkLoopCheckCommitTxDone) { if pt.IsParaForkHeight(cfg, mainHeight, pt.ForkLoopCheckCommitTxDone) {
stat.QuitId = getParaNodeIDSuffix(stat.QuitId) stat.QuitId = getParaNodeIDSuffix(stat.QuitId)
stat.ProposalId = getParaNodeIDSuffix(stat.ProposalId) stat.ProposalId = getParaNodeIDSuffix(stat.ProposalId)
...@@ -117,14 +135,21 @@ func (p *Paracross) getMainHeight() (int64, error) { ...@@ -117,14 +135,21 @@ func (p *Paracross) getMainHeight() (int64, error) {
//Query_GetNodeIDInfo get specific node addr info //Query_GetNodeIDInfo get specific node addr info
func (p *Paracross) Query_GetNodeIDInfo(in *pt.ReqParacrossNodeInfo) (types.Message, error) { func (p *Paracross) Query_GetNodeIDInfo(in *pt.ReqParacrossNodeInfo) (types.Message, error) {
if in == nil || in.Title == "" || in.Id == "" { if in == nil || in.Id == "" {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
cfg := p.GetAPI().GetConfig()
if cfg.IsPara() {
in.Title = cfg.GetTitle()
} else if in.Title == "" {
return nil, errors.Wrap(types.ErrInvalidParam, "title is null")
}
mainHeight, err := p.getMainHeight() mainHeight, err := p.getMainHeight()
if err != nil { if err != nil {
return nil, err return nil, err
} }
cfg := p.GetAPI().GetConfig()
stat, err := getNodeIDWithFork(cfg, p.GetStateDB(), in.Title, mainHeight, in.Id) stat, err := getNodeIDWithFork(cfg, p.GetStateDB(), in.Title, mainHeight, in.Id)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -214,6 +239,10 @@ func (p *Paracross) Query_GetDoneTitleHeight(in *pt.ReqParacrossTitleHeight) (ty ...@@ -214,6 +239,10 @@ func (p *Paracross) Query_GetDoneTitleHeight(in *pt.ReqParacrossTitleHeight) (ty
if in == nil { if in == nil {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
cfg := p.GetAPI().GetConfig()
if cfg.IsPara() {
in.Title = cfg.GetTitle()
}
return p.paracrossGetTitleHeight(in.Title, in.Height) return p.paracrossGetTitleHeight(in.Title, in.Height)
} }
...@@ -459,3 +488,60 @@ func (p *Paracross) Query_GetSelfConsOneStage(in *types.Int64) (types.Message, e ...@@ -459,3 +488,60 @@ func (p *Paracross) Query_GetSelfConsOneStage(in *types.Int64) (types.Message, e
func (p *Paracross) Query_ListSelfStages(in *pt.ReqQuerySelfStages) (types.Message, error) { func (p *Paracross) Query_ListSelfStages(in *pt.ReqQuerySelfStages) (types.Message, error) {
return p.listSelfStages(in) return p.listSelfStages(in)
} }
func (p *Paracross) Query_GetBlock2MainInfo(req *types.ReqBlocks) (*pt.ParaBlock2MainInfo, error) {
ret := &pt.ParaBlock2MainInfo{}
details, err := p.GetAPI().GetBlocks(req)
if err != nil {
return nil, err
}
cfg := p.GetAPI().GetConfig()
for _, item := range details.Items {
data := &pt.ParaBlock2MainMap{
Height: item.Block.Height,
BlockHash: common.ToHex(item.Block.Hash(cfg)),
MainHeight: item.Block.MainHeight,
MainHash: common.ToHex(item.Block.MainHash),
}
ret.Items = append(ret.Items, data)
}
return ret, nil
}
func (p *Paracross) Query_GetHeight(req *types.ReqString) (*pt.ParacrossConsensusStatus, error) {
cfg := p.GetAPI().GetConfig()
if req == nil || req.Data == "" {
if !cfg.IsPara() {
return nil, errors.Wrap(types.ErrInvalidParam, "req invalid")
}
}
reqTitle := req.Data
if cfg.IsPara() {
reqTitle = cfg.GetTitle()
}
res, err := p.paracrossGetHeight(reqTitle)
if err != nil {
return nil, errors.Wrapf(err, "title:%s", reqTitle)
}
header, err := p.GetAPI().GetLastHeader()
if err != nil {
return nil, errors.Wrap(err, "GetLastHeader")
}
chainHeight := header.Height
if resp, ok := res.(*pt.ParacrossStatus); ok {
// 如果主链上查询平行链的高度,chain height应该是平行链的高度而不是主链高度, 平行链的真实高度需要在平行链侧查询
if !cfg.IsPara() {
chainHeight = resp.Height
}
return &pt.ParacrossConsensusStatus{
Title: resp.Title,
ChainHeight: chainHeight,
ConsensHeight: resp.Height,
ConsensBlockHash: common.ToHex(resp.BlockHash),
}, nil
}
return nil, types.ErrDecode
}
...@@ -424,10 +424,5 @@ message ParaLocalDbBlockInfo { ...@@ -424,10 +424,5 @@ message ParaLocalDbBlockInfo {
} }
service paracross { service paracross {
rpc GetTitle(ReqString) returns (ParacrossConsensusStatus) {}
rpc ListTitles(ReqNil) returns (RespParacrossTitles) {}
rpc GetDoneTitleHeight(ReqParacrossTitleHeight) returns (RespParacrossDone) {}
rpc GetTitleHeight(ReqParacrossTitleHeight) returns (ParacrossHeightStatusRsp) {}
rpc GetAssetTxResult(ReqString) returns (ParacrossAssetRsp) {}
rpc IsSync(ReqNil) returns (IsCaughtUp) {} rpc IsSync(ReqNil) returns (IsCaughtUp) {}
} }
\ No newline at end of file
This diff is collapsed.
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