diff --git a/tools/integration-test/src/types/mod.rs b/tools/integration-test/src/types/mod.rs index a1c1db153d..13fc3a8a54 100644 --- a/tools/integration-test/src/types/mod.rs +++ b/tools/integration-test/src/types/mod.rs @@ -12,7 +12,6 @@ pub mod binary; pub mod config; pub mod env; pub mod id; -pub mod nary; pub mod process; pub mod single; pub mod tagged; diff --git a/tools/integration-test/src/types/nary/chains.rs b/tools/integration-test/src/types/nary/chains.rs deleted file mode 100644 index afd815d16b..0000000000 --- a/tools/integration-test/src/types/nary/chains.rs +++ /dev/null @@ -1,149 +0,0 @@ -use core::convert::{From, TryFrom}; -use eyre::eyre; -use ibc_relayer::chain::handle::{ChainHandle, ProdChainHandle}; -use ibc_relayer::config::SharedConfig; -use ibc_relayer::foreign_client::ForeignClient; -use ibc_relayer::registry::SharedRegistry; -use std::path::PathBuf; - -use crate::error::Error; -use crate::types::binary::chains::ConnectedChains as BinaryConnectedChains; -use crate::types::single::node::FullNode; -use crate::types::tagged::*; -use crate::util::array::{try_into_array, try_into_nested_array}; - -#[derive(Clone)] -pub struct ConnectedChains { - pub config_path: PathBuf, - pub config: SharedConfig, - pub registry: SharedRegistry, - pub chain_handles: [Handle; SIZE], - pub full_nodes: [FullNode; SIZE], - pub foreign_clients: [[ForeignClient; SIZE]; SIZE], -} - -#[derive(Clone)] -pub struct DynamicConnectedChains { - pub config_path: PathBuf, - pub config: SharedConfig, - pub registry: SharedRegistry, - pub chain_handles: Vec, - pub full_nodes: Vec, - pub foreign_clients: Vec>>, -} - -pub struct Size; - -pub type TaggedHandle = MonoTagged, Handle>; - -pub type TaggedFullNode<'a, Handle, const TAG: usize> = - MonoTagged, &'a FullNode>; - -pub type TaggedForeignClient = - ForeignClient, Handle>, MonoTagged, Handle>>; - -impl ConnectedChains { - pub fn full_node_at(&self) -> Result, Error> { - let full_node = self.raw_full_node_at(POS)?; - Ok(MonoTagged::new(full_node)) - } - - pub fn chain_handle_at(&self) -> Result, Error> { - let handle = self.raw_chain_handle_at(POS)?; - Ok(MonoTagged::new(handle.clone())) - } - - pub fn foreign_client_at( - &self, - ) -> Result, Error> { - let client = self.raw_foreign_client_at(FIRST, SECOND)?; - - Ok(ForeignClient::restore( - client.id.clone(), - MonoTagged::new(client.dst_chain.clone()), - MonoTagged::new(client.src_chain.clone()), - )) - } - - pub fn raw_full_node_at(&self, pos: usize) -> Result<&FullNode, Error> { - if pos >= SIZE { - Err(eyre!("cannot get full_node beyond position {}", pos)) - } else { - self.full_nodes - .get(pos) - .ok_or_else(|| eyre!("failed to get chain handle at position {}", pos)) - } - } - - pub fn raw_chain_handle_at(&self, pos: usize) -> Result<&Handle, Error> { - if pos >= SIZE { - Err(eyre!("cannot get chain handle beyond position {}", pos)) - } else { - self.chain_handles - .get(pos) - .ok_or_else(|| eyre!("failed to get chain handle at position {}", pos)) - } - } - - pub fn raw_foreign_client_at( - &self, - pos_a: usize, - pos_b: usize, - ) -> Result<&ForeignClient, Error> { - if pos_a >= SIZE { - Err(eyre!("cannot get chain handle beyond position {}", pos_a)) - } else if pos_b >= SIZE { - Err(eyre!("cannot get chain handle beyond position {}", pos_b)) - } else { - self.foreign_clients - .get(pos_a) - .and_then(|slice| slice.get(pos_b)) - .ok_or_else(|| { - eyre!( - "failed to get foreign client at position {}, {}", - pos_a, - pos_b - ) - }) - } - } -} - -impl TryFrom> - for ConnectedChains -{ - type Error = Error; - - fn try_from(chains: DynamicConnectedChains) -> Result { - Ok(ConnectedChains { - config_path: chains.config_path, - config: chains.config, - registry: chains.registry, - chain_handles: try_into_array(chains.chain_handles)?, - full_nodes: try_into_array(chains.full_nodes)?, - foreign_clients: try_into_nested_array(chains.foreign_clients)?, - }) - } -} - -impl From> - for BinaryConnectedChains -{ - fn from(chains: ConnectedChains) -> Self { - let [handle_a, handle_b] = chains.chain_handles; - let [node_a, node_b] = chains.full_nodes; - let [[_, client_a_to_b], [client_b_to_a, _]] = chains.foreign_clients; - - BinaryConnectedChains { - config_path: chains.config_path, - config: chains.config, - registry: chains.registry, - handle_a, - handle_b, - node_a: MonoTagged::new(node_a), - node_b: MonoTagged::new(node_b), - client_a_to_b, - client_b_to_a, - } - } -} diff --git a/tools/integration-test/src/types/nary/channel.rs b/tools/integration-test/src/types/nary/channel.rs deleted file mode 100644 index 0b25901732..0000000000 --- a/tools/integration-test/src/types/nary/channel.rs +++ /dev/null @@ -1,157 +0,0 @@ -use core::convert::TryFrom; -use eyre::eyre; -use ibc::core::ics24_host::identifier::{ChannelId, PortChannelId, PortId}; -use ibc_relayer::chain::handle::ChainHandle; -use ibc_relayer::channel::Channel; -use ibc_relayer::connection::Connection; - -use super::chains::TaggedHandle; -use crate::error::Error; -use crate::types::binary::channel::ConnectedChannel as BinaryConnectedChannel; -use crate::types::binary::client::ConnectedClients; -use crate::types::binary::connection::ConnectedConnection; -use crate::types::tagged::*; -use crate::util::array::try_into_nested_array; - -#[derive(Debug, Clone)] -pub struct ConnectedChannels { - pub connections: [[Connection; SIZE]; SIZE], - pub channels: [[Channel; SIZE]; SIZE], - pub port_channel_ids: [[PortChannelId; SIZE]; SIZE], -} - -#[derive(Debug, Clone)] -pub struct DynamicConnectedChannels { - pub connections: Vec>>, - pub channels: Vec>>, - pub port_channel_ids: Vec>, -} - -pub type TaggedChannel = - Channel, TaggedHandle>; - -pub type TaggedChannelId = - DualTagged, TaggedHandle, ChannelId>; - -pub type TaggedPortId = - DualTagged, TaggedHandle, PortId>; - -pub type TaggedPortChannelId = - DualTagged, TaggedHandle, PortChannelId>; - -impl ConnectedChannels { - pub fn channel_at( - &self, - ) -> Result, Error> { - let raw_channel = self.raw_channel_at(FIRST, SECOND)?.clone(); - - let channel = raw_channel.map_chain(MonoTagged::new, MonoTagged::new); - - Ok(channel) - } - - pub fn port_channel_id_at( - &self, - ) -> Result, Error> { - let raw_port_channel_id = self.raw_port_channel_id_at(FIRST, SECOND)?.clone(); - - Ok(DualTagged::new(raw_port_channel_id)) - } - - pub fn raw_channel_at( - &self, - first: usize, - second: usize, - ) -> Result<&Channel, Error> { - if first >= SIZE { - Err(eyre!("cannot get channel beyond position {}", first)) - } else if second >= SIZE { - Err(eyre!("cannot get channel beyond position {}", second)) - } else { - self.channels - .get(first) - .and_then(|slice| slice.get(second)) - .ok_or_else(|| { - eyre!( - "failed to get foreign client at position {}, {}", - first, - second - ) - }) - } - } - - pub fn raw_port_channel_id_at( - &self, - first: usize, - second: usize, - ) -> Result<&PortChannelId, Error> { - if first >= SIZE { - Err(eyre!( - "cannot get port channel id beyond position {}", - first - )) - } else if second >= SIZE { - Err(eyre!( - "cannot get port channel id beyond position {}", - second - )) - } else { - self.port_channel_ids - .get(first) - .and_then(|slice| slice.get(second)) - .ok_or_else(|| { - eyre!( - "failed to get foreign client at position {}, {}", - first, - second - ) - }) - } - } -} - -impl TryFrom> - for ConnectedChannels -{ - type Error = Error; - - fn try_from(channels: DynamicConnectedChannels) -> Result { - Ok(ConnectedChannels { - connections: try_into_nested_array(channels.connections)?, - channels: try_into_nested_array(channels.channels)?, - port_channel_ids: try_into_nested_array(channels.port_channel_ids)?, - }) - } -} - -impl From> - for BinaryConnectedChannel -{ - fn from(channels: ConnectedChannels) -> Self { - let [[_, connection], _] = channels.connections; - let [[_, channel], _] = channels.channels; - let [[_, port_channel_id_a], [port_channel_id_b, _]] = channels.port_channel_ids; - - let connection = ConnectedConnection { - client: ConnectedClients { - client_id_a: DualTagged::new(channel.a_side.client_id().clone()), - client_id_b: DualTagged::new(channel.b_side.client_id().clone()), - }, - - connection, - - connection_id_a: DualTagged::new(channel.a_side.connection_id().clone()), - connection_id_b: DualTagged::new(channel.b_side.connection_id().clone()), - }; - - Self { - connection, - channel, - channel_id_a: DualTagged::new(port_channel_id_a.channel_id), - channel_id_b: DualTagged::new(port_channel_id_b.channel_id), - port_a: DualTagged::new(port_channel_id_a.port_id), - port_b: DualTagged::new(port_channel_id_b.port_id), - } - } -} diff --git a/tools/integration-test/src/types/nary/mod.rs b/tools/integration-test/src/types/nary/mod.rs deleted file mode 100644 index fc1839801c..0000000000 --- a/tools/integration-test/src/types/nary/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod chains; -pub mod channel; diff --git a/tools/integration-test/src/util/array.rs b/tools/integration-test/src/util/array.rs deleted file mode 100644 index 5c2828c976..0000000000 --- a/tools/integration-test/src/util/array.rs +++ /dev/null @@ -1,63 +0,0 @@ -use core::convert::TryInto; -use eyre::eyre; - -use crate::error::Error; - -pub fn try_into_array(list: Vec) -> Result<[T; SIZE], Error> { - list.try_into() - .map_err(|_| eyre!("vector is not of length {}", SIZE)) -} - -pub fn try_into_nested_array( - list: Vec>, -) -> Result<[[T; SIZE]; SIZE], Error> { - let list_a = list - .into_iter() - .map(try_into_array) - .collect::, _>>()?; - - try_into_array(list_a) -} - -pub fn into_nested_vec(array: [[T; SIZE]; SIZE]) -> Vec> { - array.map(|array_b| array_b.into()).into() -} - -pub fn map_nested_array( - array: [[T; SIZE]; SIZE], - mapper: impl Fn(T) -> Result, -) -> Result<[[R; SIZE]; SIZE], Error> { - let mapped = into_nested_vec(array) - .into_iter() - .map(|inner| { - inner - .into_iter() - .map(&mapper) - .collect::, _>>() - }) - .collect::, _>>()?; - - try_into_nested_array(mapped) -} - -pub fn assert_same_dimension(size: usize, list: &[Vec]) -> Result<(), Error> { - if list.len() != size { - return Err(eyre!( - "expect nested vector to have the dimension {} x {}", - size, - size - )); - } - - for list_b in list.iter() { - if list_b.len() != size { - return Err(eyre!( - "expect nested vector to have the dimension {} x {}", - size, - size - )); - } - } - - Ok(()) -} diff --git a/tools/integration-test/src/util/mod.rs b/tools/integration-test/src/util/mod.rs index 98fac1ef9c..0de6fc6fe7 100644 --- a/tools/integration-test/src/util/mod.rs +++ b/tools/integration-test/src/util/mod.rs @@ -2,7 +2,6 @@ Utility and helper functions used in the tests. */ -pub mod array; pub mod file; pub mod random; pub mod retry;