From 037d93171b3a1e337a61bf265858f58f6f6a54c4 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 18 Dec 2024 17:33:32 +0000 Subject: [PATCH] Allow setting up Osmosis chains in e2e tests --- crates/tests/src/e2e/ibc_tests.rs | 27 +++++++++-- crates/tests/src/e2e/setup.rs | 80 +++++++++++++++++++++---------- 2 files changed, 79 insertions(+), 28 deletions(-) diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index fbe43bd699..058f666816 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -2139,14 +2139,19 @@ fn run_namada_cosmos( let ledger = start_namada_ledger_node_wait_wasm(&test, Some(0), Some(40))?; - // Cosmos - let test_cosmos = setup_cosmos(chain_type)?; - let cosmos = run_cosmos(&test_cosmos, true)?; - sleep(5); + let (cosmos, test_cosmos) = setup_and_boot_cosmos(chain_type)?; Ok((ledger, cosmos, test, test_cosmos)) } +fn setup_and_boot_cosmos( + chain_type: CosmosChainType, +) -> Result<(NamadaCmd, Test)> { + let test_cosmos = setup_cosmos(chain_type)?; + let cosmos = run_cosmos(&test_cosmos, true)?; + Ok((cosmos, test_cosmos)) +} + fn create_channel_with_hermes( hermes_dir: &TestDir, test_a: &Test, @@ -3487,3 +3492,17 @@ fn shielded_recv_memo_value( unreachable!() } } + +/// Basic Osmosis test that checks if the chain has been set up correctly. +#[test] +fn osmosis_basic() -> Result<()> { + let (osmosis, test_osmosis) = + setup_and_boot_cosmos(CosmosChainType::Osmosis)?; + + let _bg_osmosis = osmosis.background(); + sleep(5); + + check_cosmos_balance(&test_osmosis, COSMOS_USER, COSMOS_COIN, 1_000)?; + + Ok(()) +} diff --git a/crates/tests/src/e2e/setup.rs b/crates/tests/src/e2e/setup.rs index f9980aa5ac..39d25b9940 100644 --- a/crates/tests/src/e2e/setup.rs +++ b/crates/tests/src/e2e/setup.rs @@ -1341,9 +1341,46 @@ where pub enum CosmosChainType { Gaia(Option), CosmWasm, + Osmosis, } impl CosmosChainType { + fn genesis_cmd_args<'a>(&self, mut args: Vec<&'a str>) -> Vec<&'a str> { + if !matches!(self, CosmosChainType::Osmosis) { + args.insert(0, "genesis"); + } + args + } + + fn add_genesis_account_args<'a>( + &self, + account: &'a str, + coins: &'a str, + ) -> Vec<&'a str> { + self.genesis_cmd_args(vec!["add-genesis-account", account, coins]) + } + + fn gentx_args<'a>( + &self, + account: &'a str, + coins: &'a str, + chain_id: &'a str, + ) -> Vec<&'a str> { + self.genesis_cmd_args(vec![ + "gentx", + account, + coins, + "--keyring-backend", + "test", + "--chain-id", + chain_id, + ]) + } + + fn collect_gentxs_args<'a>(&self) -> Vec<&'a str> { + self.genesis_cmd_args(vec!["collect-gentxs"]) + } + pub fn chain_id(&self) -> String { match self { Self::Gaia(Some(suffix)) => { @@ -1351,6 +1388,7 @@ impl CosmosChainType { } Self::Gaia(_) => constants::GAIA_CHAIN_ID.to_string(), Self::CosmWasm => constants::COSMWASM_CHAIN_ID.to_string(), + Self::Osmosis => constants::OSMOSIS_CHAIN_ID.to_string(), } } @@ -1358,6 +1396,7 @@ impl CosmosChainType { match self { Self::Gaia(_) => "gaiad", Self::CosmWasm => "wasmd", + Self::Osmosis => "osmosisd", } } @@ -1365,6 +1404,9 @@ impl CosmosChainType { if chain_id == constants::COSMWASM_CHAIN_ID { return Ok(Self::CosmWasm); } + if chain_id == constants::OSMOSIS_CHAIN_ID { + return Ok(Self::Osmosis); + } match chain_id.strip_prefix(constants::GAIA_CHAIN_ID) { Some("") => Ok(Self::Gaia(None)), Some(suffix) => { @@ -1380,6 +1422,7 @@ impl CosmosChainType { match self { Self::Gaia(_) => "cosmos", Self::CosmWasm => "wasm", + Self::Osmosis => "osmo", } } @@ -1399,8 +1442,9 @@ impl CosmosChainType { // NB: ensure none of these ever conflict match self { Self::CosmWasm => 0, - Self::Gaia(None) => 1, - Self::Gaia(Some(off)) => 2 + *off, + Self::Osmosis => 1, + Self::Gaia(None) => 2, + Self::Gaia(Some(off)) => 3 + *off, } } } @@ -1451,47 +1495,34 @@ pub fn setup_cosmos(chain_type: CosmosChainType) -> Result { // Add tokens to a user account let account = find_cosmos_address(&test, constants::COSMOS_USER)?; - let args = [ - "genesis", - "add-genesis-account", - &account, - "100000000stake,1000samoleans", - ]; + let args = chain_type + .add_genesis_account_args(&account, "100000000stake,1000samoleans"); let mut cosmos = run_cosmos_cmd(&test, args, Some(10))?; cosmos.assert_success(); // Add the stake token to the relayer let account = find_cosmos_address(&test, constants::COSMOS_RELAYER)?; - let args = ["genesis", "add-genesis-account", &account, "10000stake"]; + let args = chain_type.add_genesis_account_args(&account, "10000stake"); let mut cosmos = run_cosmos_cmd(&test, args, Some(10))?; cosmos.assert_success(); // Add the stake token to the validator let validator = find_cosmos_address(&test, constants::COSMOS_VALIDATOR)?; - let args = [ - "genesis", - "add-genesis-account", - &validator, - "200000000000stake", - ]; + let args = + chain_type.add_genesis_account_args(&validator, "200000000000stake"); let mut cosmos = run_cosmos_cmd(&test, args, Some(10))?; cosmos.assert_success(); // stake - let args = [ - "genesis", - "gentx", + let args = chain_type.gentx_args( constants::COSMOS_VALIDATOR, "100000000000stake", - "--keyring-backend", - "test", - "--chain-id", &chain_id, - ]; + ); let mut cosmos = run_cosmos_cmd(&test, args, Some(10))?; cosmos.assert_success(); - let args = ["genesis", "collect-gentxs"]; + let args = chain_type.collect_gentxs_args(); let mut cosmos = run_cosmos_cmd(&test, args, Some(10))?; cosmos.assert_success(); @@ -1615,8 +1646,9 @@ pub mod constants { pub const APFEL: &str = "Apfel"; pub const KARTOFFEL: &str = "Kartoffel"; - // Gaia or CosmWasm + // Gaia or CosmWasm or Osmosis pub const GAIA_CHAIN_ID: &str = "gaia"; + pub const OSMOSIS_CHAIN_ID: &str = "osmosis"; pub const COSMWASM_CHAIN_ID: &str = "cosmwasm"; pub const COSMOS_USER: &str = "user"; pub const COSMOS_RELAYER: &str = "relayer";