@@ -35,57 +35,67 @@ var _ tmrpcclient.Client = &mocks.Client{}
3535func RegisterTxSearch (client * mocks.Client , query string , txBz []byte ) {
3636 resulTxs := []* tmrpctypes.ResultTx {{Tx : txBz }}
3737 client .On ("TxSearch" , rpc .ContextWithHeight (1 ), query , false , (* int )(nil ), (* int )(nil ), "" ).
38- Return (& tmrpctypes.ResultTxSearch {Txs : resulTxs , TotalCount : 1 }, nil )
38+ Return (& tmrpctypes.ResultTxSearch {Txs : resulTxs , TotalCount : 1 }, nil ).
39+ Maybe ()
3940}
4041
4142func RegisterTxSearchEmpty (client * mocks.Client , query string ) {
4243 client .On ("TxSearch" , rpc .ContextWithHeight (1 ), query , false , (* int )(nil ), (* int )(nil ), "" ).
43- Return (& tmrpctypes.ResultTxSearch {}, nil )
44+ Return (& tmrpctypes.ResultTxSearch {}, nil ).
45+ Maybe ()
4446}
4547
4648func RegisterTxSearchError (client * mocks.Client , query string ) {
4749 client .On ("TxSearch" , rpc .ContextWithHeight (1 ), query , false , (* int )(nil ), (* int )(nil ), "" ).
48- Return (nil , errortypes .ErrInvalidRequest )
50+ Return (nil , errortypes .ErrInvalidRequest ).
51+ Maybe ()
4952}
5053
5154// Broadcast Tx
5255func RegisterBroadcastTx (client * mocks.Client , tx types.Tx ) {
5356 client .On ("BroadcastTxSync" , context .Background (), tx ).
54- Return (& tmrpctypes.ResultBroadcastTx {}, nil )
57+ Return (& tmrpctypes.ResultBroadcastTx {}, nil ).
58+ Maybe ()
5559}
5660
5761func RegisterBroadcastTxError (client * mocks.Client , tx types.Tx ) {
5862 client .On ("BroadcastTxSync" , context .Background (), tx ).
59- Return (nil , errortypes .ErrInvalidRequest )
63+ Return (nil , errortypes .ErrInvalidRequest ).
64+ Maybe ()
6065}
6166
6267// Unconfirmed Transactions
6368func RegisterUnconfirmedTxs (client * mocks.Client , limit * int , txs []types.Tx ) {
6469 client .On ("UnconfirmedTxs" , rpc .ContextWithHeight (1 ), limit ).
65- Return (& tmrpctypes.ResultUnconfirmedTxs {Txs : txs }, nil )
70+ Return (& tmrpctypes.ResultUnconfirmedTxs {Txs : txs }, nil ).
71+ Maybe ()
6672}
6773
6874func RegisterUnconfirmedTxsEmpty (client * mocks.Client , limit * int ) {
6975 client .On ("UnconfirmedTxs" , rpc .ContextWithHeight (1 ), limit ).
7076 Return (& tmrpctypes.ResultUnconfirmedTxs {
7177 Txs : make ([]types.Tx , 2 ),
72- }, nil )
78+ }, nil ).
79+ Maybe ()
7380}
7481
7582func RegisterUnconfirmedTxsError (client * mocks.Client , limit * int ) {
7683 client .On ("UnconfirmedTxs" , rpc .ContextWithHeight (1 ), limit ).
77- Return (nil , errortypes .ErrInvalidRequest )
84+ Return (nil , errortypes .ErrInvalidRequest ).
85+ Maybe ()
7886}
7987
8088// Status
8189func RegisterStatus (client * mocks.Client ) {
8290 client .On ("Status" , rpc .ContextWithHeight (1 )).
83- Return (& tmrpctypes.ResultStatus {}, nil )
91+ Return (& tmrpctypes.ResultStatus {}, nil ).
92+ Maybe ()
8493}
8594
8695func RegisterStatusError (client * mocks.Client ) {
8796 client .On ("Status" , rpc .ContextWithHeight (1 )).
88- Return (nil , errortypes .ErrInvalidRequest )
97+ Return (nil , errortypes .ErrInvalidRequest ).
98+ Maybe ()
8999}
90100
91101// Block
@@ -97,7 +107,8 @@ func RegisterBlockMultipleTxs(
97107 block := types .MakeBlock (height , txs , nil , nil )
98108 block .ChainID = ChainID
99109 resBlock := & tmrpctypes.ResultBlock {Block : block }
100- client .On ("Block" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).Return (resBlock , nil )
110+ client .On ("Block" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).Return (resBlock , nil ).
111+ Maybe ()
101112 return resBlock , nil
102113}
103114
@@ -111,22 +122,25 @@ func RegisterBlock(
111122 emptyBlock := types .MakeBlock (height , []types.Tx {}, nil , nil )
112123 emptyBlock .ChainID = ChainID
113124 resBlock := & tmrpctypes.ResultBlock {Block : emptyBlock }
114- client .On ("Block" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).Return (resBlock , nil )
125+ client .On ("Block" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).Return (resBlock , nil ).
126+ Maybe ()
115127 return resBlock , nil
116128 }
117129
118130 // with tx
119131 block := types .MakeBlock (height , []types.Tx {tx }, nil , nil )
120132 block .ChainID = ChainID
121133 resBlock := & tmrpctypes.ResultBlock {Block : block }
122- client .On ("Block" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).Return (resBlock , nil )
134+ client .On ("Block" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).Return (resBlock , nil ).
135+ Maybe ()
123136 return resBlock , nil
124137}
125138
126139// Block returns error
127140func RegisterBlockError (client * mocks.Client , height int64 ) {
128141 client .On ("Block" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).
129- Return (nil , errortypes .ErrInvalidRequest )
142+ Return (nil , errortypes .ErrInvalidRequest ).
143+ Maybe ()
130144}
131145
132146// Block not found
@@ -135,7 +149,8 @@ func RegisterBlockNotFound(
135149 height int64 ,
136150) (* tmrpctypes.ResultBlock , error ) {
137151 client .On ("Block" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).
138- Return (& tmrpctypes.ResultBlock {Block : nil }, nil )
152+ Return (& tmrpctypes.ResultBlock {Block : nil }, nil ).
153+ Maybe ()
139154
140155 return & tmrpctypes.ResultBlock {Block : nil }, nil
141156}
@@ -145,7 +160,8 @@ func RegisterBlockPanic(client *mocks.Client, height int64) {
145160 client .On ("Block" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).
146161 Return (func (context.Context , * int64 ) * tmrpctypes.ResultBlock {
147162 panic ("Block call panic" )
148- }, nil )
163+ }, nil ).
164+ Maybe ()
149165}
150166
151167func TestRegisterBlock (t * testing.T ) {
@@ -166,12 +182,14 @@ func TestRegisterBlock(t *testing.T) {
166182func RegisterConsensusParams (client * mocks.Client , height int64 ) {
167183 consensusParams := types .DefaultConsensusParams ()
168184 client .On ("ConsensusParams" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).
169- Return (& tmrpctypes.ResultConsensusParams {ConsensusParams : * consensusParams }, nil )
185+ Return (& tmrpctypes.ResultConsensusParams {ConsensusParams : * consensusParams }, nil ).
186+ Maybe ()
170187}
171188
172189func RegisterConsensusParamsError (client * mocks.Client , height int64 ) {
173190 client .On ("ConsensusParams" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).
174- Return (nil , errortypes .ErrInvalidRequest )
191+ Return (nil , errortypes .ErrInvalidRequest ).
192+ Maybe ()
175193}
176194
177195func TestRegisterConsensusParams (t * testing.T ) {
@@ -209,7 +227,8 @@ func RegisterBlockResultsWithEventLog(client *mocks.Client, height int64) (*tmrp
209227 }
210228
211229 client .On ("BlockResults" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).
212- Return (res , nil )
230+ Return (res , nil ).
231+ Maybe ()
213232 return res , nil
214233}
215234
@@ -223,13 +242,15 @@ func RegisterBlockResults(
223242 }
224243
225244 client .On ("BlockResults" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).
226- Return (res , nil )
245+ Return (res , nil ).
246+ Maybe ()
227247 return res , nil
228248}
229249
230250func RegisterBlockResultsError (client * mocks.Client , height int64 ) {
231251 client .On ("BlockResults" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).
232- Return (nil , errortypes .ErrInvalidRequest )
252+ Return (nil , errortypes .ErrInvalidRequest ).
253+ Maybe ()
233254}
234255
235256func TestRegisterBlockResults (t * testing.T ) {
@@ -256,18 +277,21 @@ func RegisterBlockByHash(
256277 resBlock := & tmrpctypes.ResultBlock {Block : block }
257278
258279 client .On ("BlockByHash" , rpc .ContextWithHeight (1 ), []byte {0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 }).
259- Return (resBlock , nil )
280+ Return (resBlock , nil ).
281+ Maybe ()
260282 return resBlock , nil
261283}
262284
263285func RegisterBlockByHashError (client * mocks.Client , hash common.Hash , tx []byte ) {
264286 client .On ("BlockByHash" , rpc .ContextWithHeight (1 ), []byte {0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 }).
265- Return (nil , errortypes .ErrInvalidRequest )
287+ Return (nil , errortypes .ErrInvalidRequest ).
288+ Maybe ()
266289}
267290
268291func RegisterBlockByHashNotFound (client * mocks.Client , hash common.Hash , tx []byte ) {
269292 client .On ("BlockByHash" , rpc .ContextWithHeight (1 ), []byte {0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 }).
270- Return (nil , nil )
293+ Return (nil , nil ).
294+ Maybe ()
271295}
272296
273297// HeaderByHash
@@ -280,36 +304,47 @@ func RegisterHeaderByHash(
280304 resHeader := & tmrpctypes.ResultHeader {Header : & block .Header }
281305
282306 client .On ("HeaderByHash" , rpc .ContextWithHeight (1 ), bytes .HexBytes (hash .Bytes ())).
283- Return (resHeader , nil )
307+ Return (resHeader , nil ).
308+ Maybe ()
284309 return resHeader , nil
285310}
286311
287312func RegisterHeaderByHashError (client * mocks.Client , hash common.Hash , tx []byte ) {
288313 client .On ("HeaderByHash" , rpc .ContextWithHeight (1 ), bytes .HexBytes (hash .Bytes ())).
289- Return (nil , errortypes .ErrInvalidRequest )
314+ Return (nil , errortypes .ErrInvalidRequest ).
315+ Maybe ()
290316}
291317
292318func RegisterHeaderByHashNotFound (client * mocks.Client , hash common.Hash , tx []byte ) {
293319 client .On ("HeaderByHash" , rpc .ContextWithHeight (1 ), bytes .HexBytes (hash .Bytes ())).
294- Return (& tmrpctypes.ResultHeader {Header : nil }, nil )
320+ Return (& tmrpctypes.ResultHeader {Header : nil }, nil ).
321+ Maybe ()
322+ }
323+
324+ func RegisterHeaderByHashAny (client * mocks.Client ) {
325+ client .On ("HeaderByHash" , mock .Anything , mock .Anything ).
326+ Return (& tmrpctypes.ResultHeader {Header : & types.Header {Height : 1 }}, nil ).Maybe ()
295327}
296328
297329// Header
298330func RegisterHeader (client * mocks.Client , height * int64 , tx []byte ) (* tmrpctypes.ResultHeader , error ) {
299331 block := types .MakeBlock (* height , []types.Tx {tx }, nil , nil )
300332 resHeader := & tmrpctypes.ResultHeader {Header : & block .Header }
301- client .On ("Header" , rpc .ContextWithHeight (* height ), height ).Return (resHeader , nil )
333+ client .On ("Header" , rpc .ContextWithHeight (* height ), height ).Return (resHeader , nil ).
334+ Maybe ()
302335 return resHeader , nil
303336}
304337
305338func RegisterHeaderError (client * mocks.Client , height * int64 ) {
306- client .On ("Header" , rpc .ContextWithHeight (* height ), height ).Return (nil , errortypes .ErrInvalidRequest )
339+ client .On ("Header" , rpc .ContextWithHeight (* height ), height ).Return (nil , errortypes .ErrInvalidRequest ).
340+ Maybe ()
307341}
308342
309343// Header not found
310344func RegisterHeaderNotFound (client * mocks.Client , height int64 ) {
311345 client .On ("Header" , rpc .ContextWithHeight (height ), mock .AnythingOfType ("*int64" )).
312- Return (& tmrpctypes.ResultHeader {Header : nil }, nil )
346+ Return (& tmrpctypes.ResultHeader {Header : nil }, nil ).
347+ Maybe ()
313348}
314349
315350func RegisterABCIQueryWithOptions (client * mocks.Client , height int64 , path string , data bytes.HexBytes , opts tmrpcclient.ABCIQueryOptions ) {
@@ -319,12 +354,26 @@ func RegisterABCIQueryWithOptions(client *mocks.Client, height int64, path strin
319354 Value : []byte {2 }, // TODO replace with data.Bytes(),
320355 Height : height ,
321356 },
322- }, nil )
357+ }, nil ).
358+ Maybe ()
323359}
324360
325361func RegisterABCIQueryWithOptionsError (clients * mocks.Client , path string , data bytes.HexBytes , opts tmrpcclient.ABCIQueryOptions ) {
326362 clients .On ("ABCIQueryWithOptions" , context .Background (), path , data , opts ).
327- Return (nil , errortypes .ErrInvalidRequest )
363+ Return (nil , errortypes .ErrInvalidRequest ).
364+ Maybe ()
365+ }
366+
367+ func RegisterABCIQueryAny (client * mocks.Client , height int64 ) {
368+ client .On ("ABCIQueryWithOptions" , context .Background (), mock .Anything , mock .Anything , mock .Anything ).
369+ Return (& tmrpctypes.ResultABCIQuery {
370+ Response : abci.ResponseQuery {
371+ Value : []byte {2 }, // TODO replace with data.Bytes(),
372+ Height : height ,
373+ },
374+ }, nil ).
375+ Maybe ()
376+
328377}
329378
330379func RegisterABCIQueryAccount (clients * mocks.Client , data bytes.HexBytes , opts tmrpcclient.ABCIQueryOptions , acc client.Account ) {
@@ -338,5 +387,6 @@ func RegisterABCIQueryAccount(clients *mocks.Client, data bytes.HexBytes, opts t
338387 Value : respBz ,
339388 Height : 1 ,
340389 },
341- }, nil )
390+ }, nil ).
391+ Maybe ()
342392}
0 commit comments