@@ -192,6 +192,41 @@ pub struct MockIbcStore {
192
192
pub packet_receipt : PortChannelIdMap < BTreeMap < Sequence , Receipt > > ,
193
193
}
194
194
195
+ /// Config builder for MockContext.
196
+ #[ derive( Debug , TypedBuilder ) ]
197
+ #[ builder( build_method( into = MockContext ) ) ]
198
+ pub struct MockContextConfig {
199
+ #[ builder( default = HostType :: Mock ) ]
200
+ host_type : HostType ,
201
+
202
+ host_id : ChainId ,
203
+
204
+ #[ builder( default = Duration :: from_secs( DEFAULT_BLOCK_TIME_SECS ) ) ]
205
+ block_time : Duration ,
206
+
207
+ #[ builder( default = 5 ) ]
208
+ max_history_size : usize ,
209
+
210
+ latest_height : Height ,
211
+
212
+ #[ builder( default = Timestamp :: now( ) ) ]
213
+ latest_timestamp : Timestamp ,
214
+ }
215
+
216
+ /// Config builder for MockClientConfig.
217
+ #[ derive( Debug , TypedBuilder ) ]
218
+ pub struct MockClientConfig {
219
+ client_chain_id : ChainId ,
220
+ client_id : ClientId ,
221
+ #[ builder( default = mock_client_type( ) ) ]
222
+ client_type : ClientType ,
223
+ client_state_height : Height ,
224
+ #[ builder( default ) ]
225
+ consensus_state_heights : Vec < Height > ,
226
+ #[ builder( default = Timestamp :: now( ) ) ]
227
+ latest_timestamp : Timestamp ,
228
+ }
229
+
195
230
/// A context implementing the dependencies necessary for testing any IBC module.
196
231
#[ derive( Debug ) ]
197
232
pub struct MockContext {
@@ -219,24 +254,40 @@ pub struct MockContext {
219
254
pub logs : Vec < String > ,
220
255
}
221
256
222
- # [ derive ( Debug , TypedBuilder ) ]
223
- # [ builder ( build_method ( into = MockContext ) ) ]
224
- pub struct MockContextConfig {
225
- # [ builder ( default = HostType :: Mock ) ]
226
- host_type : HostType ,
227
-
228
- host_id : ChainId ,
229
-
230
- # [ builder ( default = Duration :: from_secs ( DEFAULT_BLOCK_TIME_SECS ) ) ]
231
- block_time : Duration ,
232
-
233
- # [ builder ( default = 5 ) ]
234
- max_history_size : usize ,
257
+ /// Returns a MockContext with bare minimum initialization: no clients, no connections and no channels are
258
+ /// present, and the chain has Height(5). This should be used sparingly, mostly for testing the
259
+ /// creation of new domain objects.
260
+ impl Default for MockContext {
261
+ fn default ( ) -> Self {
262
+ Self :: new (
263
+ ChainId :: new ( "mockgaia" , 0 ) . expect ( "Never fails" ) ,
264
+ HostType :: Mock ,
265
+ 5 ,
266
+ Height :: new ( 0 , 5 ) . expect ( "Never fails" ) ,
267
+ )
268
+ }
269
+ }
235
270
236
- latest_height : Height ,
271
+ /// A manual clone impl is provided because the tests are oblivious to the fact that the `ibc_store`
272
+ /// is a shared ptr.
273
+ impl Clone for MockContext {
274
+ fn clone ( & self ) -> Self {
275
+ let ibc_store = {
276
+ let ibc_store = self . ibc_store . lock ( ) . clone ( ) ;
277
+ Arc :: new ( Mutex :: new ( ibc_store) )
278
+ } ;
237
279
238
- #[ builder( default = Timestamp :: now( ) ) ]
239
- latest_timestamp : Timestamp ,
280
+ Self {
281
+ host_chain_type : self . host_chain_type ,
282
+ host_chain_id : self . host_chain_id . clone ( ) ,
283
+ max_history_size : self . max_history_size ,
284
+ history : self . history . clone ( ) ,
285
+ block_time : self . block_time ,
286
+ ibc_store,
287
+ events : self . events . clone ( ) ,
288
+ logs : self . logs . clone ( ) ,
289
+ }
290
+ }
240
291
}
241
292
242
293
impl From < MockContextConfig > for MockContext {
@@ -300,55 +351,6 @@ impl From<MockContextConfig> for MockContext {
300
351
}
301
352
}
302
353
303
- #[ derive( Debug , TypedBuilder ) ]
304
- pub struct MockClientConfig {
305
- client_chain_id : ChainId ,
306
- client_id : ClientId ,
307
- #[ builder( default = mock_client_type( ) ) ]
308
- client_type : ClientType ,
309
- client_state_height : Height ,
310
- #[ builder( default ) ]
311
- consensus_state_heights : Vec < Height > ,
312
- #[ builder( default = Timestamp :: now( ) ) ]
313
- latest_timestamp : Timestamp ,
314
- }
315
-
316
- /// Returns a MockContext with bare minimum initialization: no clients, no connections and no channels are
317
- /// present, and the chain has Height(5). This should be used sparingly, mostly for testing the
318
- /// creation of new domain objects.
319
- impl Default for MockContext {
320
- fn default ( ) -> Self {
321
- Self :: new (
322
- ChainId :: new ( "mockgaia" , 0 ) . expect ( "Never fails" ) ,
323
- HostType :: Mock ,
324
- 5 ,
325
- Height :: new ( 0 , 5 ) . expect ( "Never fails" ) ,
326
- )
327
- }
328
- }
329
-
330
- /// A manual clone impl is provided because the tests are oblivious to the fact that the `ibc_store`
331
- /// is a shared ptr.
332
- impl Clone for MockContext {
333
- fn clone ( & self ) -> Self {
334
- let ibc_store = {
335
- let ibc_store = self . ibc_store . lock ( ) . clone ( ) ;
336
- Arc :: new ( Mutex :: new ( ibc_store) )
337
- } ;
338
-
339
- Self {
340
- host_chain_type : self . host_chain_type ,
341
- host_chain_id : self . host_chain_id . clone ( ) ,
342
- max_history_size : self . max_history_size ,
343
- history : self . history . clone ( ) ,
344
- block_time : self . block_time ,
345
- ibc_store,
346
- events : self . events . clone ( ) ,
347
- logs : self . logs . clone ( ) ,
348
- }
349
- }
350
- }
351
-
352
354
/// Implementation of internal interface for use in testing. The methods in this interface should
353
355
/// _not_ be accessible to any Ics handler.
354
356
impl MockContext {
0 commit comments