Skip to content

Commit

Permalink
Have separate bootstraps in the setup context
Browse files Browse the repository at this point in the history
  • Loading branch information
soareschen committed Jan 19, 2024
1 parent 4148b92 commit c172bc8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::sync::Arc;
use cgp_core::delegate_all;
use cgp_core::prelude::*;
use cgp_core::ErrorRaiserComponent;
Expand Down Expand Up @@ -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<CosmosBootstrap>,
pub bootstrap_b: Arc<CosmosBootstrap>,
pub create_client_settings: ClientSettings,
pub init_connection_options: CosmosInitConnectionOptions,
pub init_channel_options: CosmosInitChannelOptions,
Expand Down Expand Up @@ -141,21 +143,31 @@ impl<const I: usize, const J: usize> ProvideBuilderTypeAt<CosmosBinaryChannelSet
type Builder = CosmosBuilder;
}

impl<const I: usize> ProvideBootstrapAt<CosmosBinaryChannelSetup, I>
for CosmosBinaryChannelSetupComponents
{
impl ProvideBootstrapAt<CosmosBinaryChannelSetup, 0> for CosmosBinaryChannelSetupComponents {
type Bootstrap = CosmosBootstrap;

fn chain_bootstrap(setup: &CosmosBinaryChannelSetup, _index: Index<I>) -> &CosmosBootstrap {
&setup.bootstrap
fn chain_bootstrap(setup: &CosmosBinaryChannelSetup, _index: Index<0>) -> &CosmosBootstrap {
&setup.bootstrap_a
}
}

impl<const I: usize, const J: usize> ProvideBuilderAt<CosmosBinaryChannelSetup, I, J>
for CosmosBinaryChannelSetupComponents
{
impl ProvideBootstrapAt<CosmosBinaryChannelSetup, 1> for CosmosBinaryChannelSetupComponents {
type Bootstrap = CosmosBootstrap;

fn chain_bootstrap(setup: &CosmosBinaryChannelSetup, _index: Index<1>) -> &CosmosBootstrap {
&setup.bootstrap_b
}
}

impl ProvideBuilderAt<CosmosBinaryChannelSetup, 0, 1> for CosmosBinaryChannelSetupComponents {
fn builder(setup: &CosmosBinaryChannelSetup) -> &CosmosBuilder {
&setup.bootstrap_a.builder
}
}

impl ProvideBuilderAt<CosmosBinaryChannelSetup, 1, 0> for CosmosBinaryChannelSetupComponents {
fn builder(setup: &CosmosBinaryChannelSetup) -> &CosmosBuilder {
&setup.bootstrap.builder
&setup.bootstrap_b.builder
}
}

Expand Down
16 changes: 11 additions & 5 deletions crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,7 +60,7 @@ use crate::contexts::chain_driver::CosmosChainDriver;
*/
pub struct CosmosBootstrap {
pub runtime: HermesRuntime,
pub builder: CosmosBuilder,
pub builder: Arc<CosmosBuilder>,
pub should_randomize_identifiers: bool,
pub test_dir: PathBuf,
pub chain_command_path: PathBuf,
Expand Down Expand Up @@ -196,6 +197,15 @@ impl ChainFromBootstrapParamsBuilder<CosmosBootstrap> for CosmosStdBootstrapComp
)
.await?;

for _ in 0..10 {
// Wait for full node process to start up
if let Ok(_) = base_chain.query_chain_status().await {

Check failure on line 202 in crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

redundant pattern matching, consider using `is_ok()`

error: redundant pattern matching, consider using `is_ok()` --> crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs:202:20 | 202 | if let Ok(_) = base_chain.query_chain_status().await { | -------^^^^^---------------------------------------- help: try: `if (base_chain.query_chain_status().await).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]`

Check failure on line 202 in crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

redundant pattern matching, consider using `is_ok()`

error: redundant pattern matching, consider using `is_ok()` --> crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs:202:20 | 202 | if let Ok(_) = base_chain.query_chain_status().await { | -------^^^^^---------------------------------------- help: try: `if (base_chain.query_chain_status().await).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]`

Check failure on line 202 in crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

redundant pattern matching, consider using `is_ok()`

error: redundant pattern matching, consider using `is_ok()` --> crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs:202:20 | 202 | if let Ok(_) = base_chain.query_chain_status().await { | -------^^^^^---------------------------------------- help: try: `if (base_chain.query_chain_status().await).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]`

Check failure on line 202 in crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

redundant pattern matching, consider using `is_ok()`

error: redundant pattern matching, consider using `is_ok()` --> crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs:202:20 | 202 | if let Ok(_) = base_chain.query_chain_status().await { | -------^^^^^---------------------------------------- help: try: `if (base_chain.query_chain_status().await).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]`
break;
} else {
sleep(Duration::from_secs(1)).await;
}
}

let test_chain = CosmosChainDriver {
base_chain,
chain_config,
Expand All @@ -209,10 +219,6 @@ impl ChainFromBootstrapParamsBuilder<CosmosBootstrap> 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)
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/cosmos/cosmos-integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::type_complexity)]
#![recursion_limit = "256"]

extern crate alloc;

Expand Down
25 changes: 20 additions & 5 deletions crates/cosmos/cosmos-integration-tests/src/tests/celestia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
9 changes: 5 additions & 4 deletions crates/cosmos/cosmos-integration-tests/src/tests/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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(),
Expand Down

0 comments on commit c172bc8

Please sign in to comment.