pub struct StoreGenericTestContext<S, H>where
S: ProvableStore + Debug,
H: TestHost,
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,{
pub multi_store: S,
pub host: H,
pub ibc_store: MockIbcStore<S>,
pub ibc_router: MockRouter,
}
Expand description
A context implementing the dependencies necessary for testing any IBC module.
Fields§
§multi_store: S
The multi store of the context. This is where the IBC store root is stored at IBC commitment prefix.
host: H
The type of host chain underlying this mock context.
ibc_store: MockIbcStore<S>
An object that stores all IBC related data.
ibc_router: MockRouter
A router that can route messages to the appropriate IBC application.
Implementations§
Source§impl<S, H> StoreGenericTestContext<S, H>where
S: ProvableStore + Debug,
H: TestHost,
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
Implementation of internal interface for use in testing. The methods in this interface should
not be accessible to any ICS handler.
impl<S, H> StoreGenericTestContext<S, H>where
S: ProvableStore + Debug,
H: TestHost,
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
Implementation of internal interface for use in testing. The methods in this interface should not be accessible to any ICS handler.
Sourcepub fn ibc_store(&self) -> &MockIbcStore<S>
pub fn ibc_store(&self) -> &MockIbcStore<S>
Returns an immutable reference to the IBC store.
Sourcepub fn ibc_store_mut(&mut self) -> &mut MockIbcStore<S>
pub fn ibc_store_mut(&mut self) -> &mut MockIbcStore<S>
Returns a mutable reference to the IBC store.
Sourcepub fn ibc_router(&self) -> &MockRouter
pub fn ibc_router(&self) -> &MockRouter
Returns an immutable reference to the IBC router.
Sourcepub fn ibc_router_mut(&mut self) -> &mut MockRouter
pub fn ibc_router_mut(&mut self) -> &mut MockRouter
Returns a mutable reference to the IBC router.
Sourcepub fn host_block(&self, target_height: &Height) -> Option<H::Block>
pub fn host_block(&self, target_height: &Height) -> Option<H::Block>
Returns the block at the given height from the host chain, if exists.
Sourcepub fn query_latest_block(&self) -> Option<H::Block>
pub fn query_latest_block(&self) -> Option<H::Block>
Returns the latest block from the host chain.
Sourcepub fn light_client_latest_height(&self, client_id: &ClientId) -> Height
pub fn light_client_latest_height(&self, client_id: &ClientId) -> Height
Returns the latest height of client state for the given ClientId
.
Sourcepub fn advance_block_up_to_height(self, target_height: Height) -> Self
pub fn advance_block_up_to_height(self, target_height: Height) -> Self
Advances the host chain height to the given target height.
Sourcepub fn advance_genesis_height(
&mut self,
genesis_time: Timestamp,
params: &H::BlockParams,
)
pub fn advance_genesis_height( &mut self, genesis_time: Timestamp, params: &H::BlockParams, )
Advance the first height of the host chain by generating a genesis block.
This method is same as Self::advance_genesis_height
.
But it bootstraps the genesis block by height 1 and genesis_time
.
The method starts and ends with Self::end_block
and Self::begin_block
, just
like the Self::advance_block_height_with_params
, so that it can advance to next height
i.e. height 2 - just by calling Self::advance_block_height_with_params
.
Sourcepub fn begin_block(&mut self)
pub fn begin_block(&mut self)
Begin a new block on the context.
This method commits the required metadata from the last block generation and consensus, and prepares the context for the next block. This includes the latest consensus state and the latest IBC commitment proof.
Sourcepub fn end_block(&mut self)
pub fn end_block(&mut self)
End the current block on the context.
This method commits the state of the IBC store and the host’s multi store.
Sourcepub fn commit_state_to_host(
&mut self,
block_time: Duration,
params: &H::BlockParams,
)
pub fn commit_state_to_host( &mut self, block_time: Duration, params: &H::BlockParams, )
Commit store state to the current block of the host chain by:
- Committing the state to the context’s multi store.
- Generating a new block with the commitment.
- Adding the generated block to the host’s block history.
Sourcepub fn advance_block_height_with_params(
&mut self,
block_time: Duration,
params: &H::BlockParams,
)
pub fn advance_block_height_with_params( &mut self, block_time: Duration, params: &H::BlockParams, )
Advances the host chain height by ending the current block, producing a new block, and beginning the next block.
Sourcepub fn advance_block_height(&mut self)
pub fn advance_block_height(&mut self)
Convenience method to advance the host chain height using default parameters.
Sourcepub fn latest_height(&self) -> Height
pub fn latest_height(&self) -> Height
Returns the latest height of the host chain.
Sourcepub fn latest_timestamp(&self) -> Timestamp
pub fn latest_timestamp(&self) -> Timestamp
Returns the latest timestamp of the host chain.
Sourcepub fn timestamp_at(&self, height: Height) -> Timestamp
pub fn timestamp_at(&self, height: Height) -> Timestamp
Returns the timestamp at the given height.
Sourcepub fn with_client_state(
self,
client_id: &ClientId,
client_state: AnyClientState,
) -> Self
pub fn with_client_state( self, client_id: &ClientId, client_state: AnyClientState, ) -> Self
Bootstraps the context with a client state and its corresponding ClientId
.
Sourcepub fn with_consensus_state(
self,
client_id: &ClientId,
height: Height,
consensus_state: AnyConsensusState,
) -> Self
pub fn with_consensus_state( self, client_id: &ClientId, height: Height, consensus_state: AnyConsensusState, ) -> Self
Sourcepub fn generate_light_client(
&self,
consensus_heights: Vec<Height>,
client_params: &H::LightClientParams,
) -> LightClientState<H>
pub fn generate_light_client( &self, consensus_heights: Vec<Height>, client_params: &H::LightClientParams, ) -> LightClientState<H>
Generates a light client for the host by generating a client state, as well as generating consensus states for each consensus height.
Sourcepub fn with_light_client<RH>(
self,
client_id: &ClientId,
light_client: LightClientState<RH>,
) -> Selfwhere
RH: TestHost,
pub fn with_light_client<RH>(
self,
client_id: &ClientId,
light_client: LightClientState<RH>,
) -> Selfwhere
RH: TestHost,
Bootstrap a light client with ClientState and its ConsensusState(s) to this context.
Sourcepub fn with_connection(
self,
connection_id: ConnectionId,
connection_end: ConnectionEnd,
) -> Self
pub fn with_connection( self, connection_id: ConnectionId, connection_end: ConnectionEnd, ) -> Self
Bootstraps an IBC connection to this context.
This does not bootstrap any light client.
Sourcepub fn with_channel(
self,
port_id: PortId,
chan_id: ChannelId,
channel_end: ChannelEnd,
) -> Self
pub fn with_channel( self, port_id: PortId, chan_id: ChannelId, channel_end: ChannelEnd, ) -> Self
Bootstraps an IBC channel to this context.
This does not bootstrap any corresponding IBC connection or light client.
Sourcepub fn with_send_sequence(
self,
port_id: PortId,
chan_id: ChannelId,
seq_number: Sequence,
) -> Self
pub fn with_send_sequence( self, port_id: PortId, chan_id: ChannelId, seq_number: Sequence, ) -> Self
Bootstraps a send sequence to this context.
This does not bootstrap any corresponding IBC channel, connection or light client.
Sourcepub fn with_recv_sequence(
self,
port_id: PortId,
chan_id: ChannelId,
seq_number: Sequence,
) -> Self
pub fn with_recv_sequence( self, port_id: PortId, chan_id: ChannelId, seq_number: Sequence, ) -> Self
Bootstraps a receive sequence to this context.
This does not bootstrap any corresponding IBC channel, connection or light client.
Sourcepub fn with_ack_sequence(
self,
port_id: PortId,
chan_id: ChannelId,
seq_number: Sequence,
) -> Self
pub fn with_ack_sequence( self, port_id: PortId, chan_id: ChannelId, seq_number: Sequence, ) -> Self
Bootstraps an ack sequence to this context.
This does not bootstrap any corresponding IBC channel, connection or light client.
Sourcepub fn with_packet_commitment(
self,
port_id: PortId,
chan_id: ChannelId,
seq: Sequence,
data: PacketCommitment,
) -> Self
pub fn with_packet_commitment( self, port_id: PortId, chan_id: ChannelId, seq: Sequence, data: PacketCommitment, ) -> Self
Bootstraps a packet commitment to this context.
This does not bootstrap any corresponding IBC channel, connection or light client.
Sourcepub fn validate(&mut self, msg: MsgEnvelope) -> Result<(), HandlerError>
pub fn validate(&mut self, msg: MsgEnvelope) -> Result<(), HandlerError>
Calls validate
function on MsgEnvelope
using the context’s IBC store and router.
Sourcepub fn execute(&mut self, msg: MsgEnvelope) -> Result<(), HandlerError>
pub fn execute(&mut self, msg: MsgEnvelope) -> Result<(), HandlerError>
Calls execute
function on MsgEnvelope
using the context’s IBC store and router.
Sourcepub fn dispatch(&mut self, msg: MsgEnvelope) -> Result<(), HandlerError>
pub fn dispatch(&mut self, msg: MsgEnvelope) -> Result<(), HandlerError>
Calls dispatch
function on MsgEnvelope
using the context’s IBC store and router.
Sourcepub fn deliver(&mut self, msg: MsgEnvelope) -> Result<(), HandlerError>
pub fn deliver(&mut self, msg: MsgEnvelope) -> Result<(), HandlerError>
A datagram passes from the relayer to the IBC module (on host chain).
Alternative method to Ics18Context::send
that does not exercise any serialization.
Used in testing the Ics18 algorithms, hence this may return an Ics18Error.
Sourcepub fn get_events(&self) -> Vec<IbcEvent>
pub fn get_events(&self) -> Vec<IbcEvent>
Returns all the events that have been emitted by the context’s IBC store.
Trait Implementations§
Source§impl<S, H> Debug for StoreGenericTestContext<S, H>where
S: ProvableStore + Debug + Debug,
H: TestHost + Debug,
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
impl<S, H> Debug for StoreGenericTestContext<S, H>where
S: ProvableStore + Debug + Debug,
H: TestHost + Debug,
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
Source§impl<S, H> Default for StoreGenericTestContext<S, H>where
S: ProvableStore + Debug + Default,
H: TestHost,
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
Returns a StoreGenericTestContext
with bare minimum initialization: no clients, no connections, and no channels are
present, and the chain has Height(5). This should be used sparingly, mostly for testing the
creation of new domain objects.
impl<S, H> Default for StoreGenericTestContext<S, H>where
S: ProvableStore + Debug + Default,
H: TestHost,
HostClientState<H>: ClientStateValidation<MockIbcStore<S>>,
Returns a StoreGenericTestContext
with bare minimum initialization: no clients, no connections, and no channels are
present, and the chain has Height(5). This should be used sparingly, mostly for testing the
creation of new domain objects.
Auto Trait Implementations§
impl<S, H> Freeze for StoreGenericTestContext<S, H>
impl<S, H> !RefUnwindSafe for StoreGenericTestContext<S, H>
impl<S, H> !Send for StoreGenericTestContext<S, H>
impl<S, H> !Sync for StoreGenericTestContext<S, H>
impl<S, H> Unpin for StoreGenericTestContext<S, H>
impl<S, H> !UnwindSafe for StoreGenericTestContext<S, H>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request