@@ -5,8 +5,10 @@ use basecoin_store::context::ProvableStore;
5
5
use basecoin_store:: impls:: InMemoryStore ;
6
6
use ibc:: core:: channel:: types:: channel:: ChannelEnd ;
7
7
use ibc:: core:: channel:: types:: commitment:: PacketCommitment ;
8
- use ibc:: core:: client:: context:: client_state:: ClientStateValidation ;
8
+ use ibc:: core:: client:: context:: client_state:: ClientStateExecution ;
9
+ use ibc:: core:: client:: context:: consensus_state:: ConsensusState ;
9
10
use ibc:: core:: client:: context:: { ClientExecutionContext , ClientValidationContext } ;
11
+ use ibc:: core:: client:: types:: error:: ClientError ;
10
12
use ibc:: core:: client:: types:: Height ;
11
13
use ibc:: core:: connection:: types:: ConnectionEnd ;
12
14
use ibc:: core:: entrypoint:: { dispatch, execute, validate} ;
@@ -18,8 +20,10 @@ use ibc::core::host::types::path::{
18
20
ChannelEndPath , ClientConsensusStatePath , ClientStatePath , CommitmentPath , ConnectionPath ,
19
21
SeqAckPath , SeqRecvPath , SeqSendPath ,
20
22
} ;
21
- use ibc:: core:: host:: { ExecutionContext , ValidationContext } ;
23
+ use ibc:: core:: host:: ExecutionContext ;
24
+ use ibc:: core:: host:: ValidationContext ;
22
25
use ibc:: primitives:: prelude:: * ;
26
+ use ibc:: primitives:: proto:: Any ;
23
27
use ibc:: primitives:: Timestamp ;
24
28
25
29
use super :: testapp:: ibc:: core:: types:: { LightClientState , MockIbcStore } ;
@@ -34,13 +38,13 @@ use crate::testapp::ibc::core::types::DEFAULT_BLOCK_TIME_SECS;
34
38
35
39
/// A context implementing the dependencies necessary for testing any IBC module.
36
40
#[ derive( Debug ) ]
37
- pub struct StoreGenericTestContext < S , H >
41
+ pub struct StoreGenericTestContext < S , H , ACL , ACS >
38
42
where
39
43
S : ProvableStore + Debug ,
40
44
H : TestHost ,
41
- AnyClientState : From < HostClientState < H > > ,
42
- AnyConsensusState : From < HostConsensusState < H > > ,
43
- HostClientState < H > : ClientStateValidation < MockIbcStore < S , AnyClientState , AnyConsensusState > > ,
45
+ ACL : From < HostClientState < H > > + ClientStateExecution < MockIbcStore < S , ACL , ACS > > + Clone ,
46
+ ACS : From < HostConsensusState < H > > + ConsensusState + Clone ,
47
+ HostClientState < H > : ClientStateExecution < MockIbcStore < S , ACL , ACS > > ,
44
48
{
45
49
/// The multi store of the context.
46
50
/// This is where the IBC store root is stored at IBC commitment prefix.
@@ -50,16 +54,19 @@ where
50
54
pub host : H ,
51
55
52
56
/// An object that stores all IBC related data.
53
- pub ibc_store : MockIbcStore < S , AnyClientState , AnyConsensusState > ,
57
+ pub ibc_store : MockIbcStore < S , ACL , ACS > ,
54
58
55
59
/// A router that can route messages to the appropriate IBC application.
56
60
pub ibc_router : MockRouter ,
57
61
}
58
62
59
63
/// A mock store type using basecoin-storage implementations.
60
64
pub type MockStore = InMemoryStore ;
61
- /// A [`StoreGenericTestContext`] using [`MockStore`].
62
- pub type TestContext < H > = StoreGenericTestContext < MockStore , H > ;
65
+ /// A [`StoreGenericTestContext`] using [`MockStore`], [`AnyClientState`], and [`AnyConsensusState`].
66
+ pub type TestContext < H > = StoreGenericTestContext < MockStore , H , AnyClientState , AnyConsensusState > ;
67
+ /// A [`LightClientState`] using [`MockStore`], [`AnyClientState`] and [`AnyConsensusState`].
68
+ pub type DefaultLightClientState < H > =
69
+ LightClientState < H , MockStore , AnyClientState , AnyConsensusState > ;
63
70
/// A [`StoreGenericTestContext`] using [`MockStore`] and [`MockHost`].
64
71
pub type MockContext = TestContext < MockHost > ;
65
72
/// A [`StoreGenericTestContext`] using [`MockStore`] and [`TendermintHost`].
@@ -68,13 +75,16 @@ pub type TendermintContext = TestContext<TendermintHost>;
68
75
/// Returns a [`StoreGenericTestContext`] with bare minimum initialization: no clients, no connections, and no channels are
69
76
/// present, and the chain has Height(5). This should be used sparingly, mostly for testing the
70
77
/// creation of new domain objects.
71
- impl < S , H > Default for StoreGenericTestContext < S , H >
78
+ impl < S , H , ACL , ACS > Default for StoreGenericTestContext < S , H , ACL , ACS >
72
79
where
73
80
S : ProvableStore + Debug + Default ,
74
81
H : TestHost ,
75
- AnyClientState : From < HostClientState < H > > ,
76
- AnyConsensusState : From < HostConsensusState < H > > ,
77
- HostClientState < H > : ClientStateValidation < MockIbcStore < S , AnyClientState , AnyConsensusState > > ,
82
+ ACL : From < HostClientState < H > > + ClientStateExecution < MockIbcStore < S , ACL , ACS > > + Clone ,
83
+ ACS : From < HostConsensusState < H > > + ConsensusState + Clone ,
84
+ HostClientState < H > : ClientStateExecution < MockIbcStore < S , ACL , ACS > > ,
85
+ MockIbcStore < S , ACL , ACS > :
86
+ ClientExecutionContext < ClientStateMut = ACL , ConsensusStateRef = ACS > ,
87
+ ClientError : From < <ACL as TryFrom < Any > >:: Error > ,
78
88
{
79
89
fn default ( ) -> Self {
80
90
TestContextConfig :: builder ( ) . build ( )
@@ -83,21 +93,24 @@ where
83
93
84
94
/// Implementation of internal interface for use in testing. The methods in this interface should
85
95
/// _not_ be accessible to any ICS handler.
86
- impl < S , H > StoreGenericTestContext < S , H >
96
+ impl < S , H , ACL , ACS > StoreGenericTestContext < S , H , ACL , ACS >
87
97
where
88
98
S : ProvableStore + Debug ,
89
99
H : TestHost ,
90
- HostClientState < H > : ClientStateValidation < MockIbcStore < S , AnyClientState , AnyConsensusState > > ,
91
- AnyClientState : From < HostClientState < H > > ,
92
- AnyConsensusState : From < HostConsensusState < H > > ,
100
+ ACL : From < HostClientState < H > > + ClientStateExecution < MockIbcStore < S , ACL , ACS > > + Clone ,
101
+ ACS : From < HostConsensusState < H > > + ConsensusState + Clone ,
102
+ HostClientState < H > : ClientStateExecution < MockIbcStore < S , ACL , ACS > > ,
103
+ MockIbcStore < S , ACL , ACS > :
104
+ ClientExecutionContext < ClientStateMut = ACL , ConsensusStateRef = ACS > ,
105
+ ClientError : From < <ACL as TryFrom < Any > >:: Error > ,
93
106
{
94
107
/// Returns an immutable reference to the IBC store.
95
- pub fn ibc_store ( & self ) -> & MockIbcStore < S , AnyClientState , AnyConsensusState > {
108
+ pub fn ibc_store ( & self ) -> & MockIbcStore < S , ACL , ACS > {
96
109
& self . ibc_store
97
110
}
98
111
99
112
/// Returns a mutable reference to the IBC store.
100
- pub fn ibc_store_mut ( & mut self ) -> & mut MockIbcStore < S , AnyClientState , AnyConsensusState > {
113
+ pub fn ibc_store_mut ( & mut self ) -> & mut MockIbcStore < S , ACL , ACS > {
101
114
& mut self . ibc_store
102
115
}
103
116
@@ -178,7 +191,7 @@ where
178
191
/// and consensus, and prepares the context for the next block. This includes
179
192
/// the latest consensus state and the latest IBC commitment proof.
180
193
pub fn begin_block ( & mut self ) {
181
- let consensus_state = AnyConsensusState :: from (
194
+ let consensus_state = ACS :: from (
182
195
self . host
183
196
. latest_block ( )
184
197
. into_header ( )
@@ -282,7 +295,7 @@ where
282
295
}
283
296
284
297
/// Bootstraps the context with a client state and its corresponding [`ClientId`].
285
- pub fn with_client_state ( mut self , client_id : & ClientId , client_state : AnyClientState ) -> Self {
298
+ pub fn with_client_state ( mut self , client_id : & ClientId , client_state : ACL ) -> Self {
286
299
let client_state_path = ClientStatePath :: new ( client_id. clone ( ) ) ;
287
300
self . ibc_store
288
301
. store_client_state ( client_state_path, client_state)
@@ -295,7 +308,7 @@ where
295
308
mut self ,
296
309
client_id : & ClientId ,
297
310
height : Height ,
298
- consensus_state : AnyConsensusState ,
311
+ consensus_state : ACS ,
299
312
) -> Self {
300
313
let consensus_state_path = ClientConsensusStatePath :: new (
301
314
client_id. clone ( ) ,
@@ -316,7 +329,7 @@ where
316
329
& self ,
317
330
mut consensus_heights : Vec < Height > ,
318
331
client_params : & H :: LightClientParams ,
319
- ) -> LightClientState < H , S > {
332
+ ) -> LightClientState < H , S , ACL , ACS > {
320
333
let client_height = if let Some ( & height) = consensus_heights. last ( ) {
321
334
height
322
335
} else {
@@ -344,29 +357,25 @@ where
344
357
LightClientState {
345
358
client_state,
346
359
consensus_states,
347
- _store : core:: marker:: PhantomData ,
360
+ _phantom : core:: marker:: PhantomData ,
348
361
}
349
362
}
350
363
351
364
/// Bootstrap a light client with ClientState and its ConsensusState(s) to this context.
352
365
pub fn with_light_client < RH > (
353
366
mut self ,
354
367
client_id : & ClientId ,
355
- light_client : LightClientState < RH , S > ,
368
+ light_client : LightClientState < RH , S , ACL , ACS > ,
356
369
) -> Self
357
370
where
358
371
RH : TestHost ,
359
- AnyClientState : From < HostClientState < RH > > ,
360
- AnyConsensusState : From < HostConsensusState < RH > > ,
372
+ ACL : From < HostClientState < RH > > ,
373
+ ACS : From < HostConsensusState < RH > > ,
361
374
{
362
- self = self . with_client_state ( client_id, AnyClientState :: from ( light_client. client_state ) ) ;
375
+ self = self . with_client_state ( client_id, ACL :: from ( light_client. client_state ) ) ;
363
376
364
377
for ( height, consensus_state) in light_client. consensus_states {
365
- self = self . with_consensus_state (
366
- client_id,
367
- height,
368
- AnyConsensusState :: from ( consensus_state) ,
369
- ) ;
378
+ self = self . with_consensus_state ( client_id, height, ACS :: from ( consensus_state) ) ;
370
379
371
380
self . ibc_store
372
381
. store_update_meta (
@@ -530,7 +539,7 @@ mod tests {
530
539
AnyClientState : From < HostClientState < H > > ,
531
540
AnyConsensusState : From < HostConsensusState < H > > ,
532
541
HostConsensusState < H > : ConsensusState ,
533
- HostClientState < H > : ClientStateValidation < DefaultIbcStore > ,
542
+ HostClientState < H > : ClientStateExecution < DefaultIbcStore > ,
534
543
{
535
544
name : String ,
536
545
ctx : TestContext < H > ,
@@ -542,7 +551,7 @@ mod tests {
542
551
AnyClientState : From < HostClientState < H > > ,
543
552
AnyConsensusState : From < HostConsensusState < H > > ,
544
553
HostConsensusState < H > : ConsensusState ,
545
- HostClientState < H > : ClientStateValidation < DefaultIbcStore > ,
554
+ HostClientState < H > : ClientStateExecution < DefaultIbcStore > ,
546
555
{
547
556
let cv = 0 ; // The version to use for all chains.
548
557
0 commit comments