From 160ecc4bb8beee321656cd12d0f3b81e8c4c5cad Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Fri, 12 Jan 2024 15:36:39 +0100 Subject: [PATCH] Implementing CosmosSetup context --- .../src/contexts/bootstrap.rs | 48 +++++------ .../src/contexts/setup.rs | 83 ++++++++++++++++++- .../src/tests/bootstrap.rs | 27 +++--- 3 files changed, 118 insertions(+), 40 deletions(-) diff --git a/crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs b/crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs index af2e9d1fc..35c72c8e1 100644 --- a/crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs +++ b/crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs @@ -51,7 +51,7 @@ use tokio::process::Child; use crate::contexts::chain::CosmosChainDriver; -pub struct CosmosStdBootstrapContext { +pub struct CosmosBootstrap { pub runtime: HermesRuntime, pub builder: CosmosBuilder, pub should_randomize_identifiers: bool, @@ -64,11 +64,11 @@ pub struct CosmosStdBootstrapContext { Box Result<(), Error> + Send + Sync + 'static>, } -impl CanUseLegacyCosmosSdkChainBootstrapper for CosmosStdBootstrapContext {} +impl CanUseLegacyCosmosSdkChainBootstrapper for CosmosBootstrap {} pub struct CosmosStdBootstrapComponents; -impl HasComponents for CosmosStdBootstrapContext { +impl HasComponents for CosmosBootstrap { type Components = CosmosStdBootstrapComponents; } @@ -94,19 +94,19 @@ delegate_components! { } } -impl ProvideChainType for CosmosStdBootstrapComponents { +impl ProvideChainType for CosmosStdBootstrapComponents { type Chain = CosmosChain; } -impl ProvideChainDriverType for CosmosStdBootstrapComponents { +impl ProvideChainDriverType for CosmosStdBootstrapComponents { type ChainDriver = CosmosChainDriver; } #[async_trait] -impl ChainFromBootstrapParamsBuilder for CosmosStdBootstrapComponents { +impl ChainFromBootstrapParamsBuilder for CosmosStdBootstrapComponents { #[allow(unused_variables)] async fn build_chain_from_bootstrap_params( - bootstrap: &CosmosStdBootstrapContext, + bootstrap: &CosmosBootstrap, chain_home_dir: PathBuf, chain_id: ChainId, genesis_config: CosmosGenesisConfig, @@ -180,59 +180,55 @@ impl ChainFromBootstrapParamsBuilder for CosmosStdBoo } } -impl ProvideRuntime for CosmosStdBootstrapComponents { - fn runtime(bootstrap: &CosmosStdBootstrapContext) -> &HermesRuntime { +impl ProvideRuntime for CosmosStdBootstrapComponents { + fn runtime(bootstrap: &CosmosBootstrap) -> &HermesRuntime { &bootstrap.runtime } } -impl TestDirGetter for CosmosStdBootstrapComponents { - fn test_dir(bootstrap: &CosmosStdBootstrapContext) -> &PathBuf { +impl TestDirGetter for CosmosStdBootstrapComponents { + fn test_dir(bootstrap: &CosmosBootstrap) -> &PathBuf { &bootstrap.test_dir } } -impl ChainCommandPathGetter for CosmosStdBootstrapComponents { - fn chain_command_path(bootstrap: &CosmosStdBootstrapContext) -> &PathBuf { +impl ChainCommandPathGetter for CosmosStdBootstrapComponents { + fn chain_command_path(bootstrap: &CosmosBootstrap) -> &PathBuf { &bootstrap.chain_command_path } } -impl RandomIdFlagGetter for CosmosStdBootstrapComponents { - fn should_randomize_identifiers(bootstrap: &CosmosStdBootstrapContext) -> bool { +impl RandomIdFlagGetter for CosmosStdBootstrapComponents { + fn should_randomize_identifiers(bootstrap: &CosmosBootstrap) -> bool { bootstrap.should_randomize_identifiers } } -impl CosmosGenesisConfigModifier for CosmosStdBootstrapComponents { +impl CosmosGenesisConfigModifier for CosmosStdBootstrapComponents { fn modify_genesis_config( - bootstrap: &CosmosStdBootstrapContext, + bootstrap: &CosmosBootstrap, config: &mut serde_json::Value, - ) -> Result<(), ::Error> { + ) -> Result<(), ::Error> { (bootstrap.genesis_config_modifier)(config) } } -impl CometConfigModifier for CosmosStdBootstrapComponents { +impl CometConfigModifier for CosmosStdBootstrapComponents { fn modify_comet_config( - bootstrap: &CosmosStdBootstrapContext, + bootstrap: &CosmosBootstrap, comet_config: &mut toml::Value, ) -> Result<(), Error> { (bootstrap.comet_config_modifier)(comet_config) } } -impl GenesisDenomGetter - for CosmosStdBootstrapComponents -{ +impl GenesisDenomGetter for CosmosStdBootstrapComponents { fn genesis_denom(genesis_config: &CosmosGenesisConfig) -> &Denom { &genesis_config.staking_denom } } -impl GenesisDenomGetter - for CosmosStdBootstrapComponents -{ +impl GenesisDenomGetter for CosmosStdBootstrapComponents { fn genesis_denom(genesis_config: &CosmosGenesisConfig) -> &Denom { &genesis_config.transfer_denom } diff --git a/crates/cosmos/cosmos-integration-tests/src/contexts/setup.rs b/crates/cosmos/cosmos-integration-tests/src/contexts/setup.rs index 62d9ae471..485785c13 100644 --- a/crates/cosmos/cosmos-integration-tests/src/contexts/setup.rs +++ b/crates/cosmos/cosmos-integration-tests/src/contexts/setup.rs @@ -1,16 +1,46 @@ use cgp_core::delegate_all; use cgp_core::prelude::*; +use cgp_core::ErrorRaiserComponent; use cgp_core::ErrorTypeComponent; use cgp_error_eyre::ProvideEyreError; +use cgp_error_eyre::RaiseDebugError; +use hermes_cosmos_client_components::types::connection::CosmosInitConnectionOptions; +use hermes_cosmos_relayer::contexts::birelay::CosmosBiRelay; +use hermes_cosmos_relayer::contexts::builder::CosmosBuilder; use hermes_cosmos_relayer::contexts::chain::CosmosChain; +use hermes_cosmos_relayer::contexts::relay::CosmosRelay; +use hermes_test_components::driver::traits::types::birelay_at::ProvideBiRelayTypeAt; +use hermes_test_components::driver::traits::types::builder_at::ProvideBuilderTypeAt; use hermes_test_components::driver::traits::types::chain_at::ProvideChainTypeAt; +use hermes_test_components::driver::traits::types::chain_driver_at::ProvideChainDriverTypeAt; +use hermes_test_components::driver::traits::types::relay_at::ProvideRelayTypeAt; use hermes_test_components::setup::components::binary_channel::BinaryChannelTestComponents; use hermes_test_components::setup::components::binary_channel::IsBinaryChannelTestComponent; +use hermes_test_components::setup::traits::builder_at::ProvideBuilderAt; +use hermes_test_components::setup::traits::create_client_options_at::ProvideCreateClientOptionsAt; +use hermes_test_components::setup::traits::init_connection_options_at::ProvideInitConnectionOptionsAt; +use hermes_test_components::setup::traits::port_id_at::ProvidePortIdAt; +use hermes_test_components::types::index::Twindex; +use ibc_relayer::chain::client::ClientSettings; +use ibc_relayer_types::core::ics24_host::identifier::PortId; -pub struct CosmosSetup; +use crate::contexts::bootstrap::CosmosBootstrap; +use crate::contexts::chain::CosmosChainDriver; + +pub struct CosmosSetup { + pub create_client_settings: ClientSettings, + pub bootstrap: CosmosBootstrap, + pub builder: CosmosBuilder, + pub port_id: PortId, + pub init_connection_options: CosmosInitConnectionOptions, +} pub struct CosmosSetupComponents; +impl HasComponents for CosmosSetup { + type Components = CosmosSetupComponents; +} + delegate_all!( IsBinaryChannelTestComponent, BinaryChannelTestComponents, @@ -20,6 +50,7 @@ delegate_all!( delegate_components! { CosmosSetupComponents { ErrorTypeComponent: ProvideEyreError, + ErrorRaiserComponent: RaiseDebugError, } } @@ -29,3 +60,53 @@ where { type Chain = CosmosChain; } + +impl ProvideChainDriverTypeAt for CosmosSetupComponents { + type ChainDriver = CosmosChainDriver; +} + +impl ProvideRelayTypeAt + for CosmosSetupComponents +{ + type Relay = CosmosRelay; +} + +impl ProvideBiRelayTypeAt + for CosmosSetupComponents +{ + type BiRelay = CosmosBiRelay; +} + +impl ProvideBuilderTypeAt + for CosmosSetupComponents +{ + type Builder = CosmosBuilder; +} + +impl ProvideBuilderAt for CosmosSetupComponents { + fn builder(setup: &CosmosSetup) -> &CosmosBuilder { + &setup.builder + } +} + +impl ProvideCreateClientOptionsAt + for CosmosSetupComponents +{ + fn create_client_options(setup: &CosmosSetup, _index: Twindex) -> &ClientSettings { + &setup.create_client_settings + } +} + +impl ProvideInitConnectionOptionsAt + for CosmosSetupComponents +{ + fn init_connection_options(setup: &CosmosSetup) -> &CosmosInitConnectionOptions { + &setup.init_connection_options + } +} + +impl ProvidePortIdAt for CosmosSetupComponents { + fn port_id_at(setup: &CosmosSetup, _index: Twindex) -> &PortId { + &setup.port_id + } +} diff --git a/crates/cosmos/cosmos-integration-tests/src/tests/bootstrap.rs b/crates/cosmos/cosmos-integration-tests/src/tests/bootstrap.rs index 581189d48..e9b204acd 100644 --- a/crates/cosmos/cosmos-integration-tests/src/tests/bootstrap.rs +++ b/crates/cosmos/cosmos-integration-tests/src/tests/bootstrap.rs @@ -14,13 +14,14 @@ use hermes_relayer_components::relay::traits::target::{DestinationTarget, Source use hermes_relayer_runtime::types::runtime::HermesRuntime; use hermes_test_components::bootstrap::traits::chain::CanBootstrapChain; use ibc_relayer::chain::client::ClientSettings; -use ibc_relayer::foreign_client::CreateOptions; +use ibc_relayer::chain::cosmos::client::Settings; +use ibc_relayer_types::core::ics02_client::trust_threshold::TrustThreshold; use ibc_relayer_types::core::ics24_host::identifier::PortId; use tokio::runtime::Runtime; use tokio::test; use tokio::time::sleep; -use crate::contexts::bootstrap::CosmosStdBootstrapContext; +use crate::contexts::bootstrap::CosmosBootstrap; #[test(flavor = "multi_thread")] async fn test_bootstrap_cosmos_chain() -> Result<(), Error> { @@ -31,7 +32,7 @@ async fn test_bootstrap_cosmos_chain() -> Result<(), Error> { let builder = CosmosBuilder::new_with_default(runtime.clone()); - let bootstrap = CosmosStdBootstrapContext { + let bootstrap = CosmosBootstrap { runtime, builder, should_randomize_identifiers: true, @@ -48,15 +49,19 @@ async fn test_bootstrap_cosmos_chain() -> Result<(), Error> { sleep(Duration::from_secs(2)).await; + let client_settings = ClientSettings::Tendermint(Settings { + max_clock_drift: Duration::from_secs(40), + trusting_period: None, + trust_threshold: TrustThreshold::ONE_THIRD, + }); + + println!("client settings: {:?}", client_settings); + let client_id_a = CosmosRelay::create_client( SourceTarget, &chain_a.base_chain, &chain_b.base_chain, - &ClientSettings::for_create_command( - CreateOptions::default(), - &chain_a.chain_config, - &chain_b.chain_config, - ), + &client_settings, ) .await?; @@ -64,11 +69,7 @@ async fn test_bootstrap_cosmos_chain() -> Result<(), Error> { DestinationTarget, &chain_b.base_chain, &chain_a.base_chain, - &ClientSettings::for_create_command( - CreateOptions::default(), - &chain_b.chain_config, - &chain_a.chain_config, - ), + &client_settings, ) .await?;