Skip to content

Commit

Permalink
Adding support for testing Celestia
Browse files Browse the repository at this point in the history
  • Loading branch information
soareschen committed Jan 19, 2024
1 parent 65613b3 commit 4148b92
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 134 deletions.
26 changes: 20 additions & 6 deletions crates/cosmos/cosmos-integration-tests/src/contexts/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use hermes_relayer_runtime::types::runtime::HermesRuntime;
use hermes_test_components::chain_driver::traits::types::chain::ProvideChainType;
use hermes_test_components::driver::traits::types::chain_driver::ProvideChainDriverType;
use ibc_relayer::chain::ChainType;
use ibc_relayer::config::compat_mode::CompatMode;
use ibc_relayer::config::gas_multiplier::GasMultiplier;
use ibc_relayer::config::{self, AddressType, ChainConfig};
use ibc_relayer::keyring::Store;
Expand All @@ -63,6 +64,9 @@ pub struct CosmosBootstrap {
pub test_dir: PathBuf,
pub chain_command_path: PathBuf,
pub account_prefix: String,
pub staking_denom: Denom,
pub transfer_denom: Denom,
pub compat_mode: Option<CompatMode>,
pub genesis_config_modifier:
Box<dyn Fn(&mut serde_json::Value) -> Result<(), Error> + Send + Sync + 'static>,
pub comet_config_modifier:
Expand Down Expand Up @@ -173,14 +177,14 @@ impl ChainFromBootstrapParamsBuilder<CosmosBootstrap> for CosmosStdBootstrapComp
trusting_period: Some(Duration::from_secs(14 * 24 * 3600)),
ccv_consumer_chain: false,
trust_threshold: Default::default(),
gas_price: config::GasPrice::new(0.003, genesis_config.staking_denom.to_string()),
gas_price: config::GasPrice::new(0.003, bootstrap.staking_denom.to_string()),
packet_filter: Default::default(),
address_type: AddressType::Cosmos,
memo_prefix: Default::default(),
proof_specs: Default::default(),
extension_options: Default::default(),
sequential_batch_tx: false,
compat_mode: None,
compat_mode: bootstrap.compat_mode.clone(),
clear_interval: None,
};

Expand All @@ -198,6 +202,8 @@ impl ChainFromBootstrapParamsBuilder<CosmosBootstrap> for CosmosStdBootstrapComp
genesis_config,
relayer_chain_config,
full_node_process: Arc::new(chain_process),
staking_denom: bootstrap.staking_denom.clone(),
transfer_denom: bootstrap.transfer_denom.clone(),
relayer_wallet: relayer_wallet.clone(),
user_wallet_a: user_wallet_a.clone(),
user_wallet_b: user_wallet_b.clone(),
Expand Down Expand Up @@ -254,13 +260,21 @@ impl CometConfigModifier<CosmosBootstrap> for CosmosStdBootstrapComponents {
}

impl GenesisDenomGetter<CosmosBootstrap, DenomForStaking> for CosmosStdBootstrapComponents {
fn genesis_denom(genesis_config: &CosmosGenesisConfig) -> &Denom {
&genesis_config.staking_denom
fn genesis_denom(
bootstrap: &CosmosBootstrap,
_label: DenomForStaking,
_genesis_config: &CosmosGenesisConfig,
) -> Denom {
bootstrap.staking_denom.clone()
}
}

impl GenesisDenomGetter<CosmosBootstrap, DenomForTransfer> for CosmosStdBootstrapComponents {
fn genesis_denom(genesis_config: &CosmosGenesisConfig) -> &Denom {
&genesis_config.transfer_denom
fn genesis_denom(
bootstrap: &CosmosBootstrap,
_label: DenomForTransfer,
_genesis_config: &CosmosGenesisConfig,
) -> Denom {
bootstrap.transfer_denom.clone()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub struct CosmosChainDriver {
pub relayer_chain_config: ChainConfig,
pub chain_config: CosmosChainConfig,
pub genesis_config: CosmosGenesisConfig,
pub staking_denom: Denom,
pub transfer_denom: Denom,
pub relayer_wallet: CosmosTestWallet,
pub user_wallet_a: CosmosTestWallet,
pub user_wallet_b: CosmosTestWallet,
Expand Down Expand Up @@ -209,13 +211,13 @@ impl WalletGetterAt<CosmosChainDriver, UserWallet, 1> for CosmosChainDriverCompo

impl DenomGetterAt<CosmosChainDriver, TransferDenom, 0> for CosmosChainDriverComponents {
fn denom_at(driver: &CosmosChainDriver, _kind: TransferDenom, _index: Index<0>) -> &Denom {
&driver.genesis_config.transfer_denom
&driver.transfer_denom
}
}

impl DenomGetterAt<CosmosChainDriver, StakingDenom, 0> for CosmosChainDriverComponents {
fn denom_at(driver: &CosmosChainDriver, _kind: StakingDenom, _index: Index<0>) -> &Denom {
&driver.genesis_config.staking_denom
&driver.staking_denom
}
}

Expand Down
100 changes: 0 additions & 100 deletions crates/cosmos/cosmos-integration-tests/src/tests/bootstrap.rs

This file was deleted.

65 changes: 65 additions & 0 deletions crates/cosmos/cosmos-integration-tests/src/tests/celestia.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use core::time::Duration;
use std::sync::Arc;

use eyre::Error;
use hermes_cosmos_relayer::contexts::builder::CosmosBuilder;
use hermes_cosmos_test_components::chain_driver::types::denom::Denom;
use hermes_ibc_test_suite::tests::transfer::TestIbcTransfer;
use hermes_relayer_runtime::types::runtime::HermesRuntime;
use hermes_test_components::setup::traits::run_test::CanRunTest;
use ibc_relayer::chain::client::ClientSettings;
use ibc_relayer::chain::cosmos::client::Settings;
use ibc_relayer::config::compat_mode::CompatMode;
use ibc_relayer_types::core::ics02_client::trust_threshold::TrustThreshold;
use ibc_relayer_types::core::ics24_host::identifier::PortId;
use tokio::runtime::Builder;

use crate::contexts::binary_channel::setup::CosmosBinaryChannelSetup;
use crate::contexts::bootstrap::CosmosBootstrap;

#[test]
fn celestia_integration_tests() -> Result<(), Error> {
let _ = stable_eyre::install();

let tokio_runtime = Arc::new(Builder::new_multi_thread().enable_all().build()?);

let runtime = HermesRuntime::new(tokio_runtime.clone());

let builder = CosmosBuilder::new_with_default(runtime.clone());

let bootstrap = CosmosBootstrap {
runtime,
builder,
should_randomize_identifiers: true,
test_dir: "./test-data".into(),
chain_command_path: "celestia-appd".into(),
account_prefix: "celestia".into(),
compat_mode: Some(CompatMode::V0_34),
staking_denom: Denom::base("utia"),
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,
trust_threshold: TrustThreshold::ONE_THIRD,
});

let setup = CosmosBinaryChannelSetup {
bootstrap,
create_client_settings,
init_connection_options: Default::default(),
init_channel_options: Default::default(),
port_id: PortId::transfer(),
};

tokio_runtime.block_on(async move {
setup.run_test(&TestIbcTransfer).await?;

<Result<(), Error>>::Ok(())
})?;

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,40 @@ use std::sync::Arc;

use eyre::Error;
use hermes_cosmos_relayer::contexts::builder::CosmosBuilder;
use hermes_cosmos_test_components::chain_driver::types::denom::Denom;
use hermes_ibc_test_suite::tests::transfer::TestIbcTransfer;
use hermes_relayer_runtime::types::runtime::HermesRuntime;
use hermes_test_components::setup::traits::run_test::CanRunTest;
use ibc_relayer::chain::client::ClientSettings;
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::runtime::Builder;

use crate::contexts::binary_channel::setup::CosmosBinaryChannelSetup;
use crate::contexts::bootstrap::CosmosBootstrap;

#[test(flavor = "multi_thread")]
async fn test_setup_cosmos_chain() -> Result<(), Error> {
#[test]
fn cosmos_integration_tests() -> Result<(), Error> {
let _ = stable_eyre::install();

let tokio_runtime = Arc::new(Runtime::new()?);
let tokio_runtime = Arc::new(Builder::new_multi_thread().enable_all().build()?);

let runtime = HermesRuntime::new(tokio_runtime.clone());

let builder = CosmosBuilder::new_with_default(runtime.clone());

// TODO: load parameters from environment variables
let bootstrap = CosmosBootstrap {
runtime,
builder,
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(())),
};
Expand All @@ -50,7 +55,12 @@ async fn test_setup_cosmos_chain() -> Result<(), Error> {
port_id: PortId::transfer(),
};

setup.run_test(&TestIbcTransfer).await?;
// TODO: Use a test suite entry point for running multiple tests
tokio_runtime.block_on(async move {
setup.run_test(&TestIbcTransfer).await?;

<Result<(), Error>>::Ok(())
})?;

Ok(())
}
4 changes: 2 additions & 2 deletions crates/cosmos/cosmos-integration-tests/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod bootstrap;
pub mod setup;
pub mod celestia;
pub mod cosmos;
12 changes: 10 additions & 2 deletions crates/cosmos/cosmos-relayer/src/contexts/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,16 @@ impl CosmosBuilder {
let mut rpc_client =
HttpClient::new(tx_config.rpc_address.clone()).map_err(BaseError::tendermint_rpc)?;

let status = rpc_client.status().await.unwrap();
let compat_mode = CompatMode::from_version(status.node_info.version).unwrap();
let compat_mode = if let Some(compat_mode) = chain_config.compat_mode {
compat_mode.into()
} else {
let status = rpc_client
.status()
.await
.map_err(BaseError::tendermint_rpc)?;

CompatMode::from_version(status.node_info.version).map_err(BaseError::tendermint_rpc)?
};

rpc_client.set_compat_mode(compat_mode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ pub trait HasGenesisDenom<Label>: HasGenesisConfigType + HasChainDriverType
where
Self::ChainDriver: HasDenomType,
{
fn genesis_denom(chain_config: &Self::GenesisConfig) -> &Denom<Self::ChainDriver>;
fn genesis_denom(
&self,
label: Label,
chain_config: &Self::GenesisConfig,
) -> Denom<Self::ChainDriver>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ where
ChainDriver: HasDenomType<Denom = Denom>,
{
async fn generate_wallet_configs(
_bootstrap: &Bootstrap,
bootstrap: &Bootstrap,
genesis_config: &Bootstrap::GenesisConfig,
) -> Result<Vec<CosmosWalletConfig>, Bootstrap::Error> {
// TODO: allow for randomization of denoms and amount

let denom_for_staking =
<Bootstrap as HasGenesisDenom<DenomForStaking>>::genesis_denom(genesis_config);
let denom_for_staking = bootstrap.genesis_denom(DenomForStaking, genesis_config);

let denom_for_transfer =
<Bootstrap as HasGenesisDenom<DenomForTransfer>>::genesis_denom(genesis_config);
let denom_for_transfer = bootstrap.genesis_denom(DenomForTransfer, genesis_config);

let validator = CosmosWalletConfig {
wallet_id: "validator".to_owned(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::bootstrap::traits::initializers::init_genesis_config::GenesisConfigIn
use crate::bootstrap::traits::modifiers::modify_genesis_config::CanModifyCosmosGenesisConfig;
use crate::bootstrap::traits::types::genesis_config::HasGenesisConfigType;
use crate::bootstrap::types::genesis_config::CosmosGenesisConfig;
use crate::chain_driver::types::denom::Denom;

/// Parse the generated genesis JSON file, and allow the bootstrap context to modify the genesis config
pub struct UpdateCosmosGenesisConfig;
Expand Down Expand Up @@ -56,11 +55,7 @@ where

// TODO: generate random denom

let genesis_config = CosmosGenesisConfig {
config_json,
staking_denom: Denom::base("stake"),
transfer_denom: Denom::base("coin"),
};
let genesis_config = CosmosGenesisConfig { config_json };

Ok(genesis_config.into())
}
Expand Down
Loading

0 comments on commit 4148b92

Please sign in to comment.