Skip to content

Commit

Permalink
update MockClient types
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Feb 2, 2024
1 parent e006151 commit 173ff7b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
20 changes: 11 additions & 9 deletions ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::testapp::ibc::clients::mock::consensus_state::MockConsensusState;
use crate::testapp::ibc::clients::mock::header::MockHeader;
use crate::testapp::ibc::clients::mock::misbehaviour::Misbehaviour;
use crate::testapp::ibc::clients::mock::proto::ClientState as RawMockClientState;
use crate::testapp::ibc::utils::{duration_gpb_to_ibc, duration_ibc_to_gbp};

pub const MOCK_CLIENT_STATE_TYPE_URL: &str = "/ibc.mock.ClientState";
pub const MOCK_CLIENT_TYPE: &str = "9999-mock";
Expand All @@ -38,17 +37,15 @@ pub fn client_type() -> ClientType {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct MockClientState {
pub header: MockHeader,
pub max_clock_drift: Option<Duration>,
pub trusting_period: Option<Duration>,
pub trusting_period: Duration,
pub frozen: bool,
}

impl MockClientState {
pub fn new(header: MockHeader) -> Self {
Self {
header,
max_clock_drift: None,
trusting_period: None,
trusting_period: Duration::from_nanos(0),
frozen: false,
}
}
Expand All @@ -61,6 +58,13 @@ impl MockClientState {
None
}

pub fn with_trusting_period(self, trusting_period: Duration) -> Self {
Self {
trusting_period,
..self
}
}

pub fn with_frozen_height(self, _frozen_height: Height) -> Self {
Self {
frozen: true,
Expand Down Expand Up @@ -90,8 +94,7 @@ impl TryFrom<RawMockClientState> for MockClientState {
description: "header is not present".into(),
})?
.try_into()?,
max_clock_drift: raw.max_clock_drift.map(duration_gpb_to_ibc),
trusting_period: raw.trusting_period.map(duration_gpb_to_ibc),
trusting_period: Duration::from_nanos(raw.trusting_period),
frozen: raw.frozen,
})
}
Expand All @@ -101,8 +104,7 @@ impl From<MockClientState> for RawMockClientState {
fn from(value: MockClientState) -> Self {
RawMockClientState {
header: Some(value.header.into()),
max_clock_drift: value.max_clock_drift.map(duration_ibc_to_gbp),
trusting_period: value.trusting_period.map(duration_ibc_to_gbp),
trusting_period: value.trusting_period.as_nanos() as _,
frozen: value.frozen,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl From<MockConsensusState> for RawMockConsensusState {
fn from(value: MockConsensusState) -> Self {
RawMockConsensusState {
header: Some(value.header.into()),
bytes: value.root.into_vec(),
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions ibc-testkit/src/testapp/ibc/clients/mock/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use ibc::core::primitives::Timestamp;
use ibc::primitives::proto::{Any, Protobuf};

use crate::testapp::ibc::clients::mock::proto::Header as RawMockHeader;
use crate::testapp::ibc::utils::{timestamp_gpb_to_ibc, timestamp_ibc_to_gpb};

pub const MOCK_HEADER_TYPE_URL: &str = "/ibc.mock.Header";

Expand Down Expand Up @@ -50,12 +49,11 @@ impl TryFrom<RawMockHeader> for MockHeader {
description: "missing height".into(),
})?
.try_into()?,
timestamp: raw
.timestamp
.map(timestamp_gpb_to_ibc)
.ok_or(ClientError::Other {
description: "missing timestamp".into(),
})?,
timestamp: Timestamp::from_nanoseconds(raw.timestamp).map_err(|err| {
ClientError::Other {
description: err.to_string(),
}
})?,
})
}
}
Expand All @@ -64,7 +62,7 @@ impl From<MockHeader> for RawMockHeader {
fn from(value: MockHeader) -> Self {
RawMockHeader {
height: Some(value.height.into()),
timestamp: Some(timestamp_ibc_to_gpb(value.timestamp)),
timestamp: value.timestamp.nanoseconds(),
}
}
}
Expand Down

0 comments on commit 173ff7b

Please sign in to comment.