Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
976f0a1b
Commit
976f0a1b
authored
Dec 26, 2018
by
harrylee2015
Committed by
vipwzw
Jan 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rpc_test
parent
1d8ddb8c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
190 additions
and
1 deletion
+190
-1
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+3
-0
rpc.go
plugin/dapp/paracross/rpc/rpc.go
+1
-1
rpc_test.go
plugin/dapp/paracross/rpc/rpc_test.go
+186
-0
paracross.pb.go
plugin/dapp/paracross/types/paracross.pb.go
+0
-0
No files found.
plugin/dapp/paracross/proto/paracross.proto
View file @
976f0a1b
...
...
@@ -2,6 +2,7 @@ syntax = "proto3";
import
"transaction.proto"
;
import
"common.proto"
;
import
"blockchain.proto"
;
package
types
;
...
...
@@ -130,4 +131,5 @@ service paracross {
rpc
ListTitles
(
ReqNil
)
returns
(
RespParacrossTitles
)
{}
rpc
GetTitleHeight
(
ReqParacrossTitleHeight
)
returns
(
ReceiptParacrossDone
)
{}
rpc
GetAssetTxResult
(
ReqHash
)
returns
(
ParacrossAsset
)
{}
rpc
IsSync
(
ReqNil
)
returns
(
IsCaughtUp
)
{}
}
\ No newline at end of file
plugin/dapp/paracross/rpc/rpc.go
View file @
976f0a1b
...
...
@@ -102,7 +102,7 @@ func (g *channelClient) IsSync(ctx context.Context, in *types.ReqNil) (*types.Is
}
// IsSync query is sync
func
(
c
*
Jrpc
)
IsSync
(
in
*
types
.
ReqNil
,
result
*
bool
)
error
{
func
(
c
*
Jrpc
)
IsSync
(
in
*
types
.
ReqNil
,
result
*
interface
{}
)
error
{
//TODO consensus and paracross are not the same registered names ?
data
,
err
:=
c
.
cli
.
QueryConsensusFunc
(
"para"
,
"IsCaughtUp"
,
&
types
.
ReqNil
{})
*
result
=
false
...
...
plugin/dapp/paracross/rpc/rpc_test.go
0 → 100644
View file @
976f0a1b
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package
rpc
//only load all plugin and system
import
(
"github.com/33cn/chain33/client/mocks"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
"testing"
)
func
newGrpc
(
api
*
mocks
.
QueueProtocolAPI
)
*
channelClient
{
return
&
channelClient
{
ChannelClient
:
rpctypes
.
ChannelClient
{
QueueProtocolAPI
:
api
},
}
}
func
newJrpc
(
api
*
mocks
.
QueueProtocolAPI
)
*
Jrpc
{
return
&
Jrpc
{
cli
:
newGrpc
(
api
)}
}
func
TestChannelClient_GetTitle
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqString
{
Data
:
"xxxxxxxxxxx"
}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetTitle"
,
req
)
.
Return
(
&
pt
.
ParacrossStatus
{},
nil
)
_
,
err
:=
client
.
GetTitle
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestJrpc_GetTitle
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
j
:=
newJrpc
(
api
)
req
:=
&
types
.
ReqString
{
Data
:
"xxxxxxxxxxx"
}
var
result
interface
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetTitle"
,
req
)
.
Return
(
&
pt
.
ParacrossStatus
{},
nil
)
err
:=
j
.
GetHeight
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
}
func
TestChannelClient_ListTitles
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqNil
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"ListTitles"
,
req
)
.
Return
(
&
pt
.
RespParacrossTitles
{},
nil
)
_
,
err
:=
client
.
ListTitles
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestJrpc_ListTitles
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
j
:=
newJrpc
(
api
)
req
:=
&
types
.
ReqNil
{}
var
result
interface
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"ListTitles"
,
req
)
.
Return
(
&
pt
.
RespParacrossTitles
{},
nil
)
err
:=
j
.
ListTitles
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
}
func
TestChannelClient_GetTitleHeight
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
pt
.
ReqParacrossTitleHeight
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetTitleHeight"
,
req
)
.
Return
(
&
pt
.
ReceiptParacrossDone
{},
nil
)
_
,
err
:=
client
.
GetTitleHeight
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestJrpc_GetTitleHeight
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
j
:=
newJrpc
(
api
)
req
:=
&
pt
.
ReqParacrossTitleHeight
{}
var
result
interface
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetTitleHeight"
,
req
)
.
Return
(
&
pt
.
ReceiptParacrossDone
{},
nil
)
err
:=
j
.
GetTitleHeight
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
}
func
TestChannelClient_GetAssetTxResult
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqHash
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetAssetTxResult"
,
req
)
.
Return
(
&
pt
.
ParacrossAsset
{},
nil
)
_
,
err
:=
client
.
GetAssetTxResult
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestJrpc_GetAssetTxResult
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
j
:=
newJrpc
(
api
)
req
:=
&
types
.
ReqHash
{}
var
result
interface
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetAssetTxResult"
,
req
)
.
Return
(
&
pt
.
ParacrossAsset
{},
nil
)
err
:=
j
.
GetAssetTxResult
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
}
func
TestChannelClient_IsSync
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqNil
{}
api
.
On
(
"QueryConsensusFunc"
,
"para"
,
"IsCaughtUp"
,
req
)
.
Return
(
&
types
.
IsCaughtUp
{},
nil
)
_
,
err
:=
client
.
IsSync
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestJrpc_IsSync
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
J
:=
newJrpc
(
api
)
req
:=
&
types
.
ReqNil
{}
var
result
interface
{}
api
.
On
(
"QueryConsensusFunc"
,
"para"
,
"IsCaughtUp"
,
req
)
.
Return
(
&
types
.
IsCaughtUp
{},
nil
)
err
:=
J
.
IsSync
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
}
//TODO wait finish
//func TestRPC_CallTestNode(t *testing.T) {
// api := new(mocks.QueueProtocolAPI)
// cfg, sub := testnode.GetDefaultConfig()
// // para consensus
// cfg.Consensus.Name = "para"
// cfg.Title="user.p.test."
// cfg.BlockChain.IsParaChain=true
// cfg.Store.Name="mavl"
// mock33 := testnode.NewWithConfig(cfg, sub, api)
// defer func() {
// mock33.Close()
// mock.AssertExpectationsForObjects(t, api)
// }()
// g := newGrpc(api)
// g.Init(pt.GetExecName(), mock33.GetRPC(), newJrpc(api), g)
// time.Sleep(time.Millisecond)
// mock33.Listen()
// time.Sleep(time.Millisecond)
// api.On("Query", pt.GetExecName(), "GetTitle", &types.ReqString{}).Return(&pt.ParacrossStatus{Title:"test"}, nil)
// api.On("Query", pt.GetExecName(), "ListTitles", &types.ReqNil{}).Return(&pt.RespParacrossTitles{Titles:[]*pt.ReceiptParacrossDone{&pt.ReceiptParacrossDone{Title:"test1"},&pt.ReceiptParacrossDone{Title:"test2"}}}, nil)
// api.On("Query", pt.GetExecName(), "GetTitleHeight", &pt.ReqParacrossTitleHeight{}).Return(&pt.ReceiptParacrossDone{Height:10}, nil)
// api.On("Query", pt.GetExecName(), "GetAssetTxResult", &types.ReqHash{}).Return(&pt.ParacrossAsset{Symbol:"test"}, nil)
// api.On("QueryConsensusFunc", "para", "IsCaughtUp",&types.ReqNil{}).Return(&types.IsCaughtUp{Iscaughtup:true}, nil)
// //test jrpc
// rpcCfg := mock33.GetCfg().RPC
// jsonClient, err := jsonclient.NewJSONClient("http://" + rpcCfg.JrpcBindAddr + "/")
// assert.Nil(t, err)
// assert.NotNil(t, jsonClient)
// var result pt.ParacrossStatus
// err = jsonClient.Call("paracross.GetHeight", nil, &result)
// fmt.Println(err)
// assert.Nil(t, err)
// assert.Equal(t, "test", result.Title)
//
// var reply types.IsCaughtUp
// err = jsonClient.Call("paracross.IsSync", &types.ReqNil{}, &reply)
// assert.Nil(t, err)
// assert.Equal(t, true, reply.Iscaughtup)
//
// var res pt.RespParacrossTitles
// err = jsonClient.Call("paracross.ListTitles", &types.ReqNil{}, &res)
// assert.Nil(t, err)
// assert.Equal(t, 2, len(res.Titles))
//
// //test grpc
//
// ctx := context.Background()
// c, err := grpc.DialContext(ctx, rpcCfg.GrpcBindAddr, grpc.WithInsecure())
// assert.Nil(t, err)
// assert.NotNil(t, c)
//
// client := pt.NewParacrossClient(c)
// issync, err := client.IsSync(ctx, &types.ReqNil{})
// assert.Nil(t, err)
// assert.Equal(t, true, issync.Iscaughtup)
//}
plugin/dapp/paracross/types/paracross.pb.go
View file @
976f0a1b
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment