Skip to content

Commit

Permalink
Implementing CosmosSetup context
Browse files Browse the repository at this point in the history
  • Loading branch information
soareschen committed Jan 12, 2024
1 parent 7650b14 commit 160ecc4
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 40 deletions.
48 changes: 22 additions & 26 deletions crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -64,11 +64,11 @@ pub struct CosmosStdBootstrapContext {
Box<dyn Fn(&mut toml::Value) -> 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;
}

Expand All @@ -94,19 +94,19 @@ delegate_components! {
}
}

impl ProvideChainType<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
impl ProvideChainType<CosmosBootstrap> for CosmosStdBootstrapComponents {
type Chain = CosmosChain;
}

impl ProvideChainDriverType<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
impl ProvideChainDriverType<CosmosBootstrap> for CosmosStdBootstrapComponents {
type ChainDriver = CosmosChainDriver;
}

#[async_trait]
impl ChainFromBootstrapParamsBuilder<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
impl ChainFromBootstrapParamsBuilder<CosmosBootstrap> 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,
Expand Down Expand Up @@ -180,59 +180,55 @@ impl ChainFromBootstrapParamsBuilder<CosmosStdBootstrapContext> for CosmosStdBoo
}
}

impl ProvideRuntime<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
fn runtime(bootstrap: &CosmosStdBootstrapContext) -> &HermesRuntime {
impl ProvideRuntime<CosmosBootstrap> for CosmosStdBootstrapComponents {
fn runtime(bootstrap: &CosmosBootstrap) -> &HermesRuntime {
&bootstrap.runtime
}
}

impl TestDirGetter<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
fn test_dir(bootstrap: &CosmosStdBootstrapContext) -> &PathBuf {
impl TestDirGetter<CosmosBootstrap> for CosmosStdBootstrapComponents {
fn test_dir(bootstrap: &CosmosBootstrap) -> &PathBuf {
&bootstrap.test_dir
}
}

impl ChainCommandPathGetter<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
fn chain_command_path(bootstrap: &CosmosStdBootstrapContext) -> &PathBuf {
impl ChainCommandPathGetter<CosmosBootstrap> for CosmosStdBootstrapComponents {
fn chain_command_path(bootstrap: &CosmosBootstrap) -> &PathBuf {
&bootstrap.chain_command_path
}
}

impl RandomIdFlagGetter<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
fn should_randomize_identifiers(bootstrap: &CosmosStdBootstrapContext) -> bool {
impl RandomIdFlagGetter<CosmosBootstrap> for CosmosStdBootstrapComponents {
fn should_randomize_identifiers(bootstrap: &CosmosBootstrap) -> bool {
bootstrap.should_randomize_identifiers
}
}

impl CosmosGenesisConfigModifier<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
impl CosmosGenesisConfigModifier<CosmosBootstrap> for CosmosStdBootstrapComponents {
fn modify_genesis_config(
bootstrap: &CosmosStdBootstrapContext,
bootstrap: &CosmosBootstrap,
config: &mut serde_json::Value,
) -> Result<(), <CosmosStdBootstrapContext as HasErrorType>::Error> {
) -> Result<(), <CosmosBootstrap as HasErrorType>::Error> {
(bootstrap.genesis_config_modifier)(config)
}
}

impl CometConfigModifier<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
impl CometConfigModifier<CosmosBootstrap> 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<CosmosStdBootstrapContext, DenomForStaking>
for CosmosStdBootstrapComponents
{
impl GenesisDenomGetter<CosmosBootstrap, DenomForStaking> for CosmosStdBootstrapComponents {
fn genesis_denom(genesis_config: &CosmosGenesisConfig) -> &Denom {
&genesis_config.staking_denom
}
}

impl GenesisDenomGetter<CosmosStdBootstrapContext, DenomForTransfer>
for CosmosStdBootstrapComponents
{
impl GenesisDenomGetter<CosmosBootstrap, DenomForTransfer> for CosmosStdBootstrapComponents {
fn genesis_denom(genesis_config: &CosmosGenesisConfig) -> &Denom {
&genesis_config.transfer_denom
}
Expand Down
83 changes: 82 additions & 1 deletion crates/cosmos/cosmos-integration-tests/src/contexts/setup.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -20,6 +50,7 @@ delegate_all!(
delegate_components! {
CosmosSetupComponents {
ErrorTypeComponent: ProvideEyreError,
ErrorRaiserComponent: RaiseDebugError,
}
}

Expand All @@ -29,3 +60,53 @@ where
{
type Chain = CosmosChain;
}

impl<const I: usize> ProvideChainDriverTypeAt<CosmosSetup, I> for CosmosSetupComponents {
type ChainDriver = CosmosChainDriver;
}

impl<const I: usize, const J: usize> ProvideRelayTypeAt<CosmosSetup, I, J>
for CosmosSetupComponents
{
type Relay = CosmosRelay;
}

impl<const I: usize, const J: usize> ProvideBiRelayTypeAt<CosmosSetup, I, J>
for CosmosSetupComponents
{
type BiRelay = CosmosBiRelay;
}

impl<const I: usize, const J: usize> ProvideBuilderTypeAt<CosmosSetup, I, J>
for CosmosSetupComponents
{
type Builder = CosmosBuilder;
}

impl<const I: usize, const J: usize> ProvideBuilderAt<CosmosSetup, I, J> for CosmosSetupComponents {
fn builder(setup: &CosmosSetup) -> &CosmosBuilder {
&setup.builder
}
}

impl<const I: usize, const J: usize> ProvideCreateClientOptionsAt<CosmosSetup, I, J>
for CosmosSetupComponents
{
fn create_client_options(setup: &CosmosSetup, _index: Twindex<I, J>) -> &ClientSettings {
&setup.create_client_settings
}
}

impl<const I: usize, const J: usize> ProvideInitConnectionOptionsAt<CosmosSetup, I, J>
for CosmosSetupComponents
{
fn init_connection_options(setup: &CosmosSetup) -> &CosmosInitConnectionOptions {
&setup.init_connection_options
}
}

impl<const I: usize, const J: usize> ProvidePortIdAt<CosmosSetup, I, J> for CosmosSetupComponents {
fn port_id_at(setup: &CosmosSetup, _index: Twindex<I, J>) -> &PortId {
&setup.port_id
}
}
27 changes: 14 additions & 13 deletions crates/cosmos/cosmos-integration-tests/src/tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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,
Expand All @@ -48,27 +49,27 @@ 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?;

let client_id_b = CosmosRelay::create_client(
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?;

Expand Down

0 comments on commit 160ecc4

Please sign in to comment.