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
0cb95366
Commit
0cb95366
authored
Jan 11, 2019
by
vipwzw
Committed by
33cn
Jan 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update chain33
parent
0c5d333f
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
190 additions
and
90 deletions
+190
-90
chain_test.go
vendor/github.com/33cn/chain33/blockchain/chain_test.go
+23
-0
proc.go
vendor/github.com/33cn/chain33/blockchain/proc.go
+29
-0
mock_blockchain_test.go
...or/github.com/33cn/chain33/client/mock_blockchain_test.go
+8
-0
api.go
vendor/github.com/33cn/chain33/client/mocks/api.go
+18
-18
queueprotocol.go
vendor/github.com/33cn/chain33/client/queueprotocol.go
+7
-9
queueprotocol_test.go
vendor/github.com/33cn/chain33/client/queueprotocol_test.go
+20
-0
queueprotocolapi.go
vendor/github.com/33cn/chain33/client/queueprotocolapi.go
+3
-2
rpc_ctx_test.go
vendor/github.com/33cn/chain33/client/rpc_ctx_test.go
+6
-0
grpchandler.go
vendor/github.com/33cn/chain33/rpc/grpchandler.go
+10
-5
jrpchandler.go
vendor/github.com/33cn/chain33/rpc/jrpchandler.go
+0
-16
jrpchandler_test.go
vendor/github.com/33cn/chain33/rpc/jrpchandler_test.go
+0
-20
server_test.go
vendor/github.com/33cn/chain33/rpc/server_test.go
+9
-0
event.go
vendor/github.com/33cn/chain33/types/event.go
+3
-0
chain33client.go
vendor/github.com/33cn/chain33/types/mocks/chain33client.go
+47
-17
common.proto
vendor/github.com/33cn/chain33/types/proto/common.proto
+0
-0
rpc.proto
vendor/github.com/33cn/chain33/types/proto/rpc.proto
+7
-3
rpc.pb.go
vendor/github.com/33cn/chain33/types/rpc.pb.go
+0
-0
No files found.
vendor/github.com/33cn/chain33/blockchain/chain_test.go
View file @
0cb95366
...
...
@@ -116,6 +116,7 @@ func TestBlockChain(t *testing.T) {
testProcDelParaChainBlockMsg
(
t
,
mock33
,
blockchain
)
testProcAddParaChainBlockMsg
(
t
,
mock33
,
blockchain
)
testProcGetBlockBySeqMsg
(
t
,
mock33
,
blockchain
)
testProcBlockChainFork
(
t
,
blockchain
)
testDelBlock
(
t
,
blockchain
,
curBlock
)
...
...
@@ -895,6 +896,28 @@ func testProcAddParaChainBlockMsg(t *testing.T, mock33 *testnode.Chain33Mock, bl
chainlog
.
Info
(
"testProcAddParaChainBlockMsg end --------------------"
)
}
func
testProcGetBlockBySeqMsg
(
t
*
testing
.
T
,
mock33
*
testnode
.
Chain33Mock
,
blockchain
*
blockchain
.
BlockChain
)
{
chainlog
.
Info
(
"testProcGetBlockBySeqMsg begin --------------------"
)
seq
,
err
:=
blockchain
.
GetStore
()
.
LoadBlockLastSequence
()
assert
.
Nil
(
t
,
err
)
//block, err := blockchain.GetBlock(curheight)
//require.NoError(t, err)
msgGen
:=
mock33
.
GetClient
()
.
NewMessage
(
"blockchain"
,
types
.
EventGetBlockBySeq
,
&
types
.
Int64
{
Data
:
seq
})
mock33
.
GetClient
()
.
Send
(
msgGen
,
true
)
msg
,
err
:=
mock33
.
GetClient
()
.
Wait
(
msgGen
)
if
err
!=
nil
{
t
.
Log
(
err
)
//t.Error("testProcAddParaChainBlockMsg only in parachain ")
}
blockseq
:=
msg
.
Data
.
(
*
types
.
BlockSeq
)
assert
.
Equal
(
t
,
seq
,
blockseq
.
Num
)
chainlog
.
Info
(
"testProcGetBlockBySeqMsg end --------------------"
)
}
func
testProcBlockChainFork
(
t
*
testing
.
T
,
blockchain
*
blockchain
.
BlockChain
)
{
chainlog
.
Info
(
"testProcBlockChainFork begin --------------------"
)
...
...
vendor/github.com/33cn/chain33/blockchain/proc.go
View file @
0cb95366
...
...
@@ -73,6 +73,9 @@ func (chain *BlockChain) ProcRecvMsg() {
case
types
.
EventGetBlockByHashes
:
go
chain
.
processMsg
(
msg
,
reqnum
,
chain
.
getBlockByHashes
)
case
types
.
EventGetBlockBySeq
:
go
chain
.
processMsg
(
msg
,
reqnum
,
chain
.
getBlockBySeq
)
case
types
.
EventDelParaChainBlockDetail
:
go
chain
.
processMsg
(
msg
,
reqnum
,
chain
.
delParaChainBlockDetail
)
...
...
@@ -418,6 +421,32 @@ func (chain *BlockChain) getBlockByHashes(msg queue.Message) {
}
}
func
(
chain
*
BlockChain
)
getBlockBySeq
(
msg
queue
.
Message
)
{
seq
:=
(
msg
.
Data
)
.
(
*
types
.
Int64
)
req
:=
&
types
.
ReqBlocks
{
Start
:
seq
.
Data
,
End
:
seq
.
Data
,
IsDetail
:
false
,
Pid
:
[]
string
{}}
sequences
,
err
:=
chain
.
GetBlockSequences
(
req
)
if
err
!=
nil
{
chainlog
.
Error
(
"getBlockBySeq"
,
"seq err"
,
err
.
Error
())
msg
.
Reply
(
chain
.
client
.
NewMessage
(
"rpc"
,
types
.
EventGetBlockBySeq
,
err
))
return
}
reqHashes
:=
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
sequences
.
Items
[
0
]
.
Hash
}}
blocks
,
err
:=
chain
.
GetBlockByHashes
(
reqHashes
.
Hashes
)
if
err
!=
nil
{
chainlog
.
Error
(
"getBlockBySeq"
,
"hash err"
,
err
.
Error
())
msg
.
Reply
(
chain
.
client
.
NewMessage
(
"rpc"
,
types
.
EventGetBlockBySeq
,
err
))
return
}
blockSeq
:=
&
types
.
BlockSeq
{
Num
:
seq
.
Data
,
Seq
:
sequences
.
Items
[
0
],
Detail
:
blocks
.
Items
[
0
],
}
msg
.
Reply
(
chain
.
client
.
NewMessage
(
"rpc"
,
types
.
EventGetBlockBySeq
,
blockSeq
))
}
//平行链del block的处理
func
(
chain
*
BlockChain
)
delParaChainBlockDetail
(
msg
queue
.
Message
)
{
var
parablockDetail
*
types
.
ParaChainBlockDetail
...
...
vendor/github.com/33cn/chain33/client/mock_blockchain_test.go
View file @
0cb95366
...
...
@@ -104,6 +104,14 @@ func (m *mockBlockChain) SetQueueClient(q queue.Queue) {
case
types
.
EventGetSeqByHash
:
msg
.
Reply
(
client
.
NewMessage
(
blockchainKey
,
types
.
EventReplyQuery
,
&
types
.
Int64
{
Data
:
1
}))
case
types
.
EventGetBlockBySeq
:
if
req
,
ok
:=
msg
.
GetData
()
.
(
*
types
.
Int64
);
ok
{
// just for cover
if
req
.
Data
==
10
{
msg
.
Reply
(
client
.
NewMessage
(
blockchainKey
,
types
.
EventReplyQuery
,
&
types
.
Reply
{
IsOk
:
false
,
Msg
:
[]
byte
(
"not support"
)}))
}
msg
.
Reply
(
client
.
NewMessage
(
blockchainKey
,
types
.
EventReplyQuery
,
&
types
.
BlockSeq
{
Num
:
1
}))
}
case
types
.
EventIsSync
:
msg
.
Reply
(
client
.
NewMessage
(
blockchainKey
,
types
.
EventReplyIsSync
,
&
types
.
IsCaughtUp
{}))
case
types
.
EventIsNtpClockSync
:
...
...
vendor/github.com/33cn/chain33/client/mocks/api.go
View file @
0cb95366
...
...
@@ -200,21 +200,21 @@ func (_m *QueueProtocolAPI) GetBlockByHashes(param *types.ReqHashes) (*types.Blo
return
r0
,
r1
}
// GetBlock
Hash
provides a mock function with given fields: param
func
(
_m
*
QueueProtocolAPI
)
GetBlock
Hash
(
param
*
types
.
ReqInt
)
(
*
types
.
ReplyHash
,
error
)
{
// GetBlock
BySeq
provides a mock function with given fields: param
func
(
_m
*
QueueProtocolAPI
)
GetBlock
BySeq
(
param
*
types
.
Int64
)
(
*
types
.
BlockSeq
,
error
)
{
ret
:=
_m
.
Called
(
param
)
var
r0
*
types
.
ReplyHash
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
*
types
.
ReqInt
)
*
types
.
ReplyHash
);
ok
{
var
r0
*
types
.
BlockSeq
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
*
types
.
Int64
)
*
types
.
BlockSeq
);
ok
{
r0
=
rf
(
param
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
ReplyHash
)
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
BlockSeq
)
}
}
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
*
types
.
ReqInt
)
error
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
*
types
.
Int64
)
error
);
ok
{
r1
=
rf
(
param
)
}
else
{
r1
=
ret
.
Error
(
1
)
...
...
@@ -223,21 +223,21 @@ func (_m *QueueProtocolAPI) GetBlockHash(param *types.ReqInt) (*types.ReplyHash,
return
r0
,
r1
}
// GetBlock
Overview
provides a mock function with given fields: param
func
(
_m
*
QueueProtocolAPI
)
GetBlock
Overview
(
param
*
types
.
ReqHash
)
(
*
types
.
BlockOverview
,
error
)
{
// GetBlock
Hash
provides a mock function with given fields: param
func
(
_m
*
QueueProtocolAPI
)
GetBlock
Hash
(
param
*
types
.
ReqInt
)
(
*
types
.
ReplyHash
,
error
)
{
ret
:=
_m
.
Called
(
param
)
var
r0
*
types
.
BlockOverview
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
*
types
.
Req
Hash
)
*
types
.
BlockOverview
);
ok
{
var
r0
*
types
.
ReplyHash
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
*
types
.
Req
Int
)
*
types
.
ReplyHash
);
ok
{
r0
=
rf
(
param
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
BlockOverview
)
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
ReplyHash
)
}
}
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
*
types
.
Req
Hash
)
error
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
*
types
.
Req
Int
)
error
);
ok
{
r1
=
rf
(
param
)
}
else
{
r1
=
ret
.
Error
(
1
)
...
...
@@ -246,21 +246,21 @@ func (_m *QueueProtocolAPI) GetBlockOverview(param *types.ReqHash) (*types.Block
return
r0
,
r1
}
// GetBlock
Sequences
provides a mock function with given fields: param
func
(
_m
*
QueueProtocolAPI
)
GetBlock
Sequences
(
param
*
types
.
ReqBlocks
)
(
*
types
.
BlockSequences
,
error
)
{
// GetBlock
Overview
provides a mock function with given fields: param
func
(
_m
*
QueueProtocolAPI
)
GetBlock
Overview
(
param
*
types
.
ReqHash
)
(
*
types
.
BlockOverview
,
error
)
{
ret
:=
_m
.
Called
(
param
)
var
r0
*
types
.
Block
Sequences
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
*
types
.
Req
Blocks
)
*
types
.
BlockSequences
);
ok
{
var
r0
*
types
.
Block
Overview
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
*
types
.
Req
Hash
)
*
types
.
BlockOverview
);
ok
{
r0
=
rf
(
param
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Block
Sequences
)
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Block
Overview
)
}
}
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
*
types
.
Req
Blocks
)
error
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
*
types
.
Req
Hash
)
error
);
ok
{
r1
=
rf
(
param
)
}
else
{
r1
=
ret
.
Error
(
1
)
...
...
vendor/github.com/33cn/chain33/client/queueprotocol.go
View file @
0cb95366
...
...
@@ -950,24 +950,22 @@ func (q *QueueProtocol) GetBlockByHashes(param *types.ReqHashes) (*types.BlockDe
return
nil
,
err
}
// GetBlock
Sequences block执行序列号
func
(
q
*
QueueProtocol
)
GetBlock
Sequences
(
param
*
types
.
ReqBlocks
)
(
*
types
.
BlockSequences
,
error
)
{
// GetBlock
BySeq get block detail and hash by seq
func
(
q
*
QueueProtocol
)
GetBlock
BySeq
(
param
*
types
.
Int64
)
(
*
types
.
BlockSeq
,
error
)
{
if
param
==
nil
{
err
:=
types
.
ErrInvalidParam
log
.
Error
(
"GetBlock
Sequences
"
,
"Error"
,
err
)
log
.
Error
(
"GetBlock
BySeq
"
,
"Error"
,
err
)
return
nil
,
err
}
msg
,
err
:=
q
.
query
(
blockchainKey
,
types
.
EventGetBlock
Sequences
,
param
)
msg
,
err
:=
q
.
query
(
blockchainKey
,
types
.
EventGetBlock
BySeq
,
param
)
if
err
!=
nil
{
log
.
Error
(
"GetBlock
Sequences
"
,
"Error"
,
err
.
Error
())
log
.
Error
(
"GetBlock
BySeq
"
,
"Error"
,
err
.
Error
())
return
nil
,
err
}
if
reply
,
ok
:=
msg
.
GetData
()
.
(
*
types
.
BlockSeq
uences
);
ok
{
if
reply
,
ok
:=
msg
.
GetData
()
.
(
*
types
.
BlockSeq
);
ok
{
return
reply
,
nil
}
err
=
types
.
ErrTypeAsset
log
.
Error
(
"GetBlockSequences"
,
"Error"
,
err
)
return
nil
,
err
return
nil
,
types
.
ErrTypeAsset
}
// QueryChain query chain
...
...
vendor/github.com/33cn/chain33/client/queueprotocol_test.go
View file @
0cb95366
...
...
@@ -807,6 +807,7 @@ func TestGRPC(t *testing.T) {
testGetAddrOverviewGRPC
(
t
,
&
grpcMock
)
testGetBlockHashGRPC
(
t
,
&
grpcMock
)
testGetSequenceByHashGRPC
(
t
,
&
grpcMock
)
testGetBlockBySeqGRPC
(
t
,
&
grpcMock
)
testGenSeedGRPC
(
t
,
&
grpcMock
)
testGetSeedGRPC
(
t
,
&
grpcMock
)
testSaveSeedGRPC
(
t
,
&
grpcMock
)
...
...
@@ -818,6 +819,7 @@ func TestGRPC(t *testing.T) {
testIsSyncGRPC
(
t
,
&
grpcMock
)
testIsNtpClockSyncGRPC
(
t
,
&
grpcMock
)
testNetInfoGRPC
(
t
,
&
grpcMock
)
}
func
testNetInfoGRPC
(
t
*
testing
.
T
,
rpc
*
mockGRPCSystem
)
{
...
...
@@ -1140,3 +1142,21 @@ func testGetSequenceByHashGRPC(t *testing.T, rpc *mockGRPCSystem) {
t
.
Error
(
"Call GetSequenceByHash Failed."
,
err
)
}
}
func
testGetBlockBySeqGRPC
(
t
*
testing
.
T
,
rpc
*
mockGRPCSystem
)
{
var
res
types
.
BlockSeq
//just for coverage
err
:=
rpc
.
newRpcCtx
(
"GetBlockBySeq"
,
&
types
.
Int64
{
Data
:
1
},
&
res
)
assert
.
Nil
(
t
,
err
)
err
=
rpc
.
newRpcCtx
(
"GetBlockBySeq"
,
&
types
.
Int64
{
Data
:
10
},
&
res
)
assert
.
NotNil
(
t
,
err
)
}
func
TestGetBlockBySeq
(
t
*
testing
.
T
)
{
q
:=
client
.
QueueProtocol
{}
_
,
err
:=
q
.
GetBlockBySeq
(
nil
)
assert
.
NotNil
(
t
,
err
)
}
vendor/github.com/33cn/chain33/client/queueprotocolapi.go
View file @
0cb95366
...
...
@@ -107,10 +107,11 @@ type QueueProtocolAPI interface {
//types.EventGetLastBlockSequence:
GetLastBlockSequence
()
(
*
types
.
Int64
,
error
)
//types.EventGetBlockSequences:
GetBlockSequences
(
param
*
types
.
ReqBlocks
)
(
*
types
.
BlockSequences
,
error
)
//types.EventGetBlockByHashes:
GetBlockByHashes
(
param
*
types
.
ReqHashes
)
(
*
types
.
BlockDetails
,
error
)
//types.EventGetBlockBySeq:
GetBlockBySeq
(
param
*
types
.
Int64
)
(
*
types
.
BlockSeq
,
error
)
//types.EventGetSequenceByHash:
GetSequenceByHash
(
param
*
types
.
ReqHash
)
(
*
types
.
Int64
,
error
)
...
...
vendor/github.com/33cn/chain33/client/rpc_ctx_test.go
View file @
0cb95366
...
...
@@ -321,6 +321,12 @@ func (c *GrpcCtx) Run() (err error) {
*
c
.
Res
.
(
*
types
.
Int64
)
=
*
reply
}
errRet
=
err
case
"GetBlockBySeq"
:
reply
,
err
:=
rpc
.
GetBlockBySeq
(
context
.
Background
(),
c
.
Params
.
(
*
types
.
Int64
))
if
err
==
nil
{
*
c
.
Res
.
(
*
types
.
BlockSeq
)
=
*
reply
}
errRet
=
err
default
:
errRet
=
errors
.
New
(
fmt
.
Sprintf
(
"Unsupport method %v"
,
c
.
Method
))
}
...
...
vendor/github.com/33cn/chain33/rpc/grpchandler.go
View file @
0cb95366
...
...
@@ -344,11 +344,6 @@ func (g *Grpc) GetLastBlockSequence(ctx context.Context, in *pb.ReqNil) (*pb.Int
return
g
.
cli
.
GetLastBlockSequence
()
}
// GetBlockSequences get block sequeces
func
(
g
*
Grpc
)
GetBlockSequences
(
ctx
context
.
Context
,
in
*
pb
.
ReqBlocks
)
(
*
pb
.
BlockSequences
,
error
)
{
return
g
.
cli
.
GetBlockSequences
(
in
)
}
// GetBlockByHashes get block by hashes
func
(
g
*
Grpc
)
GetBlockByHashes
(
ctx
context
.
Context
,
in
*
pb
.
ReqHashes
)
(
*
pb
.
BlockDetails
,
error
)
{
return
g
.
cli
.
GetBlockByHashes
(
in
)
...
...
@@ -359,6 +354,11 @@ func (g *Grpc) GetSequenceByHash(ctx context.Context, in *pb.ReqHash) (*pb.Int64
return
g
.
cli
.
GetSequenceByHash
(
in
)
}
// GetBlockBySeq get block with hash by seq
func
(
g
*
Grpc
)
GetBlockBySeq
(
ctx
context
.
Context
,
in
*
pb
.
Int64
)
(
*
pb
.
BlockSeq
,
error
)
{
return
g
.
cli
.
GetBlockBySeq
(
in
)
}
// SignRawTx signature rawtransaction
func
(
g
*
Grpc
)
SignRawTx
(
ctx
context
.
Context
,
in
*
pb
.
ReqSignRawTx
)
(
*
pb
.
ReplySignRawTx
,
error
)
{
return
g
.
cli
.
SignRawTx
(
in
)
...
...
@@ -372,3 +372,8 @@ func (g *Grpc) QueryRandNum(ctx context.Context, in *pb.ReqRandHash) (*pb.ReplyH
}
return
reply
.
(
*
pb
.
ReplyHash
),
nil
}
// GetFork get fork height by fork key
func
(
g
*
Grpc
)
GetFork
(
ctx
context
.
Context
,
in
*
pb
.
ReqKey
)
(
*
pb
.
Int64
,
error
)
{
return
&
pb
.
Int64
{
Data
:
pb
.
GetFork
(
string
(
in
.
Key
))},
nil
}
vendor/github.com/33cn/chain33/rpc/jrpchandler.go
View file @
0cb95366
...
...
@@ -1051,22 +1051,6 @@ func (c *Chain33) GetLastBlockSequence(in *types.ReqNil, result *interface{}) er
return
nil
}
// GetBlockSequences get the block loading sequence number information for the specified interval
func
(
c
*
Chain33
)
GetBlockSequences
(
in
rpctypes
.
BlockParam
,
result
*
interface
{})
error
{
resp
,
err
:=
c
.
cli
.
GetBlockSequences
(
&
types
.
ReqBlocks
{
Start
:
in
.
Start
,
End
:
in
.
End
,
IsDetail
:
in
.
Isdetail
,
Pid
:
[]
string
{
""
}})
if
err
!=
nil
{
return
err
}
var
BlkSeqs
rpctypes
.
ReplyBlkSeqs
items
:=
resp
.
GetItems
()
for
_
,
item
:=
range
items
{
BlkSeqs
.
BlkSeqInfos
=
append
(
BlkSeqs
.
BlkSeqInfos
,
&
rpctypes
.
ReplyBlkSeq
{
Hash
:
common
.
ToHex
(
item
.
GetHash
()),
Type
:
item
.
GetType
()})
}
*
result
=
&
BlkSeqs
return
nil
}
// GetBlockByHashes get block information by hashes
func
(
c
*
Chain33
)
GetBlockByHashes
(
in
rpctypes
.
ReqHashes
,
result
*
interface
{})
error
{
log
.
Warn
(
"GetBlockByHashes"
,
"hashes"
,
in
)
...
...
vendor/github.com/33cn/chain33/rpc/jrpchandler_test.go
View file @
0cb95366
...
...
@@ -1214,26 +1214,6 @@ func TestChain33_GetLastBlockSequence(t *testing.T) {
assert
.
Equal
(
t
,
int64
(
1
),
result2
)
}
func
TestChain33_GetBlockSequences
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newTestChain33
(
api
)
var
result
interface
{}
api
.
On
(
"GetBlockSequences"
,
mock
.
Anything
)
.
Return
(
nil
,
types
.
ErrInvalidParam
)
err
:=
client
.
GetBlockSequences
(
rpctypes
.
BlockParam
{},
&
result
)
assert
.
NotNil
(
t
,
err
)
api
=
new
(
mocks
.
QueueProtocolAPI
)
client
=
newTestChain33
(
api
)
var
result2
interface
{}
blocks
:=
types
.
BlockSequences
{}
blocks
.
Items
=
make
([]
*
types
.
BlockSequence
,
0
)
blocks
.
Items
=
append
(
blocks
.
Items
,
&
types
.
BlockSequence
{
Hash
:
[]
byte
(
"h1"
),
Type
:
1
})
api
.
On
(
"GetBlockSequences"
,
mock
.
Anything
)
.
Return
(
&
blocks
,
nil
)
err
=
client
.
GetBlockSequences
(
rpctypes
.
BlockParam
{},
&
result2
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
len
(
result2
.
(
*
rpctypes
.
ReplyBlkSeqs
)
.
BlkSeqInfos
))
}
func
TestChain33_GetBlockByHashes
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newTestChain33
(
api
)
...
...
vendor/github.com/33cn/chain33/rpc/server_test.go
View file @
0cb95366
...
...
@@ -175,6 +175,15 @@ func TestGrpc_Call(t *testing.T) {
assert
.
Equal
(
t
,
ret
.
IsOk
,
result
.
IsOk
)
assert
.
Equal
(
t
,
ret
.
Msg
,
result
.
Msg
)
rst
,
err
:=
client
.
GetFork
(
ctx
,
&
types
.
ReqKey
{
Key
:
[]
byte
(
"ForkBlockHash"
)})
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
1
),
rst
.
Data
)
api
.
On
(
"GetBlockBySeq"
,
mock
.
Anything
)
.
Return
(
&
types
.
BlockSeq
{},
nil
)
blockSeq
,
err
:=
client
.
GetBlockBySeq
(
ctx
,
&
types
.
Int64
{
Data
:
1
})
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
&
types
.
BlockSeq
{},
blockSeq
)
server
.
Close
()
mock
.
AssertExpectationsForObjects
(
t
,
api
)
}
vendor/github.com/33cn/chain33/types/event.go
View file @
0cb95366
...
...
@@ -138,6 +138,7 @@ const (
EventStoreListReply
=
131
EventListBlockSeqCB
=
132
EventGetSeqCBLastNum
=
133
EventGetBlockBySeq
=
134
//exec
EventBlockChainQuery
=
212
...
...
@@ -276,4 +277,6 @@ var eventName = map[int]string{
// Token
EventBlockChainQuery
:
"EventBlockChainQuery"
,
EventConsensusQuery
:
"EventConsensusQuery"
,
EventGetBlockBySeq
:
"EventGetBlockBySeq"
,
}
vendor/github.com/33cn/chain33/types/mocks/chain33client.go
View file @
0cb95366
...
...
@@ -402,6 +402,36 @@ func (_m *Chain33Client) GetBlockByHashes(ctx context.Context, in *types.ReqHash
return
r0
,
r1
}
// GetBlockBySeq provides a mock function with given fields: ctx, in, opts
func
(
_m
*
Chain33Client
)
GetBlockBySeq
(
ctx
context
.
Context
,
in
*
types
.
Int64
,
opts
...
grpc
.
CallOption
)
(
*
types
.
BlockSeq
,
error
)
{
_va
:=
make
([]
interface
{},
len
(
opts
))
for
_i
:=
range
opts
{
_va
[
_i
]
=
opts
[
_i
]
}
var
_ca
[]
interface
{}
_ca
=
append
(
_ca
,
ctx
,
in
)
_ca
=
append
(
_ca
,
_va
...
)
ret
:=
_m
.
Called
(
_ca
...
)
var
r0
*
types
.
BlockSeq
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
Int64
,
...
grpc
.
CallOption
)
*
types
.
BlockSeq
);
ok
{
r0
=
rf
(
ctx
,
in
,
opts
...
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
BlockSeq
)
}
}
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
context
.
Context
,
*
types
.
Int64
,
...
grpc
.
CallOption
)
error
);
ok
{
r1
=
rf
(
ctx
,
in
,
opts
...
)
}
else
{
r1
=
ret
.
Error
(
1
)
}
return
r0
,
r1
}
// GetBlockHash provides a mock function with given fields: ctx, in, opts
func
(
_m
*
Chain33Client
)
GetBlockHash
(
ctx
context
.
Context
,
in
*
types
.
ReqInt
,
opts
...
grpc
.
CallOption
)
(
*
types
.
ReplyHash
,
error
)
{
_va
:=
make
([]
interface
{},
len
(
opts
))
...
...
@@ -462,8 +492,8 @@ func (_m *Chain33Client) GetBlockOverview(ctx context.Context, in *types.ReqHash
return
r0
,
r1
}
// GetBlock
Sequence
s provides a mock function with given fields: ctx, in, opts
func
(
_m
*
Chain33Client
)
GetBlock
Sequences
(
ctx
context
.
Context
,
in
*
types
.
ReqBlocks
,
opts
...
grpc
.
CallOption
)
(
*
types
.
BlockSequences
,
error
)
{
// GetBlocks provides a mock function with given fields: ctx, in, opts
func
(
_m
*
Chain33Client
)
GetBlock
s
(
ctx
context
.
Context
,
in
*
types
.
ReqBlocks
,
opts
...
grpc
.
CallOption
)
(
*
types
.
Reply
,
error
)
{
_va
:=
make
([]
interface
{},
len
(
opts
))
for
_i
:=
range
opts
{
_va
[
_i
]
=
opts
[
_i
]
...
...
@@ -473,12 +503,12 @@ func (_m *Chain33Client) GetBlockSequences(ctx context.Context, in *types.ReqBlo
_ca
=
append
(
_ca
,
_va
...
)
ret
:=
_m
.
Called
(
_ca
...
)
var
r0
*
types
.
BlockSequences
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
ReqBlocks
,
...
grpc
.
CallOption
)
*
types
.
BlockSequences
);
ok
{
var
r0
*
types
.
Reply
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
ReqBlocks
,
...
grpc
.
CallOption
)
*
types
.
Reply
);
ok
{
r0
=
rf
(
ctx
,
in
,
opts
...
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
BlockSequences
)
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Reply
)
}
}
...
...
@@ -492,8 +522,8 @@ func (_m *Chain33Client) GetBlockSequences(ctx context.Context, in *types.ReqBlo
return
r0
,
r1
}
// Get
Blocks
provides a mock function with given fields: ctx, in, opts
func
(
_m
*
Chain33Client
)
Get
Blocks
(
ctx
context
.
Context
,
in
*
types
.
ReqBlocks
,
opts
...
grpc
.
CallOption
)
(
*
types
.
Reply
,
error
)
{
// Get
FatalFailure
provides a mock function with given fields: ctx, in, opts
func
(
_m
*
Chain33Client
)
Get
FatalFailure
(
ctx
context
.
Context
,
in
*
types
.
ReqNil
,
opts
...
grpc
.
CallOption
)
(
*
types
.
Int32
,
error
)
{
_va
:=
make
([]
interface
{},
len
(
opts
))
for
_i
:=
range
opts
{
_va
[
_i
]
=
opts
[
_i
]
...
...
@@ -503,17 +533,17 @@ func (_m *Chain33Client) GetBlocks(ctx context.Context, in *types.ReqBlocks, opt
_ca
=
append
(
_ca
,
_va
...
)
ret
:=
_m
.
Called
(
_ca
...
)
var
r0
*
types
.
Reply
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
Req
Blocks
,
...
grpc
.
CallOption
)
*
types
.
Reply
);
ok
{
var
r0
*
types
.
Int32
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
Req
Nil
,
...
grpc
.
CallOption
)
*
types
.
Int32
);
ok
{
r0
=
rf
(
ctx
,
in
,
opts
...
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Reply
)
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Int32
)
}
}
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
context
.
Context
,
*
types
.
Req
Blocks
,
...
grpc
.
CallOption
)
error
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
context
.
Context
,
*
types
.
Req
Nil
,
...
grpc
.
CallOption
)
error
);
ok
{
r1
=
rf
(
ctx
,
in
,
opts
...
)
}
else
{
r1
=
ret
.
Error
(
1
)
...
...
@@ -522,8 +552,8 @@ func (_m *Chain33Client) GetBlocks(ctx context.Context, in *types.ReqBlocks, opt
return
r0
,
r1
}
// GetF
atalFailure
provides a mock function with given fields: ctx, in, opts
func
(
_m
*
Chain33Client
)
GetF
atalFailure
(
ctx
context
.
Context
,
in
*
types
.
ReqNil
,
opts
...
grpc
.
CallOption
)
(
*
types
.
Int32
,
error
)
{
// GetF
ork
provides a mock function with given fields: ctx, in, opts
func
(
_m
*
Chain33Client
)
GetF
ork
(
ctx
context
.
Context
,
in
*
types
.
ReqKey
,
opts
...
grpc
.
CallOption
)
(
*
types
.
Int64
,
error
)
{
_va
:=
make
([]
interface
{},
len
(
opts
))
for
_i
:=
range
opts
{
_va
[
_i
]
=
opts
[
_i
]
...
...
@@ -533,17 +563,17 @@ func (_m *Chain33Client) GetFatalFailure(ctx context.Context, in *types.ReqNil,
_ca
=
append
(
_ca
,
_va
...
)
ret
:=
_m
.
Called
(
_ca
...
)
var
r0
*
types
.
Int
32
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
Req
Nil
,
...
grpc
.
CallOption
)
*
types
.
Int32
);
ok
{
var
r0
*
types
.
Int
64
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
Req
Key
,
...
grpc
.
CallOption
)
*
types
.
Int64
);
ok
{
r0
=
rf
(
ctx
,
in
,
opts
...
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Int
32
)
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Int
64
)
}
}
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
context
.
Context
,
*
types
.
Req
Nil
,
...
grpc
.
CallOption
)
error
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
context
.
Context
,
*
types
.
Req
Key
,
...
grpc
.
CallOption
)
error
);
ok
{
r1
=
rf
(
ctx
,
in
,
opts
...
)
}
else
{
r1
=
ret
.
Error
(
1
)
...
...
vendor/github.com/33cn/chain33/types/proto/common.proto
View file @
0cb95366
vendor/github.com/33cn/chain33/types/proto/rpc.proto
View file @
0cb95366
...
...
@@ -122,14 +122,15 @@ service chain33 {
rpc
GetFatalFailure
(
types.ReqNil
)
returns
(
Int32
)
{}
rpc
GetLastBlockSequence
(
ReqNil
)
returns
(
Int64
)
{}
//获取指定区间的block加载序列号信息
rpc
GetBlockSequences
(
ReqBlocks
)
returns
(
BlockSequences
)
{}
// get add block's sequence by hash
rpc
GetSequenceByHash
(
ReqHash
)
returns
(
Int64
)
{}
//通过block hash 获取对应的blocks信息
rpc
GetBlockByHashes
(
ReqHashes
)
returns
(
BlockDetails
)
{}
//通过block seq 获取对应的blocks hash 信息
rpc
GetBlockBySeq
(
Int64
)
returns
(
BlockSeq
)
{}
//关闭chain33
rpc
CloseQueue
(
ReqNil
)
returns
(
Reply
)
{}
...
...
@@ -142,4 +143,7 @@ service chain33 {
// 获取随机HASH
rpc
QueryRandNum
(
ReqRandHash
)
returns
(
ReplyHash
)
{}
// 获取是否达到fork高度
rpc
GetFork
(
ReqKey
)
returns
(
Int64
)
{}
}
vendor/github.com/33cn/chain33/types/rpc.pb.go
View file @
0cb95366
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