Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate legacy tests #495

Merged
merged 9 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions .github/workflows/integration-tests-legacy.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ members = [

"crates/mock/mock-relayer",

#"tools/integration-test",
#"tools/test-framework",

"crates/ibc/ibc-components",
"crates/ibc/ibc-token-transfer-components",
"crates/ibc/ibc-mock-chain",
Expand All @@ -81,7 +78,6 @@ ibc = { version = "0.56.0", default-features = false
ibc-client-tendermint = { version = "0.56.0", default-features = false }
ibc-proto = { version = "0.51.1", default-features = false }
ibc-relayer = { version = "0.29.3" }
ibc-relayer-types = { version = "0.29.3" }
ibc-telemetry = { version = "0.29.3" }
tendermint = { version = "0.40" }
tendermint-proto = { version = "0.40" }
Expand Down Expand Up @@ -193,7 +189,6 @@ hermes-ibc-mock-chain = { version = "0.1.0" }
# cgp-inner = { git = "https://github.com/contextgeneric/cgp.git" }

ibc-relayer = { git = "https://github.com/informalsystems/hermes.git" }
ibc-relayer-types = { git = "https://github.com/informalsystems/hermes.git" }
ibc-telemetry = { git = "https://github.com/informalsystems/hermes.git" }

hermes-chain-components = { path = "./crates/chain/chain-components" }
Expand Down
2 changes: 1 addition & 1 deletion crates/cosmos/cosmos-chain-components/src/impls/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ where
}

fn write_acknowledgement(event: &WriteAckEvent) -> &Vec<u8> {
&event.packet.data
&event.acknowledgment
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use std::collections::HashMap;

use ibc::core::host::types::identifiers::{ChannelId, PortId};

#[derive(Clone, Default)]
pub struct PacketFilterConfig;
pub struct PacketFilterConfig {
pub filter_map: HashMap<(ChannelId, PortId), bool>,
}

impl PacketFilterConfig {
pub fn new(filter_map: HashMap<(ChannelId, PortId), bool>) -> Self {
Self { filter_map }
}
}

impl PacketFilterConfig {
/// TODO: Use proper packet filtering
pub fn is_allowed(&self, _port_id: &PortId, _channel_id: &ChannelId) -> bool {
true
pub fn is_allowed(&self, port_id: &PortId, channel_id: &ChannelId) -> bool {
*self
.filter_map
.get(&(channel_id.clone(), port_id.clone()))
.unwrap_or(&true)
}
}
74 changes: 56 additions & 18 deletions crates/cosmos/cosmos-integration-tests/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ use std::str::FromStr;

use eyre::Report;
use hermes_cosmos_chain_components::types::config::gas::dynamic_gas_config::DynamicGasConfig;
use hermes_cosmos_chain_components::types::messages::packet::packet_filter::PacketFilterConfig;
use hermes_cosmos_relayer::contexts::build::CosmosBuilder;
use hermes_error::types::Error;
use hermes_runtime::types::runtime::HermesRuntime;
use hermes_test_components::setup::traits::driver::{CanBuildTestDriver, HasTestDriverType};
use hermes_test_components::setup::traits::driver::CanBuildTestDriver;
use ibc::core::host::types::identifiers::PortId;
use serde_json::Value as JsonValue;
use tokio::runtime::Builder;
use toml::Value as TomlValue;
use tracing::info;
use tracing::level_filters::LevelFilter;
use tracing::{info, Subscriber};
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, EnvFilter};
Expand Down Expand Up @@ -42,17 +43,22 @@ impl FromStr for TestPreset {
}
}

pub fn init_test_runtime() -> HermesRuntime {
let _ = stable_eyre::install();

pub fn build_tracing_subscriber() -> impl Subscriber + Send + Sync {
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();

tracing_subscriber::registry()
.with(fmt::layer())
.with(env_filter)
.init();
}

pub fn init_test_runtime() -> HermesRuntime {
let _ = stable_eyre::install();

let subscriber = build_tracing_subscriber();
// Avoid crashing if already initialised
let _ = subscriber.try_init();

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

Expand All @@ -70,10 +76,17 @@ pub fn build_osmosis_bootstrap(
transfer_denom_prefix: String,
genesis_modifier: impl Fn(&mut JsonValue) -> Result<(), Error> + Send + Sync + 'static,
comet_config_modifier: impl Fn(&mut TomlValue) -> Result<(), Error> + Send + Sync + 'static,
packet_filter: PacketFilterConfig,
) -> LegacyCosmosBootstrap {
let dynamic_gas_config = Some(DynamicGasConfig::new(1.1, 1.6, "osmosis", "stake"));

let cosmos_builder = CosmosBuilder::new_with_default(runtime.clone());
let cosmos_builder = CosmosBuilder::new(
Default::default(),
runtime.clone(),
Default::default(),
packet_filter,
Default::default(),
Default::default(),
);

LegacyCosmosBootstrap {
fields: Arc::new(LegacyCosmosBootstrapFields {
Expand All @@ -100,9 +113,17 @@ pub fn build_gaia_bootstrap(
transfer_denom_prefix: String,
genesis_modifier: impl Fn(&mut JsonValue) -> Result<(), Error> + Send + Sync + 'static,
comet_config_modifier: impl Fn(&mut TomlValue) -> Result<(), Error> + Send + Sync + 'static,
packet_filter: PacketFilterConfig,
) -> CosmosBootstrap {
let dynamic_gas_config = Some(DynamicGasConfig::default());
let cosmos_builder = CosmosBuilder::new_with_default(runtime.clone());
let cosmos_builder = CosmosBuilder::new(
Default::default(),
runtime.clone(),
Default::default(),
packet_filter,
Default::default(),
Default::default(),
);

CosmosBootstrap {
fields: Arc::new(CosmosBootstrapFields {
Expand All @@ -124,6 +145,7 @@ pub fn build_gaia_bootstrap(
async fn setup_gaia_to_gaia(
runtime: &HermesRuntime,
builder: CosmosBuilder,
packet_filter: PacketFilterConfig,
) -> Result<CosmosBinaryChannelTestDriver, Error> {
let bootstrap_chain_0 = build_gaia_bootstrap(
runtime.clone(),
Expand All @@ -132,6 +154,7 @@ async fn setup_gaia_to_gaia(
"coin".into(),
|_| Ok(()),
|_| Ok(()),
packet_filter.clone(),
);

let bootstrap_chain_1 = build_gaia_bootstrap(
Expand All @@ -141,6 +164,7 @@ async fn setup_gaia_to_gaia(
"coin".into(),
|_| Ok(()),
|_| Ok(()),
packet_filter,
);

let setup = CosmosBinaryChannelSetup {
Expand All @@ -159,6 +183,7 @@ async fn setup_gaia_to_gaia(
async fn setup_osmosis_to_osmosis(
runtime: &HermesRuntime,
builder: CosmosBuilder,
packet_filter: PacketFilterConfig,
) -> Result<CosmosBinaryChannelTestDriver, Error> {
let bootstrap_chain_0 = build_osmosis_bootstrap(
runtime.clone(),
Expand All @@ -167,6 +192,7 @@ async fn setup_osmosis_to_osmosis(
"coin".into(),
|_| Ok(()),
|_| Ok(()),
packet_filter.clone(),
);

let bootstrap_chain_1 = build_osmosis_bootstrap(
Expand All @@ -176,6 +202,7 @@ async fn setup_osmosis_to_osmosis(
"coin".into(),
|_| Ok(()),
|_| Ok(()),
packet_filter,
);

let setup = CosmosBinaryChannelSetup {
Expand All @@ -194,6 +221,7 @@ async fn setup_osmosis_to_osmosis(
async fn setup_osmosis_to_gaia(
runtime: &HermesRuntime,
builder: CosmosBuilder,
packet_filter: PacketFilterConfig,
) -> Result<CosmosBinaryChannelTestDriver, Error> {
let bootstrap_chain_0 = build_osmosis_bootstrap(
runtime.clone(),
Expand All @@ -202,6 +230,7 @@ async fn setup_osmosis_to_gaia(
"coin".into(),
|_| Ok(()),
|_| Ok(()),
packet_filter.clone(),
);

let bootstrap_chain_1 = build_gaia_bootstrap(
Expand All @@ -211,6 +240,7 @@ async fn setup_osmosis_to_gaia(
"coin".into(),
|_| Ok(()),
|_| Ok(()),
packet_filter,
);

let setup = CosmosBinaryChannelSetup {
Expand All @@ -226,20 +256,28 @@ async fn setup_osmosis_to_gaia(
setup.build_driver().await
}

pub async fn init_preset_bootstraps<Setup>(
pub async fn init_preset_bootstraps(
runtime: &HermesRuntime,
) -> Result<Setup::TestDriver, Error>
where
Setup: HasTestDriverType<TestDriver = CosmosBinaryChannelTestDriver>,
{
packet_filter: PacketFilterConfig,
) -> Result<CosmosBinaryChannelTestDriver, Error> {
let test_preset = env::var("TEST_PRESET")
.unwrap_or_else(|_| "GaiaToGaia".to_string())
.parse::<TestPreset>()?;
let builder = CosmosBuilder::new_with_default(runtime.clone());

let builder = CosmosBuilder::new(
Default::default(),
runtime.clone(),
Default::default(),
packet_filter.clone(),
Default::default(),
Default::default(),
);

match test_preset {
TestPreset::GaiaToGaia => setup_gaia_to_gaia(runtime, builder).await,
TestPreset::OsmosisToOsmosis => setup_osmosis_to_osmosis(runtime, builder).await,
TestPreset::OsmosisToGaia => setup_osmosis_to_gaia(runtime, builder).await,
TestPreset::GaiaToGaia => setup_gaia_to_gaia(runtime, builder, packet_filter).await,
TestPreset::OsmosisToOsmosis => {
setup_osmosis_to_osmosis(runtime, builder, packet_filter).await
}
TestPreset::OsmosisToGaia => setup_osmosis_to_gaia(runtime, builder, packet_filter).await,
}
}
2 changes: 2 additions & 0 deletions crates/cosmos/cosmos-integration-tests/tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn test_cosmos_bootstrap() -> Result<(), Error> {
"coin".into(),
|_| Ok(()),
|_| Ok(()),
Default::default(),
));

let bootstrap_legacy = Arc::new(build_osmosis_bootstrap(
Expand All @@ -26,6 +27,7 @@ fn test_cosmos_bootstrap() -> Result<(), Error> {
"coin".into(),
|_| Ok(()),
|_| Ok(()),
Default::default(),
));

runtime.runtime.clone().block_on(async move {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![recursion_limit = "256"]

use hermes_cosmos_integration_tests::contexts::binary_channel::setup::CosmosBinaryChannelSetup;
use hermes_cosmos_integration_tests::contexts::binary_channel::test_driver::CosmosBinaryChannelTestDriver;
use hermes_cosmos_integration_tests::contexts::bootstrap::CosmosBootstrap;
use hermes_cosmos_integration_tests::init::{init_preset_bootstraps, init_test_runtime};
use hermes_error::types::Error;
use hermes_ibc_test_suite::tests::transfer::TestIbcTransfer;
Expand All @@ -14,10 +12,8 @@ fn cosmos_integration_tests() -> Result<(), Error> {

// TODO: Use a test suite entry point for running multiple tests
runtime.runtime.clone().block_on(async move {
let setup: CosmosBinaryChannelTestDriver = init_preset_bootstraps::<
CosmosBinaryChannelSetup<CosmosBootstrap, CosmosBootstrap>,
>(&runtime)
.await?;
let setup: CosmosBinaryChannelTestDriver =
init_preset_bootstraps(&runtime, Default::default()).await?;
TestIbcTransfer::run_test(&TestIbcTransfer, &setup).await?;

<Result<(), Error>>::Ok(())
Expand Down
Loading
Loading