Skip to content

Commit

Permalink
refactor for updated mock ibc context
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Jan 30, 2024
1 parent bbec93a commit 16f6d60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 9 additions & 6 deletions ibc-testkit/src/fixtures/core/context.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use alloc::sync::Arc;
use alloc::fmt::Debug;
use core::cmp::min;
use core::ops::{Add, Sub};
use core::time::Duration;

use basecoin_store::context::ProvableStore;
use ibc::core::client::types::Height;
use ibc::core::host::types::identifiers::ChainId;
use ibc::core::primitives::prelude::*;
use ibc::core::primitives::Timestamp;
use parking_lot::Mutex;
use tendermint_testgen::Validator as TestgenValidator;
use typed_builder::TypedBuilder;

use crate::hosts::block::{HostBlock, HostType};
use crate::testapp::ibc::core::types::{MockContext, MockIbcStore, DEFAULT_BLOCK_TIME_SECS};
use crate::testapp::ibc::core::types::{MockGenericContext, MockIbcStore, DEFAULT_BLOCK_TIME_SECS};

/// Configuration of the `MockContext` type for generating dummy contexts.
#[derive(Debug, TypedBuilder)]
Expand Down Expand Up @@ -41,7 +41,10 @@ pub struct MockContextConfig {
latest_timestamp: Timestamp,
}

impl From<MockContextConfig> for MockContext {
impl<S> From<MockContextConfig> for MockGenericContext<S>
where
S: ProvableStore + Debug + Default,
{
fn from(params: MockContextConfig) -> Self {
assert_ne!(
params.max_history_size, 0,
Expand Down Expand Up @@ -115,13 +118,13 @@ impl From<MockContextConfig> for MockContext {
.collect()
};

MockContext {
MockGenericContext {
host_chain_type: params.host_type,
host_chain_id: params.host_id.clone(),
max_history_size: params.max_history_size,
history,
block_time: params.block_time,
ibc_store: Arc::new(Mutex::new(MockIbcStore::default())),
ibc_store: MockIbcStore::default(),
}
}
}
10 changes: 8 additions & 2 deletions ibc-testkit/src/relayer/context.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use alloc::fmt::Debug;

use basecoin_store::context::ProvableStore;
use ibc::core::client::types::Height;
use ibc::core::handler::types::error::ContextError;
use ibc::core::host::types::identifiers::ClientId;
Expand All @@ -6,7 +9,7 @@ use ibc::core::primitives::prelude::*;
use ibc::core::primitives::Signer;

use crate::testapp::ibc::clients::AnyClientState;
use crate::testapp::ibc::core::types::MockContext;
use crate::testapp::ibc::core::types::MockGenericContext;
/// Trait capturing all dependencies (i.e., the context) which algorithms in ICS18 require to
/// relay packets between chains. This trait comprises the dependencies towards a single chain.
/// Most of the functions in this represent wrappers over the ABCI interface.
Expand All @@ -24,7 +27,10 @@ pub trait RelayerContext {
fn signer(&self) -> Signer;
}

impl RelayerContext for MockContext {
impl<S> RelayerContext for MockGenericContext<S>
where
S: ProvableStore + Debug,
{
fn query_latest_height(&self) -> Result<Height, ContextError> {
ValidationContext::host_height(self)
}
Expand Down

0 comments on commit 16f6d60

Please sign in to comment.