@@ -5,8 +5,10 @@ use basecoin_store::context::ProvableStore;
55use basecoin_store:: impls:: InMemoryStore ;
66use ibc:: core:: channel:: types:: channel:: ChannelEnd ;
77use 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 ;
910use ibc:: core:: client:: context:: { ClientExecutionContext , ClientValidationContext } ;
11+ use ibc:: core:: client:: types:: error:: ClientError ;
1012use ibc:: core:: client:: types:: Height ;
1113use ibc:: core:: connection:: types:: ConnectionEnd ;
1214use ibc:: core:: entrypoint:: { dispatch, execute, validate} ;
@@ -18,8 +20,10 @@ use ibc::core::host::types::path::{
1820 ChannelEndPath , ClientConsensusStatePath , ClientStatePath , CommitmentPath , ConnectionPath ,
1921 SeqAckPath , SeqRecvPath , SeqSendPath ,
2022} ;
21- use ibc:: core:: host:: { ExecutionContext , ValidationContext } ;
23+ use ibc:: core:: host:: ExecutionContext ;
24+ use ibc:: core:: host:: ValidationContext ;
2225use ibc:: primitives:: prelude:: * ;
26+ use ibc:: primitives:: proto:: Any ;
2327use ibc:: primitives:: Timestamp ;
2428
2529use super :: testapp:: ibc:: core:: types:: { LightClientState , MockIbcStore } ;
@@ -34,13 +38,13 @@ use crate::testapp::ibc::core::types::DEFAULT_BLOCK_TIME_SECS;
3438
3539/// A context implementing the dependencies necessary for testing any IBC module.
3640#[ derive( Debug ) ]
37- pub struct StoreGenericTestContext < S , H >
41+ pub struct StoreGenericTestContext < S , H , ACL , ACS >
3842where
3943 S : ProvableStore + Debug ,
4044 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 > > ,
4448{
4549 /// The multi store of the context.
4650 /// This is where the IBC store root is stored at IBC commitment prefix.
@@ -50,16 +54,19 @@ where
5054 pub host : H ,
5155
5256 /// An object that stores all IBC related data.
53- pub ibc_store : MockIbcStore < S , AnyClientState , AnyConsensusState > ,
57+ pub ibc_store : MockIbcStore < S , ACL , ACS > ,
5458
5559 /// A router that can route messages to the appropriate IBC application.
5660 pub ibc_router : MockRouter ,
5761}
5862
5963/// A mock store type using basecoin-storage implementations.
6064pub 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 > ;
6370/// A [`StoreGenericTestContext`] using [`MockStore`] and [`MockHost`].
6471pub type MockContext = TestContext < MockHost > ;
6572/// A [`StoreGenericTestContext`] using [`MockStore`] and [`TendermintHost`].
@@ -68,13 +75,16 @@ pub type TendermintContext = TestContext<TendermintHost>;
6875/// Returns a [`StoreGenericTestContext`] with bare minimum initialization: no clients, no connections, and no channels are
6976/// present, and the chain has Height(5). This should be used sparingly, mostly for testing the
7077/// 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 >
7279where
7380 S : ProvableStore + Debug + Default ,
7481 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 > ,
7888{
7989 fn default ( ) -> Self {
8090 TestContextConfig :: builder ( ) . build ( )
@@ -83,21 +93,24 @@ where
8393
8494/// Implementation of internal interface for use in testing. The methods in this interface should
8595/// _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 >
8797where
8898 S : ProvableStore + Debug ,
8999 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 > ,
93106{
94107 /// 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 > {
96109 & self . ibc_store
97110 }
98111
99112 /// 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 > {
101114 & mut self . ibc_store
102115 }
103116
@@ -178,7 +191,7 @@ where
178191 /// and consensus, and prepares the context for the next block. This includes
179192 /// the latest consensus state and the latest IBC commitment proof.
180193 pub fn begin_block ( & mut self ) {
181- let consensus_state = AnyConsensusState :: from (
194+ let consensus_state = ACS :: from (
182195 self . host
183196 . latest_block ( )
184197 . into_header ( )
@@ -282,7 +295,7 @@ where
282295 }
283296
284297 /// 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 {
286299 let client_state_path = ClientStatePath :: new ( client_id. clone ( ) ) ;
287300 self . ibc_store
288301 . store_client_state ( client_state_path, client_state)
@@ -295,7 +308,7 @@ where
295308 mut self ,
296309 client_id : & ClientId ,
297310 height : Height ,
298- consensus_state : AnyConsensusState ,
311+ consensus_state : ACS ,
299312 ) -> Self {
300313 let consensus_state_path = ClientConsensusStatePath :: new (
301314 client_id. clone ( ) ,
@@ -316,7 +329,7 @@ where
316329 & self ,
317330 mut consensus_heights : Vec < Height > ,
318331 client_params : & H :: LightClientParams ,
319- ) -> LightClientState < H , S > {
332+ ) -> LightClientState < H , S , ACL , ACS > {
320333 let client_height = if let Some ( & height) = consensus_heights. last ( ) {
321334 height
322335 } else {
@@ -344,29 +357,25 @@ where
344357 LightClientState {
345358 client_state,
346359 consensus_states,
347- _store : core:: marker:: PhantomData ,
360+ _phantom : core:: marker:: PhantomData ,
348361 }
349362 }
350363
351364 /// Bootstrap a light client with ClientState and its ConsensusState(s) to this context.
352365 pub fn with_light_client < RH > (
353366 mut self ,
354367 client_id : & ClientId ,
355- light_client : LightClientState < RH , S > ,
368+ light_client : LightClientState < RH , S , ACL , ACS > ,
356369 ) -> Self
357370 where
358371 RH : TestHost ,
359- AnyClientState : From < HostClientState < RH > > ,
360- AnyConsensusState : From < HostConsensusState < RH > > ,
372+ ACL : From < HostClientState < RH > > ,
373+ ACS : From < HostConsensusState < RH > > ,
361374 {
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 ) ) ;
363376
364377 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) ) ;
370379
371380 self . ibc_store
372381 . store_update_meta (
@@ -530,7 +539,7 @@ mod tests {
530539 AnyClientState : From < HostClientState < H > > ,
531540 AnyConsensusState : From < HostConsensusState < H > > ,
532541 HostConsensusState < H > : ConsensusState ,
533- HostClientState < H > : ClientStateValidation < DefaultIbcStore > ,
542+ HostClientState < H > : ClientStateExecution < DefaultIbcStore > ,
534543 {
535544 name : String ,
536545 ctx : TestContext < H > ,
@@ -542,7 +551,7 @@ mod tests {
542551 AnyClientState : From < HostClientState < H > > ,
543552 AnyConsensusState : From < HostConsensusState < H > > ,
544553 HostConsensusState < H > : ConsensusState ,
545- HostClientState < H > : ClientStateValidation < DefaultIbcStore > ,
554+ HostClientState < H > : ClientStateExecution < DefaultIbcStore > ,
546555 {
547556 let cv = 0 ; // The version to use for all chains.
548557
0 commit comments