From c172bc8b9b8b7e5ec9a779546f7e871638db0602 Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Fri, 19 Jan 2024 12:58:36 +0100 Subject: [PATCH] Have separate bootstraps in the setup context --- .../src/contexts/binary_channel/setup.rs | 32 +++++++++++++------ .../src/contexts/bootstrap.rs | 16 +++++++--- .../cosmos-integration-tests/src/lib.rs | 1 + .../src/tests/celestia.rs | 25 ++++++++++++--- .../src/tests/cosmos.rs | 9 +++--- 5 files changed, 59 insertions(+), 24 deletions(-) diff --git a/crates/cosmos/cosmos-integration-tests/src/contexts/binary_channel/setup.rs b/crates/cosmos/cosmos-integration-tests/src/contexts/binary_channel/setup.rs index 8e8eedc79..9301ee2df 100644 --- a/crates/cosmos/cosmos-integration-tests/src/contexts/binary_channel/setup.rs +++ b/crates/cosmos/cosmos-integration-tests/src/contexts/binary_channel/setup.rs @@ -1,3 +1,4 @@ +use alloc::sync::Arc; use cgp_core::delegate_all; use cgp_core::prelude::*; use cgp_core::ErrorRaiserComponent; @@ -44,7 +45,8 @@ use crate::contexts::relay_driver::CosmosRelayDriver; with both chains being Cosmos chains. */ pub struct CosmosBinaryChannelSetup { - pub bootstrap: CosmosBootstrap, + pub bootstrap_a: Arc, + pub bootstrap_b: Arc, pub create_client_settings: ClientSettings, pub init_connection_options: CosmosInitConnectionOptions, pub init_channel_options: CosmosInitChannelOptions, @@ -141,21 +143,31 @@ impl ProvideBuilderTypeAt ProvideBootstrapAt - for CosmosBinaryChannelSetupComponents -{ +impl ProvideBootstrapAt for CosmosBinaryChannelSetupComponents { type Bootstrap = CosmosBootstrap; - fn chain_bootstrap(setup: &CosmosBinaryChannelSetup, _index: Index) -> &CosmosBootstrap { - &setup.bootstrap + fn chain_bootstrap(setup: &CosmosBinaryChannelSetup, _index: Index<0>) -> &CosmosBootstrap { + &setup.bootstrap_a } } -impl ProvideBuilderAt - for CosmosBinaryChannelSetupComponents -{ +impl ProvideBootstrapAt for CosmosBinaryChannelSetupComponents { + type Bootstrap = CosmosBootstrap; + + fn chain_bootstrap(setup: &CosmosBinaryChannelSetup, _index: Index<1>) -> &CosmosBootstrap { + &setup.bootstrap_b + } +} + +impl ProvideBuilderAt for CosmosBinaryChannelSetupComponents { + fn builder(setup: &CosmosBinaryChannelSetup) -> &CosmosBuilder { + &setup.bootstrap_a.builder + } +} + +impl ProvideBuilderAt for CosmosBinaryChannelSetupComponents { fn builder(setup: &CosmosBinaryChannelSetup) -> &CosmosBuilder { - &setup.bootstrap.builder + &setup.bootstrap_b.builder } } diff --git a/crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs b/crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs index 8d1049f55..f8297d8cc 100644 --- a/crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs +++ b/crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs @@ -36,6 +36,7 @@ use hermes_cosmos_test_components::bootstrap::types::chain_config::CosmosChainCo use hermes_cosmos_test_components::bootstrap::types::genesis_config::CosmosGenesisConfig; use hermes_cosmos_test_components::chain_driver::types::denom::Denom; use hermes_cosmos_test_components::chain_driver::types::wallet::CosmosTestWallet; +use hermes_relayer_components::chain::traits::components::chain_status_querier::CanQueryChainStatus; use hermes_relayer_components::runtime::traits::runtime::{ProvideRuntime, RuntimeTypeComponent}; use hermes_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use hermes_relayer_runtime::types::runtime::HermesRuntime; @@ -59,7 +60,7 @@ use crate::contexts::chain_driver::CosmosChainDriver; */ pub struct CosmosBootstrap { pub runtime: HermesRuntime, - pub builder: CosmosBuilder, + pub builder: Arc, pub should_randomize_identifiers: bool, pub test_dir: PathBuf, pub chain_command_path: PathBuf, @@ -196,6 +197,15 @@ impl ChainFromBootstrapParamsBuilder for CosmosStdBootstrapComp ) .await?; + for _ in 0..10 { + // Wait for full node process to start up + if let Ok(_) = base_chain.query_chain_status().await { + break; + } else { + sleep(Duration::from_secs(1)).await; + } + } + let test_chain = CosmosChainDriver { base_chain, chain_config, @@ -209,10 +219,6 @@ impl ChainFromBootstrapParamsBuilder for CosmosStdBootstrapComp user_wallet_b: user_wallet_b.clone(), }; - // Sleep for a while to wait for the chain node to really start up - // TODO: use other more reliable method to check that the full node has started. - sleep(Duration::from_secs(1)).await; - Ok(test_chain) } } diff --git a/crates/cosmos/cosmos-integration-tests/src/lib.rs b/crates/cosmos/cosmos-integration-tests/src/lib.rs index 37c86971b..10c38597d 100644 --- a/crates/cosmos/cosmos-integration-tests/src/lib.rs +++ b/crates/cosmos/cosmos-integration-tests/src/lib.rs @@ -1,4 +1,5 @@ #![allow(clippy::type_complexity)] +#![recursion_limit = "256"] extern crate alloc; diff --git a/crates/cosmos/cosmos-integration-tests/src/tests/celestia.rs b/crates/cosmos/cosmos-integration-tests/src/tests/celestia.rs index f76c922e7..051332d57 100644 --- a/crates/cosmos/cosmos-integration-tests/src/tests/celestia.rs +++ b/crates/cosmos/cosmos-integration-tests/src/tests/celestia.rs @@ -25,9 +25,23 @@ fn celestia_integration_tests() -> Result<(), Error> { let runtime = HermesRuntime::new(tokio_runtime.clone()); - let builder = CosmosBuilder::new_with_default(runtime.clone()); + let builder = Arc::new(CosmosBuilder::new_with_default(runtime.clone())); - let bootstrap = CosmosBootstrap { + let cosmos_bootstrap = Arc::new(CosmosBootstrap { + runtime: runtime.clone(), + builder: builder.clone(), + should_randomize_identifiers: true, + test_dir: "./test-data".into(), + chain_command_path: "gaiad".into(), + account_prefix: "cosmos".into(), + compat_mode: None, + staking_denom: Denom::base("stake"), + transfer_denom: Denom::base("coin"), + genesis_config_modifier: Box::new(|_| Ok(())), + comet_config_modifier: Box::new(|_| Ok(())), + }); + + let celestia_bootstrap = Arc::new(CosmosBootstrap { runtime, builder, should_randomize_identifiers: true, @@ -39,16 +53,17 @@ fn celestia_integration_tests() -> Result<(), Error> { transfer_denom: Denom::base("coin"), genesis_config_modifier: Box::new(|_| Ok(())), comet_config_modifier: Box::new(|_| Ok(())), - }; + }); let create_client_settings = ClientSettings::Tendermint(Settings { max_clock_drift: Duration::from_secs(40), - trusting_period: None, + trusting_period: Some(Duration::from_secs(60 * 60)), trust_threshold: TrustThreshold::ONE_THIRD, }); let setup = CosmosBinaryChannelSetup { - bootstrap, + bootstrap_a: cosmos_bootstrap, + bootstrap_b: celestia_bootstrap, create_client_settings, init_connection_options: Default::default(), init_channel_options: Default::default(), diff --git a/crates/cosmos/cosmos-integration-tests/src/tests/cosmos.rs b/crates/cosmos/cosmos-integration-tests/src/tests/cosmos.rs index 99f491d1a..3ea318929 100644 --- a/crates/cosmos/cosmos-integration-tests/src/tests/cosmos.rs +++ b/crates/cosmos/cosmos-integration-tests/src/tests/cosmos.rs @@ -24,10 +24,10 @@ fn cosmos_integration_tests() -> Result<(), Error> { let runtime = HermesRuntime::new(tokio_runtime.clone()); - let builder = CosmosBuilder::new_with_default(runtime.clone()); + let builder = Arc::new(CosmosBuilder::new_with_default(runtime.clone())); // TODO: load parameters from environment variables - let bootstrap = CosmosBootstrap { + let bootstrap = Arc::new(CosmosBootstrap { runtime, builder, should_randomize_identifiers: true, @@ -39,7 +39,7 @@ fn cosmos_integration_tests() -> Result<(), Error> { transfer_denom: Denom::base("coin"), genesis_config_modifier: Box::new(|_| Ok(())), comet_config_modifier: Box::new(|_| Ok(())), - }; + }); let create_client_settings = ClientSettings::Tendermint(Settings { max_clock_drift: Duration::from_secs(40), @@ -48,7 +48,8 @@ fn cosmos_integration_tests() -> Result<(), Error> { }); let setup = CosmosBinaryChannelSetup { - bootstrap, + bootstrap_a: bootstrap.clone(), + bootstrap_b: bootstrap, create_client_settings, init_connection_options: Default::default(), init_channel_options: Default::default(),