ibc_testkit/hosts/
mock.rsuse alloc::vec::Vec;
use bon::Builder;
use ibc::core::client::types::Height;
use ibc::core::host::types::identifiers::ChainId;
use ibc::core::primitives::Timestamp;
use super::{TestBlock, TestHeader, TestHost};
use crate::testapp::ibc::clients::mock::client_state::MockClientState;
use crate::testapp::ibc::clients::mock::consensus_state::MockConsensusState;
use crate::testapp::ibc::clients::mock::header::MockHeader;
#[derive(Debug, Builder)]
pub struct MockHost {
#[builder(default = ChainId::new("mock-0").expect("Never fails"))]
pub chain_id: ChainId,
#[builder(default)]
pub history: Vec<MockHeader>,
}
impl Default for MockHost {
fn default() -> Self {
Self::builder().build()
}
}
impl TestHost for MockHost {
type Block = MockHeader;
type ClientState = MockClientState;
type BlockParams = ();
type LightClientParams = ();
fn history(&self) -> &Vec<Self::Block> {
&self.history
}
fn push_block(&mut self, block: Self::Block) {
self.history.push(block);
}
fn generate_block(
&self,
_commitment_root: Vec<u8>,
height: u64,
timestamp: Timestamp,
_params: &Self::BlockParams,
) -> Self::Block {
MockHeader {
height: Height::new(self.chain_id.revision_number(), height).expect("Never fails"),
timestamp,
}
}
fn generate_client_state(
&self,
latest_height: &Height,
_params: &Self::LightClientParams,
) -> Self::ClientState {
MockClientState::new(self.get_block(latest_height).expect("height exists"))
}
}
impl TestBlock for MockHeader {
type Header = Self;
fn height(&self) -> Height {
self.height
}
fn timestamp(&self) -> Timestamp {
self.timestamp
}
fn into_header_with_trusted(self, _trusted_block: &Self) -> Self::Header {
self
}
}
impl From<MockHeader> for MockConsensusState {
fn from(block: MockHeader) -> Self {
Self::new(block)
}
}
impl TestHeader for MockHeader {
type ConsensusState = MockConsensusState;
fn height(&self) -> Height {
self.height
}
fn timestamp(&self) -> Timestamp {
self.timestamp
}
}