diff --git a/Cargo.toml b/Cargo.toml index 4f3384533..c4c0367ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,33 +1,35 @@ [workspace] resolver = "2" +# members sorted by publishing order to `crates.io` members = [ - "ibc", - "ibc-data-types", - "ibc-primitives", - "ibc-core", - "ibc-clients", - "ibc-apps", - "ibc-testkit", - "ibc-query", "ibc-derive", - "ibc-core/ics02-client", + "ibc-primitives", + "ibc-core/ics24-host/types", + "ibc-core/ics26-routing/types", + "ibc-core/ics23-commitment/types", "ibc-core/ics02-client/types", - "ibc-core/ics03-connection", "ibc-core/ics03-connection/types", - "ibc-core/ics04-channel", "ibc-core/ics04-channel/types", - "ibc-core/ics23-commitment/types", - "ibc-core/ics24-host", - "ibc-core/ics24-host/types", - "ibc-core/ics24-host/cosmos", - "ibc-core/ics25-handler", "ibc-core/ics25-handler/types", + "ibc-core/ics02-client/context", + "ibc-core/ics24-host", "ibc-core/ics26-routing", - "ibc-core/ics26-routing/types", - "ibc-clients/ics07-tendermint", + "ibc-core/ics02-client", + "ibc-core/ics03-connection", + "ibc-core/ics04-channel", + "ibc-core/ics25-handler", + "ibc-core", "ibc-clients/ics07-tendermint/types", - "ibc-apps/ics20-transfer", + "ibc-clients/ics07-tendermint", + "ibc-clients", + "ibc-core/ics24-host/cosmos", "ibc-apps/ics20-transfer/types", + "ibc-apps/ics20-transfer", + "ibc-apps", + "ibc-data-types", + "ibc", + "ibc-query", + "ibc-testkit", ] exclude = [ "ci/cw-check", diff --git a/RELEASES.md b/RELEASES.md index dc6a55865..9a584f679 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,4 +1,3 @@ - ## Releases Our release process is as follows: @@ -33,8 +32,8 @@ Our release process is as follows: work. Fix any potential issues here and push them to the release PR. 7. Mark the PR as **Ready for Review** and incorporate feedback on the release. 8. Once approved, merge the PR, and pull the `main` branch. -9. Run `cargo publish -p ` for each package separately to publish - the crates. +9. Publish each package to crates.io by running `cargo publish -p ` + in the order specified in the workspace `Cargo.toml`. 10. Create a signed tag and push it to GitHub: `git tag -s -a vX.Y.Z`. In the tag message, write the version and the link to the corresponding section of the changelog. diff --git a/ci/cw-check/Cargo.lock b/ci/cw-check/Cargo.lock index 0f3cc0f4f..a9c9685a3 100644 --- a/ci/cw-check/Cargo.lock +++ b/ci/cw-check/Cargo.lock @@ -676,10 +676,8 @@ version = "0.48.0" dependencies = [ "bytes", "displaydoc", - "ibc-core-client-context", "ibc-core-client-types", "ibc-core-commitment-types", - "ibc-core-handler-types", "ibc-core-host-types", "ibc-primitives", "ibc-proto", diff --git a/ci/no-std-check/Cargo.lock b/ci/no-std-check/Cargo.lock index 08ed7b9de..d0f8b0fee 100644 --- a/ci/no-std-check/Cargo.lock +++ b/ci/no-std-check/Cargo.lock @@ -1274,10 +1274,8 @@ version = "0.48.0" dependencies = [ "bytes", "displaydoc", - "ibc-core-client-context", "ibc-core-client-types", "ibc-core-commitment-types", - "ibc-core-handler-types", "ibc-core-host-types", "ibc-primitives", "ibc-proto", diff --git a/ibc-apps/ics20-transfer/types/Cargo.toml b/ibc-apps/ics20-transfer/types/Cargo.toml index ad7af1ee6..150ba8d63 100644 --- a/ibc-apps/ics20-transfer/types/Cargo.toml +++ b/ibc-apps/ics20-transfer/types/Cargo.toml @@ -36,7 +36,6 @@ parity-scale-codec = { workspace = true , optional = true } scale-info = { workspace = true , optional = true } [dev-dependencies] -ibc-testkit = { workspace = true } serde_json = { workspace = true } rstest = { workspace = true } @@ -50,13 +49,11 @@ std = [ "primitive-types/std", "ibc-core/std", "ibc-proto/std", - "ibc-testkit/std", ] serde = [ "dep:serde", "ibc-core/serde", "ibc-proto/serde", - "ibc-testkit/serde" ] schema = [ "dep:schemars", diff --git a/ibc-apps/ics20-transfer/types/src/packet.rs b/ibc-apps/ics20-transfer/types/src/packet.rs index d9d1ace76..cc8babc23 100644 --- a/ibc-apps/ics20-transfer/types/src/packet.rs +++ b/ibc-apps/ics20-transfer/types/src/packet.rs @@ -63,7 +63,6 @@ impl From for RawPacketData { #[cfg(test)] mod tests { - use ibc_testkit::utils::core::signer::dummy_bech32_account; use primitive_types::U256; use super::*; @@ -71,7 +70,9 @@ mod tests { impl PacketData { pub fn new_dummy() -> Self { - let address: Signer = dummy_bech32_account().into(); + let address: Signer = "cosmos1wxeyh7zgn4tctjzs0vtqpc6p5cxq5t2muzl7ng" + .to_string() + .into(); Self { token: BaseCoin { diff --git a/ibc-clients/ics07-tendermint/src/client_state.rs b/ibc-clients/ics07-tendermint/src/client_state.rs index 6f6dfdcb5..515ebf627 100644 --- a/ibc-clients/ics07-tendermint/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/src/client_state.rs @@ -503,7 +503,7 @@ mod tests { use core::time::Duration; use ibc_client_tendermint_types::{ - AllowUpdate, ClientState as ClientStateType, ClientStateParams, TrustThreshold, + AllowUpdate, ClientState as ClientStateType, TrustThreshold, }; use ibc_core_client::types::Height; use ibc_core_commitment_types::specs::ProofSpecs; @@ -511,6 +511,19 @@ mod tests { use super::*; + #[derive(Clone, Debug, PartialEq)] + pub struct ClientStateParams { + pub id: ChainId, + pub trust_level: TrustThreshold, + pub trusting_period: Duration, + pub unbonding_period: Duration, + pub max_clock_drift: Duration, + pub latest_height: Height, + pub proof_specs: ProofSpecs, + pub upgrade_path: Vec, + pub allow_update: AllowUpdate, + } + #[test] fn client_state_verify_height() { // Define a "default" set of parameters to reuse throughout these tests. diff --git a/ibc-clients/ics07-tendermint/types/Cargo.toml b/ibc-clients/ics07-tendermint/types/Cargo.toml index 55935dad4..68ec26b55 100644 --- a/ibc-clients/ics07-tendermint/types/Cargo.toml +++ b/ibc-clients/ics07-tendermint/types/Cargo.toml @@ -26,10 +26,8 @@ prost = { workspace = true } serde = { workspace = true, optional = true } # ibc dependencies -ibc-core-client-context = { workspace = true } ibc-core-client-types = { workspace = true } ibc-core-commitment-types = { workspace = true } -ibc-core-handler-types = { workspace = true } ibc-core-host-types = { workspace = true } ibc-primitives = { workspace = true } ibc-proto = { workspace = true } @@ -44,7 +42,6 @@ parity-scale-codec = { workspace = true, optional = true } scale-info = { workspace = true, optional = true } [dev-dependencies] -ibc-testkit = { workspace = true } serde_json = { workspace = true } tendermint-rpc = { workspace = true } @@ -56,10 +53,8 @@ std = [ "prost/std", "serde/std", "serde_json/std", - "ibc-core-client-context/std", "ibc-core-client-types/std", "ibc-core-commitment-types/std", - "ibc-core-handler-types/std", "ibc-core-host-types/std", "ibc-primitives/std", "ibc-proto/std", @@ -67,10 +62,8 @@ std = [ ] serde = [ "dep:serde", - "ibc-core-client-context/serde", "ibc-core-client-types/serde", "ibc-core-commitment-types/serde", - "ibc-core-handler-types/serde", "ibc-core-host-types/serde", "ibc-primitives/serde", "ibc-proto/serde", @@ -78,7 +71,6 @@ serde = [ schema = [ "ibc-core-client-types/schema", "ibc-core-commitment-types/schema", - "ibc-core-handler-types/schema", "ibc-core-host-types/schema", "ibc-primitives/schema", "ibc-proto/json-schema", @@ -89,7 +81,6 @@ borsh = [ "dep:borsh", "ibc-core-client-types/borsh", "ibc-core-commitment-types/borsh", - "ibc-core-handler-types/borsh", "ibc-core-host-types/borsh", "ibc-primitives/borsh", "ibc-proto/borsh", @@ -99,7 +90,6 @@ parity-scale-codec = [ "dep:scale-info", "ibc-core-client-types/parity-scale-codec", "ibc-core-commitment-types/parity-scale-codec", - "ibc-core-handler-types/parity-scale-codec", "ibc-core-host-types/parity-scale-codec", "ibc-primitives/parity-scale-codec", "ibc-proto/parity-scale-codec", diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index 172ffdba9..ba323a400 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -1,5 +1,4 @@ -//! Implements the core [`ClientState`](crate::core::ics02_client::client_state::ClientState) trait -//! for the Tendermint light client. +//! Contains the implementation of the Tendermint `ClientState` domain type. use core::cmp::max; use core::convert::{TryFrom, TryInto}; @@ -35,23 +34,7 @@ pub struct AllowUpdate { pub after_misbehaviour: bool, } -/// Parameters needed when initializing a new `ClientState`. This type -/// exists mainly as a convenience for providing default values in -/// testing scenarios. -#[derive(Clone, Debug, PartialEq)] -pub struct ClientStateParams { - pub id: ChainId, - pub trust_level: TrustThreshold, - pub trusting_period: Duration, - pub unbonding_period: Duration, - pub max_clock_drift: Duration, - pub latest_height: Height, - pub proof_specs: ProofSpecs, - pub upgrade_path: Vec, - pub allow_update: AllowUpdate, -} - -/// Contains the core implementation of the Tendermint light client +/// Defines data structure for Tendermint client state. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq)] pub struct ClientState { @@ -439,66 +422,23 @@ pub(crate) mod serde_tests { #[cfg(test)] mod tests { - use core::str::FromStr; use core::time::Duration; - use ibc_core_client_types::Height; - use ibc_core_commitment_types::specs::ProofSpecs; - use ibc_proto::google::protobuf::Any; - use ibc_proto::ibc::core::client::v1::Height as RawHeight; - use ibc_proto::ibc::lightclients::tendermint::v1::{ClientState as RawTmClientState, Fraction}; - use ibc_proto::ics23::ProofSpec as Ics23ProofSpec; - use ibc_testkit::utils::clients::tendermint::dummy_tendermint_header; - use tendermint::block::Header; + use ibc_core_commitment_types::proto::ics23::ProofSpec as Ics23ProofSpec; use super::*; - use crate::client_state::{AllowUpdate, ClientState}; - use crate::error::Error; - - impl ClientState { - pub fn new_dummy_from_raw(frozen_height: RawHeight) -> Result { - Self::try_from(get_dummy_raw_tm_client_state(frozen_height)) - } - - pub fn new_dummy_from_header(tm_header: Header) -> Self { - let chain_id = ChainId::from_str(tm_header.chain_id.as_str()).expect("Never fails"); - Self::new( - chain_id.clone(), - Default::default(), - Duration::from_secs(64000), - Duration::from_secs(128000), - Duration::from_millis(3000), - Height::new(chain_id.revision_number(), u64::from(tm_header.height)) - .expect("Never fails"), - Default::default(), - Default::default(), - AllowUpdate { - after_expiry: false, - after_misbehaviour: false, - }, - ) - .expect("Never fails") - } - } - pub fn get_dummy_raw_tm_client_state(frozen_height: RawHeight) -> RawTmClientState { - #[allow(deprecated)] - RawTmClientState { - chain_id: ChainId::new("ibc-0").expect("Never fails").to_string(), - trust_level: Some(Fraction { - numerator: 1, - denominator: 3, - }), - trusting_period: Some(Duration::from_secs(64000).into()), - unbonding_period: Some(Duration::from_secs(128000).into()), - max_clock_drift: Some(Duration::from_millis(3000).into()), - latest_height: Some(Height::new(0, 10).expect("Never fails").into()), - proof_specs: ProofSpecs::default().into(), - upgrade_path: Default::default(), - frozen_height: Some(frozen_height), - allow_update_after_expiry: false, - allow_update_after_misbehaviour: false, - } + #[derive(Clone, Debug, PartialEq)] + pub struct ClientStateParams { + pub id: ChainId, + pub trust_level: TrustThreshold, + pub trusting_period: Duration, + pub unbonding_period: Duration, + pub max_clock_drift: Duration, + pub latest_height: Height, + pub proof_specs: ProofSpecs, + pub upgrade_path: Vec, + pub allow_update: AllowUpdate, } #[test] @@ -644,7 +584,7 @@ mod tests { for test in tests { let p = test.params.clone(); - let cs_result = ClientState::new( + let cs_result: Result = ClientState::new( p.id, p.trust_level, p.trusting_period, @@ -666,50 +606,4 @@ mod tests { ); } } - - #[test] - fn tm_client_state_conversions_healthy() { - // check client state creation path from a proto type - let tm_client_state_from_raw = ClientState::new_dummy_from_raw(RawHeight { - revision_number: 0, - revision_height: 0, - }); - assert!(tm_client_state_from_raw.is_ok()); - - let any_from_tm_client_state = Any::from( - tm_client_state_from_raw - .as_ref() - .expect("Never fails") - .clone(), - ); - let tm_client_state_from_any = ClientState::try_from(any_from_tm_client_state); - assert!(tm_client_state_from_any.is_ok()); - assert_eq!( - tm_client_state_from_raw.expect("Never fails"), - tm_client_state_from_any.expect("Never fails") - ); - - // check client state creation path from a tendermint header - let tm_header = dummy_tendermint_header(); - let tm_client_state_from_header = ClientState::new_dummy_from_header(tm_header); - let any_from_header = Any::from(tm_client_state_from_header.clone()); - let tm_client_state_from_any = ClientState::try_from(any_from_header); - assert!(tm_client_state_from_any.is_ok()); - assert_eq!( - tm_client_state_from_header, - tm_client_state_from_any.expect("Never fails") - ); - } - - #[test] - fn tm_client_state_malformed_with_frozen_height() { - let tm_client_state_from_raw = ClientState::new_dummy_from_raw(RawHeight { - revision_number: 0, - revision_height: 10, - }); - match tm_client_state_from_raw { - Err(Error::FrozenHeightNotAllowed) => {} - _ => panic!("Expected to fail with FrozenHeightNotAllowed error"), - } - } } diff --git a/ibc-core/ics02-client/context/Cargo.toml b/ibc-core/ics02-client/context/Cargo.toml index 5a5f1d467..3b19788b7 100644 --- a/ibc-core/ics02-client/context/Cargo.toml +++ b/ibc-core/ics02-client/context/Cargo.toml @@ -35,9 +35,6 @@ ibc-primitives = { workspace = true } # cosmos dependencies tendermint = { workspace = true } -[dev-dependencies] -ibc-testkit = { workspace = true } - [features] default = ["std"] std = [ diff --git a/ibc-core/ics02-client/types/Cargo.toml b/ibc-core/ics02-client/types/Cargo.toml index f4cb72346..8b01bbca1 100644 --- a/ibc-core/ics02-client/types/Cargo.toml +++ b/ibc-core/ics02-client/types/Cargo.toml @@ -40,9 +40,6 @@ tendermint = { workspace = true } parity-scale-codec = { workspace = true, optional = true } scale-info = { workspace = true, optional = true } -[dev-dependencies] -ibc-testkit = { workspace = true } - [features] default = ["std"] std = [ diff --git a/ibc-core/ics02-client/types/src/events.rs b/ibc-core/ics02-client/types/src/events.rs index f9ae7213c..d7c7545c1 100644 --- a/ibc-core/ics02-client/types/src/events.rs +++ b/ibc-core/ics02-client/types/src/events.rs @@ -8,10 +8,10 @@ use tendermint::abci; use crate::height::Height; /// Client event types -const CREATE_CLIENT_EVENT: &str = "create_client"; -const UPDATE_CLIENT_EVENT: &str = "update_client"; -const CLIENT_MISBEHAVIOUR_EVENT: &str = "client_misbehaviour"; -const UPGRADE_CLIENT_EVENT: &str = "upgrade_client"; +pub const CREATE_CLIENT_EVENT: &str = "create_client"; +pub const UPDATE_CLIENT_EVENT: &str = "update_client"; +pub const CLIENT_MISBEHAVIOUR_EVENT: &str = "client_misbehaviour"; +pub const UPGRADE_CLIENT_EVENT: &str = "upgrade_client"; /// The content of the `key` field for the attribute containing the client identifier. pub const CLIENT_ID_ATTRIBUTE_KEY: &str = "client_id"; @@ -416,102 +416,3 @@ impl From for abci::Event { } } } - -#[cfg(test)] -mod tests { - use core::str::FromStr; - - use ibc_proto::google::protobuf::Any; - use ibc_testkit::utils::clients::mock::dummy_new_mock_header; - use prost::Message; - use tendermint::abci::Event as AbciEvent; - - use super::*; - - #[test] - fn ibc_to_abci_client_events() { - struct Test { - event_kind: &'static str, - event: AbciEvent, - expected_keys: Vec<&'static str>, - expected_values: Vec<&'static str>, - } - - let client_type = ClientType::from_str("07-tendermint") - .expect("never fails because it's a valid client type"); - let client_id = ClientId::new(client_type.clone(), 0).unwrap(); - let consensus_height = Height::new(0, 5).unwrap(); - let consensus_heights = vec![Height::new(0, 5).unwrap(), Height::new(0, 7).unwrap()]; - let header: Any = dummy_new_mock_header(5).into(); - let expected_keys = vec![ - "client_id", - "client_type", - "consensus_height", - "consensus_heights", - "header", - ]; - - let expected_values = vec![ - "07-tendermint-0", - "07-tendermint", - "0-5", - "0-5,0-7", - "0a102f6962632e6d6f636b2e48656164657212040a021005", - ]; - - let tests: Vec = vec![ - Test { - event_kind: CREATE_CLIENT_EVENT, - event: CreateClient::new(client_id.clone(), client_type.clone(), consensus_height) - .into(), - expected_keys: expected_keys[0..3].to_vec(), - expected_values: expected_values[0..3].to_vec(), - }, - Test { - event_kind: UPDATE_CLIENT_EVENT, - event: UpdateClient::new( - client_id.clone(), - client_type.clone(), - consensus_height, - consensus_heights, - header.encode_to_vec(), - ) - .into(), - expected_keys: expected_keys.clone(), - expected_values: expected_values.clone(), - }, - Test { - event_kind: UPGRADE_CLIENT_EVENT, - event: UpgradeClient::new(client_id.clone(), client_type.clone(), consensus_height) - .into(), - expected_keys: expected_keys[0..3].to_vec(), - expected_values: expected_values[0..3].to_vec(), - }, - Test { - event_kind: CLIENT_MISBEHAVIOUR_EVENT, - event: ClientMisbehaviour::new(client_id, client_type).into(), - expected_keys: expected_keys[0..2].to_vec(), - expected_values: expected_values[0..2].to_vec(), - }, - ]; - - for t in tests { - assert_eq!(t.event.kind, t.event_kind); - assert_eq!(t.expected_keys.len(), t.event.attributes.len()); - for (i, e) in t.event.attributes.iter().enumerate() { - assert_eq!( - e.key, t.expected_keys[i], - "key mismatch for {:?}", - t.event_kind - ); - } - for (i, e) in t.event.attributes.iter().enumerate() { - assert_eq!( - e.value, t.expected_values[i], - "value mismatch for {:?}", - t.event_kind - ); - } - } - } -} diff --git a/ibc-core/ics02-client/types/src/msgs/create_client.rs b/ibc-core/ics02-client/types/src/msgs/create_client.rs index 7c3347980..f20353c91 100644 --- a/ibc-core/ics02-client/types/src/msgs/create_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/create_client.rs @@ -70,22 +70,3 @@ impl From for RawMsgCreateClient { } } } - -#[cfg(test)] -mod tests { - - use ibc_proto::ibc::core::client::v1::MsgCreateClient as RawMsgCreateClient; - use ibc_testkit::utils::core::client::dummy_raw_msg_create_client; - - use crate::msgs::create_client::MsgCreateClient; - - #[test] - fn msg_create_client_serialization() { - let raw = dummy_raw_msg_create_client(); - let msg = MsgCreateClient::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgCreateClient::from(msg.clone()); - let msg_back = MsgCreateClient::try_from(raw_back.clone()).unwrap(); - assert_eq!(msg, msg_back); - assert_eq!(raw, raw_back); - } -} diff --git a/ibc-core/ics02-client/types/src/msgs/update_client.rs b/ibc-core/ics02-client/types/src/msgs/update_client.rs index 60c70cfc2..0e6a020ad 100644 --- a/ibc-core/ics02-client/types/src/msgs/update_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/update_client.rs @@ -63,22 +63,3 @@ impl From for RawMsgUpdateClient { } } } - -#[cfg(test)] -mod tests { - use ibc_proto::ibc::core::client::v1::MsgUpdateClient as RawMsgUpdateClient; - use ibc_testkit::utils::core::client::dummy_raw_msg_update_client; - - use super::*; - use crate::msgs::MsgUpdateClient; - - #[test] - fn msg_update_client_serialization() { - let raw = dummy_raw_msg_update_client(); - let msg = MsgUpdateClient::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgUpdateClient::from(msg.clone()); - let msg_back = MsgUpdateClient::try_from(raw_back.clone()).unwrap(); - assert_eq!(msg, msg_back); - assert_eq!(raw, raw_back); - } -} diff --git a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs index 2175a3cb4..cf8ed7506 100644 --- a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs @@ -95,21 +95,3 @@ impl TryFrom for MsgUpgradeClient { }) } } - -#[cfg(test)] -mod tests { - use ibc_proto::ibc::core::client::v1::MsgUpgradeClient as RawMsgUpgradeClient; - use ibc_testkit::utils::core::client::dummy_raw_msg_upgrade_client; - - use crate::msgs::upgrade_client::MsgUpgradeClient; - - #[test] - fn msg_upgrade_client_serialization() { - let raw = dummy_raw_msg_upgrade_client(); - let msg = MsgUpgradeClient::try_from(raw.clone()).unwrap(); - let raw_back: RawMsgUpgradeClient = RawMsgUpgradeClient::from(msg.clone()); - let msg_back = MsgUpgradeClient::try_from(raw_back.clone()).unwrap(); - assert_eq!(msg, msg_back); - assert_eq!(raw, raw_back); - } -} diff --git a/ibc-core/ics03-connection/types/Cargo.toml b/ibc-core/ics03-connection/types/Cargo.toml index f34d459bb..9f1f7379b 100644 --- a/ibc-core/ics03-connection/types/Cargo.toml +++ b/ibc-core/ics03-connection/types/Cargo.toml @@ -41,9 +41,6 @@ tendermint = { workspace = true } parity-scale-codec = { workspace = true, optional = true } scale-info = { workspace = true, optional = true } -[dev-dependencies] -ibc-testkit = { workspace = true } - [features] default = ["std"] std = [ diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs index 3ba244ed9..462648c88 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs @@ -128,96 +128,3 @@ impl From for RawMsgConnectionOpenAck { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::client::v1::Height; - use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; - use ibc_testkit::utils::core::connection::dummy_raw_msg_conn_open_ack; - - use crate::msgs::conn_open_ack::MsgConnectionOpenAck; - - #[test] - fn parse_connection_open_ack_msg() { - #[derive(Clone, Debug, PartialEq)] - struct Test { - name: String, - raw: RawMsgConnectionOpenAck, - want_pass: bool, - } - - let default_ack_msg = dummy_raw_msg_conn_open_ack(5, 5); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_ack_msg.clone(), - want_pass: true, - }, - Test { - name: "Bad connection id, non-alpha".to_string(), - raw: RawMsgConnectionOpenAck { - connection_id: "con007".to_string(), - ..default_ack_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad version, missing version".to_string(), - raw: RawMsgConnectionOpenAck { - version: None, - ..default_ack_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad proof height, height is 0".to_string(), - raw: RawMsgConnectionOpenAck { - proof_height: Some(Height { - revision_number: 1, - revision_height: 0, - }), - ..default_ack_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad consensus height, height is 0".to_string(), - raw: RawMsgConnectionOpenAck { - consensus_height: Some(Height { - revision_number: 1, - revision_height: 0, - }), - ..default_ack_msg - }, - want_pass: false, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let msg = MsgConnectionOpenAck::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - msg.is_ok(), - "MsgConnOpenAck::new failed for test {}, \nmsg {:?} with error {:?}", - test.name, - test.raw, - msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_conn_open_ack(5, 6); - let msg = MsgConnectionOpenAck::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgConnectionOpenAck::from(msg.clone()); - let msg_back = MsgConnectionOpenAck::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs index 545805c37..631a31b18 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs @@ -70,76 +70,3 @@ impl From for RawMsgConnectionOpenConfirm { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::client::v1::Height; - use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenConfirm as RawMsgConnectionOpenConfirm; - use ibc_testkit::utils::core::connection::dummy_raw_msg_conn_open_confirm; - - use crate::msgs::conn_open_confirm::MsgConnectionOpenConfirm; - - #[test] - fn parse_connection_open_confirm_msg() { - #[derive(Clone, Debug, PartialEq)] - struct Test { - name: String, - raw: RawMsgConnectionOpenConfirm, - want_pass: bool, - } - - let default_ack_msg = dummy_raw_msg_conn_open_confirm(); - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_ack_msg.clone(), - want_pass: true, - }, - Test { - name: "Bad connection id, non-alpha".to_string(), - raw: RawMsgConnectionOpenConfirm { - connection_id: "con007".to_string(), - ..default_ack_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad proof height, height is 0".to_string(), - raw: RawMsgConnectionOpenConfirm { - proof_height: Some(Height { - revision_number: 1, - revision_height: 0, - }), - ..default_ack_msg - }, - want_pass: false, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let msg = MsgConnectionOpenConfirm::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - msg.is_ok(), - "MsgConnOpenTry::new failed for test {}, \nmsg {:?} with error {:?}", - test.name, - test.raw, - msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_conn_open_confirm(); - let msg = MsgConnectionOpenConfirm::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgConnectionOpenConfirm::from(msg.clone()); - let msg_back = MsgConnectionOpenConfirm::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs index 1638fc8ae..8a1bbee57 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs @@ -126,121 +126,3 @@ impl From for RawMsgConnectionOpenInit { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::connection::v1::{ - Counterparty as RawCounterparty, MsgConnectionOpenInit as RawMsgConnectionOpenInit, - }; - use ibc_testkit::utils::core::connection::{ - dummy_raw_counterparty_conn, dummy_raw_msg_conn_open_init, - }; - - use super::MsgConnectionOpenInit; - - #[test] - fn parse_connection_open_init_msg() { - #[derive(Clone, Debug, PartialEq)] - struct Test { - name: String, - raw: RawMsgConnectionOpenInit, - want_pass: bool, - } - - let default_init_msg = dummy_raw_msg_conn_open_init(); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_init_msg.clone(), - want_pass: true, - }, - Test { - name: "Bad client id, name too short".to_string(), - raw: RawMsgConnectionOpenInit { - client_id: "client".to_string(), - ..default_init_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad destination connection id, name too long".to_string(), - raw: RawMsgConnectionOpenInit { - counterparty: Some(RawCounterparty { - connection_id: - "abcdefghijksdffjssdkflweldflsfladfsfwjkrekcmmsdfsdfjflddmnopqrstu" - .to_string(), - ..dummy_raw_counterparty_conn(None) - }), - ..default_init_msg - }, - want_pass: false, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let msg = MsgConnectionOpenInit::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - msg.is_ok(), - "MsgConnOpenInit::new failed for test {}, \nmsg {:?} with error {:?}", - test.name, - test.raw, - msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_conn_open_init(); - let msg = MsgConnectionOpenInit::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgConnectionOpenInit::from(msg.clone()); - let msg_back = MsgConnectionOpenInit::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - - // Check if handler sets counterparty connection id to `None` - // in case relayer passes `MsgConnectionOpenInit` message with it set to `Some(_)`. - let raw_with_counterparty_conn_id_some = dummy_raw_msg_conn_open_init(); - let msg_with_counterparty_conn_id_some = - MsgConnectionOpenInit::try_from(raw_with_counterparty_conn_id_some).unwrap(); - let raw_with_counterparty_conn_id_some_back = - RawMsgConnectionOpenInit::from(msg_with_counterparty_conn_id_some.clone()); - let msg_with_counterparty_conn_id_some_back = - MsgConnectionOpenInit::try_from(raw_with_counterparty_conn_id_some_back.clone()) - .unwrap(); - assert_eq!( - raw_with_counterparty_conn_id_some_back - .counterparty - .unwrap() - .connection_id, - "".to_string() - ); - assert_eq!( - msg_with_counterparty_conn_id_some, - msg_with_counterparty_conn_id_some_back - ); - } - - /// Test that borsh serialization/deserialization works well with delay periods up to u64::MAX - #[cfg(feature = "borsh")] - #[test] - fn test_borsh() { - let mut raw = dummy_raw_msg_conn_open_init(); - raw.delay_period = u64::MAX; - let msg = MsgConnectionOpenInit::try_from(raw.clone()).unwrap(); - - let serialized = borsh::to_vec(&msg).unwrap(); - - let msg_deserialized = - ::try_from_slice(&serialized) - .unwrap(); - - assert_eq!(msg, msg_deserialized); - } -} diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs index 4999f54c4..776a46f36 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs @@ -240,152 +240,3 @@ impl From for RawMsgConnectionOpenTry { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::client::v1::Height; - use ibc_proto::ibc::core::connection::v1::{ - Counterparty as RawCounterparty, MsgConnectionOpenTry as RawMsgConnectionOpenTry, - }; - use ibc_testkit::utils::core::connection::{ - dummy_raw_counterparty_conn, dummy_raw_msg_conn_open_try, - }; - - use crate::msgs::conn_open_try::MsgConnectionOpenTry; - - #[test] - fn parse_connection_open_try_msg() { - #[derive(Clone, Debug, PartialEq)] - struct Test { - name: String, - raw: RawMsgConnectionOpenTry, - want_pass: bool, - } - - let default_try_msg = dummy_raw_msg_conn_open_try(10, 34); - - let tests: Vec = - vec![ - Test { - name: "Good parameters".to_string(), - raw: default_try_msg.clone(), - want_pass: true, - }, - Test { - name: "Bad client id, name too short".to_string(), - raw: RawMsgConnectionOpenTry { - client_id: "client".to_string(), - ..default_try_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad destination connection id, name too long".to_string(), - raw: RawMsgConnectionOpenTry { - counterparty: Some(RawCounterparty { - connection_id: - "abcdasdfasdfsdfasfdwefwfsdfsfsfasfwewvxcvdvwgadvaadsefghijklmnopqrstu" - .to_string(), - ..dummy_raw_counterparty_conn(Some(0)) - }), - ..default_try_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Correct destination client id with lower/upper case and special chars" - .to_string(), - raw: RawMsgConnectionOpenTry { - counterparty: Some(RawCounterparty { - client_id: "ClientId_".to_string(), - ..dummy_raw_counterparty_conn(Some(0)) - }), - ..default_try_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad counterparty versions, empty versions vec".to_string(), - raw: RawMsgConnectionOpenTry { - counterparty_versions: Vec::new(), - ..default_try_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad counterparty versions, empty version string".to_string(), - raw: RawMsgConnectionOpenTry { - counterparty_versions: Vec::new(), - ..default_try_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad proof height, height is 0".to_string(), - raw: RawMsgConnectionOpenTry { - proof_height: Some(Height { revision_number: 1, revision_height: 0 }), - ..default_try_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad consensus height, height is 0".to_string(), - raw: RawMsgConnectionOpenTry { - proof_height: Some(Height { revision_number: 1, revision_height: 0 }), - ..default_try_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Empty proof".to_string(), - raw: RawMsgConnectionOpenTry { - proof_init: b"".to_vec(), - ..default_try_msg - }, - want_pass: false, - } - ] - .into_iter() - .collect(); - - for test in tests { - let msg = MsgConnectionOpenTry::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - msg.is_ok(), - "MsgConnOpenTry::new failed for test {}, \nmsg {:?} with error {:?}", - test.name, - test.raw, - msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_conn_open_try(10, 34); - let msg = MsgConnectionOpenTry::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgConnectionOpenTry::from(msg.clone()); - let msg_back = MsgConnectionOpenTry::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } - - /// Test that borsh serialization/deserialization works well with delay periods up to u64::MAX - #[cfg(feature = "borsh")] - #[test] - fn test_borsh() { - let mut raw = dummy_raw_msg_conn_open_try(10, 34); - raw.delay_period = u64::MAX; - let msg = MsgConnectionOpenTry::try_from(raw.clone()).unwrap(); - - let serialized = borsh::to_vec(&msg).unwrap(); - - let msg_deserialized = - ::try_from_slice(&serialized).unwrap(); - - assert_eq!(msg, msg_deserialized); - } -} diff --git a/ibc-core/ics04-channel/types/Cargo.toml b/ibc-core/ics04-channel/types/Cargo.toml index ab06daea0..bbd34da60 100644 --- a/ibc-core/ics04-channel/types/Cargo.toml +++ b/ibc-core/ics04-channel/types/Cargo.toml @@ -43,9 +43,6 @@ tendermint = { workspace = true } parity-scale-codec = { workspace = true, optional = true } scale-info = { workspace = true, optional = true } -[dev-dependencies] -ibc-testkit = { workspace = true } - [features] default = ["std"] std = [ diff --git a/ibc-core/ics04-channel/types/src/channel.rs b/ibc-core/ics04-channel/types/src/channel.rs index eed651870..aa0f3b633 100644 --- a/ibc-core/ics04-channel/types/src/channel.rs +++ b/ibc-core/ics04-channel/types/src/channel.rs @@ -565,148 +565,3 @@ impl Display for State { write!(f, "{}", self.as_string()) } } - -#[cfg(test)] -mod tests { - use core::str::FromStr; - - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::Channel as RawChannel; - use ibc_testkit::utils::core::channel::dummy_raw_channel_end; - - use crate::channel::ChannelEnd; - - #[test] - fn channel_end_try_from_raw() { - let raw_channel_end = dummy_raw_channel_end(2, Some(0)); - - let empty_raw_channel_end = RawChannel { - counterparty: None, - ..raw_channel_end.clone() - }; - - struct Test { - name: String, - params: RawChannel, - want_pass: bool, - } - - let tests: Vec = vec![ - Test { - name: "Raw channel end with missing counterparty".to_string(), - params: empty_raw_channel_end, - want_pass: false, - }, - Test { - name: "Raw channel end with incorrect state".to_string(), - params: RawChannel { - state: -1, - ..raw_channel_end.clone() - }, - want_pass: false, - }, - Test { - name: "Raw channel end with incorrect ordering".to_string(), - params: RawChannel { - ordering: -1, - ..raw_channel_end.clone() - }, - want_pass: false, - }, - Test { - name: "Raw channel end with incorrect connection id in connection hops".to_string(), - params: RawChannel { - connection_hops: vec!["connection*".to_string()].into_iter().collect(), - ..raw_channel_end.clone() - }, - want_pass: false, - }, - Test { - name: "Raw channel end with incorrect connection id (has blank space)".to_string(), - params: RawChannel { - connection_hops: vec!["con nection".to_string()].into_iter().collect(), - ..raw_channel_end.clone() - }, - want_pass: false, - }, - Test { - name: "Raw channel end with two correct connection ids in connection hops" - .to_string(), - params: RawChannel { - connection_hops: vec!["connection-1".to_string(), "connection-2".to_string()] - .into_iter() - .collect(), - ..raw_channel_end.clone() - }, - want_pass: true, - }, - Test { - name: "Raw channel end with correct params".to_string(), - params: raw_channel_end, - want_pass: true, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let p = test.params.clone(); - - let ce_result = ChannelEnd::try_from(p); - - assert_eq!( - test.want_pass, - ce_result.is_ok(), - "ChannelEnd::try_from() failed for test {}, \nmsg{:?} with error {:?}", - test.name, - test.params.clone(), - ce_result.err(), - ); - } - } - - #[test] - fn parse_channel_ordering_type() { - use super::Order; - - struct Test { - ordering: &'static str, - want_res: Order, - want_err: bool, - } - let tests: Vec = vec![ - Test { - ordering: "UNINITIALIZED", - want_res: Order::None, - want_err: false, - }, - Test { - ordering: "UNORDERED", - want_res: Order::Unordered, - want_err: false, - }, - Test { - ordering: "ORDERED", - want_res: Order::Ordered, - want_err: false, - }, - Test { - ordering: "UNKNOWN_ORDER", - want_res: Order::None, - want_err: true, - }, - ] - .into_iter() - .collect(); - - for test in tests { - match Order::from_str(test.ordering) { - Ok(res) => { - assert!(!test.want_err); - assert_eq!(test.want_res, res); - } - Err(_) => assert!(test.want_err, "parse failed"), - } - } - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs b/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs index 0b5be9ea8..50cba957e 100644 --- a/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs +++ b/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs @@ -74,79 +74,3 @@ impl From for RawMsgAcknowledgement { } } } - -#[cfg(test)] -mod test { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgAcknowledgement as RawMsgAcknowledgement; - use ibc_testkit::utils::core::channel::dummy_raw_msg_acknowledgement; - use ibc_testkit::utils::core::signer::dummy_bech32_account; - - use crate::error::PacketError; - use crate::msgs::acknowledgement::MsgAcknowledgement; - - #[test] - fn msg_acknowledgment_try_from_raw() { - struct Test { - name: String, - raw: RawMsgAcknowledgement, - want_pass: bool, - } - - let height = 50; - let default_raw_msg = dummy_raw_msg_acknowledgement(height); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_msg.clone(), - want_pass: true, - }, - Test { - name: "Missing packet".to_string(), - raw: RawMsgAcknowledgement { - packet: None, - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof height".to_string(), - raw: RawMsgAcknowledgement { - proof_height: None, - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Empty signer".to_string(), - raw: RawMsgAcknowledgement { - signer: dummy_bech32_account(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Empty proof acked".to_string(), - raw: RawMsgAcknowledgement { - proof_acked: Vec::new(), - ..default_raw_msg - }, - want_pass: false, - }, - ]; - - for test in tests { - let res_msg: Result = test.raw.clone().try_into(); - - assert_eq!( - res_msg.is_ok(), - test.want_pass, - "MsgAcknowledgement::try_from failed for test {} \nraw message: {:?} with error: {:?}", - test.name, - test.raw, - res_msg.err() - ); - } - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/chan_close_confirm.rs b/ibc-core/ics04-channel/types/src/msgs/chan_close_confirm.rs index 8c028cf11..f69ddf472 100644 --- a/ibc-core/ics04-channel/types/src/msgs/chan_close_confirm.rs +++ b/ibc-core/ics04-channel/types/src/msgs/chan_close_confirm.rs @@ -70,121 +70,3 @@ impl From for RawMsgChannelCloseConfirm { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm; - use ibc_proto::ibc::core::client::v1::Height; - use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_close_confirm; - - use crate::msgs::chan_close_confirm::MsgChannelCloseConfirm; - - #[test] - fn parse_channel_close_confirm_msg() { - struct Test { - name: String, - raw: RawMsgChannelCloseConfirm, - want_pass: bool, - } - - let proof_height = 10; - let default_raw_msg = dummy_raw_msg_chan_close_confirm(proof_height); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_msg.clone(), - want_pass: true, - }, - Test { - name: "Correct port".to_string(), - raw: RawMsgChannelCloseConfirm { - port_id: "p34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad port, name too short".to_string(), - raw: RawMsgChannelCloseConfirm { - port_id: "p".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad port, name too long".to_string(), - raw: RawMsgChannelCloseConfirm { - port_id: - "abcdefghijklmnsdfasdfasdfasdfasdgafgadsfasdfasdfasdasfdasdfsadfopqrstuabcdefghijklmnsdfasdfasdfasdfasdgafgadsfasdfasdfasdasfdasdfsadfopqrstu" - .to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Correct channel identifier".to_string(), - raw: RawMsgChannelCloseConfirm { - channel_id: "channel-34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad channel, name too short".to_string(), - raw: RawMsgChannelCloseConfirm { - channel_id: "chshort".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad channel, name too long".to_string(), - raw: RawMsgChannelCloseConfirm { - channel_id: - "channel-128391283791827398127398791283912837918273981273987912839" - .to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad proof height, height = 0".to_string(), - raw: RawMsgChannelCloseConfirm { - proof_height: Some(Height { - revision_number: 0, - revision_height: 0, - }), - ..default_raw_msg - }, - want_pass: false, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let msg = MsgChannelCloseConfirm::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - msg.is_ok(), - "MsgChanCloseConfirm::try_from raw failed for test {}, \nraw msg {:?} with error {:?}", - test.name, - test.raw, - msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_chan_close_confirm(19); - let msg = MsgChannelCloseConfirm::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgChannelCloseConfirm::from(msg.clone()); - let msg_back = MsgChannelCloseConfirm::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/chan_close_init.rs b/ibc-core/ics04-channel/types/src/msgs/chan_close_init.rs index dafc18dcb..c92cd5992 100644 --- a/ibc-core/ics04-channel/types/src/msgs/chan_close_init.rs +++ b/ibc-core/ics04-channel/types/src/msgs/chan_close_init.rs @@ -55,104 +55,3 @@ impl From for RawMsgChannelCloseInit { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgChannelCloseInit as RawMsgChannelCloseInit; - use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_close_init; - - use crate::msgs::chan_close_init::MsgChannelCloseInit; - - #[test] - fn parse_channel_close_init_msg() { - struct Test { - name: String, - raw: RawMsgChannelCloseInit, - want_pass: bool, - } - - let default_raw_msg = dummy_raw_msg_chan_close_init(); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_msg.clone(), - want_pass: true, - }, - Test { - name: "Correct port".to_string(), - raw: RawMsgChannelCloseInit { - port_id: "p34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad port, name too short".to_string(), - raw: RawMsgChannelCloseInit { - port_id: "p".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad port, name too long".to_string(), - raw: RawMsgChannelCloseInit { - port_id: "abcdefsdfasdfasdfasdfasdfasdfadsfasdgafsgadfasdfasdfasdfsdfasdfaghijklmnopqrstuabcdefsdfasdfasdfasdfasdfasdfadsfasdgafsgadfasdfasdfasdfsdfasdfaghijklmnopqrstu".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Correct channel identifier".to_string(), - raw: RawMsgChannelCloseInit { - channel_id: "channel-34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad channel, name too short".to_string(), - raw: RawMsgChannelCloseInit { - channel_id: "chshort".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad channel, name too long".to_string(), - raw: RawMsgChannelCloseInit { - channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), - ..default_raw_msg - }, - want_pass: false, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let msg = MsgChannelCloseInit::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - msg.is_ok(), - "MsgChanCloseInit::try_from failed for test {}, \nmsg {:?} with error {:?}", - test.name, - test.raw, - msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_chan_close_init(); - let msg = MsgChannelCloseInit::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgChannelCloseInit::from(msg.clone()); - let msg_back = MsgChannelCloseInit::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/chan_open_ack.rs b/ibc-core/ics04-channel/types/src/msgs/chan_open_ack.rs index c2f962d64..5ef4c5694 100644 --- a/ibc-core/ics04-channel/types/src/msgs/chan_open_ack.rs +++ b/ibc-core/ics04-channel/types/src/msgs/chan_open_ack.rs @@ -75,173 +75,3 @@ impl From for RawMsgChannelOpenAck { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgChannelOpenAck as RawMsgChannelOpenAck; - use ibc_proto::ibc::core::client::v1::Height; - use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_open_ack; - - use crate::msgs::chan_open_ack::MsgChannelOpenAck; - - #[test] - fn parse_channel_open_ack_msg() { - struct Test { - name: String, - raw: RawMsgChannelOpenAck, - want_pass: bool, - } - - let proof_height = 20; - let default_raw_msg = dummy_raw_msg_chan_open_ack(proof_height); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_msg.clone(), - want_pass: true, - }, - Test { - name: "Correct port identifier".to_string(), - raw: RawMsgChannelOpenAck { - port_id: "p34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad port, name too short".to_string(), - raw: RawMsgChannelOpenAck { - port_id: "p".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad port, name too long".to_string(), - raw: RawMsgChannelOpenAck { - port_id: "abcdezdfDfsdfgfddsfsfdsdfdfvxcvzxcvsgdfsdfwefwvsdfdsfdasgagadgsadgsdffghijklmnopqrstuabcdezdfDfsdfgfddsfsfdsdfdfvxcvzxcvsgdfsdfwefwvsdfdsfdasgagadgsadgsdffghijklmnopqrstu".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Correct channel identifier".to_string(), - raw: RawMsgChannelOpenAck { - channel_id: "channel-34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad channel, name too short".to_string(), - raw: RawMsgChannelOpenAck { - channel_id: "chshort".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad channel, name too long".to_string(), - raw: RawMsgChannelOpenAck { - channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "[Counterparty] Correct channel identifier".to_string(), - raw: RawMsgChannelOpenAck { - counterparty_channel_id: "channel-34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "[Counterparty] Bad channel, name too short".to_string(), - raw: RawMsgChannelOpenAck { - counterparty_channel_id: "chshort".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "[Counterparty] Bad channel, name too long".to_string(), - raw: RawMsgChannelOpenAck { - counterparty_channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Empty counterparty version (allowed)".to_string(), - raw: RawMsgChannelOpenAck { - counterparty_version: " ".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Arbitrary counterparty version (allowed)".to_string(), - raw: RawMsgChannelOpenAck { - counterparty_version: "v1.1.23-alpha".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad proof height, height = 0".to_string(), - raw: RawMsgChannelOpenAck { - proof_height: Some(Height { - revision_number: 0, - revision_height: 0, - }), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof height".to_string(), - raw: RawMsgChannelOpenAck { - proof_height: None, - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof try (object proof)".to_string(), - raw: RawMsgChannelOpenAck { - proof_try: Vec::new(), - ..default_raw_msg - }, - want_pass: false, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let res_msg = MsgChannelOpenAck::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - res_msg.is_ok(), - "MsgChanOpenAck::try_from raw failed for test {}, \nraw msg {:?} with error {:?}", - test.name, - test.raw, - res_msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_chan_open_ack(100); - let msg = MsgChannelOpenAck::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgChannelOpenAck::from(msg.clone()); - let msg_back = MsgChannelOpenAck::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/chan_open_confirm.rs b/ibc-core/ics04-channel/types/src/msgs/chan_open_confirm.rs index 8ff31e03a..cffc523b8 100644 --- a/ibc-core/ics04-channel/types/src/msgs/chan_open_confirm.rs +++ b/ibc-core/ics04-channel/types/src/msgs/chan_open_confirm.rs @@ -70,125 +70,3 @@ impl From for RawMsgChannelOpenConfirm { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm; - use ibc_proto::ibc::core::client::v1::Height; - use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_open_confirm; - - use crate::msgs::chan_open_confirm::MsgChannelOpenConfirm; - - #[test] - fn parse_channel_open_confirm_msg() { - struct Test { - name: String, - raw: RawMsgChannelOpenConfirm, - want_pass: bool, - } - - let proof_height = 78; - let default_raw_msg = dummy_raw_msg_chan_open_confirm(proof_height); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_msg.clone(), - want_pass: true, - }, - Test { - name: "Correct port".to_string(), - raw: RawMsgChannelOpenConfirm { - port_id: "p34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad port, name too short".to_string(), - raw: RawMsgChannelOpenConfirm { - port_id: "p".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad port, name too long".to_string(), - raw: RawMsgChannelOpenConfirm { - port_id: "abcdesdfasdsdffasdfasdfasfasdgasdfgasdfasdfasdfasdfasdfasdffghijklmnopqrstuabcdesdfasdsdffasdfasdfasfasdgasdfgasdfasdfasdfasdfasdfasdffghijklmnopqrstu".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Correct channel identifier".to_string(), - raw: RawMsgChannelOpenConfirm { - channel_id: "channel-34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad channel, name too short".to_string(), - raw: RawMsgChannelOpenConfirm { - channel_id: "chshort".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad channel, name too long".to_string(), - raw: RawMsgChannelOpenConfirm { - channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad proof height, height = 0".to_string(), - raw: RawMsgChannelOpenConfirm { - proof_height: Some(Height { - revision_number: 0, - revision_height: 0, - }), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing object proof".to_string(), - raw: RawMsgChannelOpenConfirm { - proof_ack: Vec::new(), - ..default_raw_msg - }, - want_pass: false, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let res_msg = MsgChannelOpenConfirm::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - res_msg.is_ok(), - "MsgChanOpenConfirm::try_from failed for test {}, \nraw msg {:?} with error {:?}", - test.name, - test.raw, - res_msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_chan_open_confirm(19); - let msg = MsgChannelOpenConfirm::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgChannelOpenConfirm::from(msg.clone()); - let msg_back = MsgChannelOpenConfirm::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/chan_open_init.rs b/ibc-core/ics04-channel/types/src/msgs/chan_open_init.rs index 2a11c07b9..aa5175eae 100644 --- a/ibc-core/ics04-channel/types/src/msgs/chan_open_init.rs +++ b/ibc-core/ics04-channel/types/src/msgs/chan_open_init.rs @@ -87,96 +87,3 @@ impl From for RawMsgChannelOpenInit { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgChannelOpenInit as RawMsgChannelOpenInit; - use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_open_init; - - use crate::msgs::chan_open_init::MsgChannelOpenInit; - - #[test] - fn channel_open_init_from_raw() { - struct Test { - name: String, - raw: RawMsgChannelOpenInit, - want_pass: bool, - } - - let default_raw_init_msg = dummy_raw_msg_chan_open_init(None); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_init_msg.clone(), - want_pass: true, - }, - Test { - name: "Incorrect port identifier, slash (separator) prohibited".to_string(), - raw: RawMsgChannelOpenInit { - port_id: "p34/".to_string(), - ..default_raw_init_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing channel".to_string(), - raw: RawMsgChannelOpenInit { - channel: None, - ..default_raw_init_msg - }, - want_pass: false, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let res_msg = MsgChannelOpenInit::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - res_msg.is_ok(), - "MsgChanOpenInit::try_from failed for test {}, \nraw msg {:?} with error {:?}", - test.name, - test.raw, - res_msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - // Check if raw and domain types are equal after conversions - let raw = dummy_raw_msg_chan_open_init(None); - let msg = MsgChannelOpenInit::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgChannelOpenInit::from(msg.clone()); - let msg_back = MsgChannelOpenInit::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - - // Check if handler sets counterparty channel id to `None` - // in case relayer passes `MsgChannelOpenInit` message with it set to `Some(_)` - let raw_with_counterparty_chan_id_some = dummy_raw_msg_chan_open_init(None); - let msg_with_counterparty_chan_id_some = - MsgChannelOpenInit::try_from(raw_with_counterparty_chan_id_some).unwrap(); - let raw_with_counterparty_chan_id_some_back = - RawMsgChannelOpenInit::from(msg_with_counterparty_chan_id_some.clone()); - let msg_with_counterparty_chan_id_some_back = - MsgChannelOpenInit::try_from(raw_with_counterparty_chan_id_some_back.clone()).unwrap(); - assert_eq!( - raw_with_counterparty_chan_id_some_back - .channel - .unwrap() - .counterparty - .unwrap() - .channel_id, - "".to_string() - ); - assert_eq!( - msg_with_counterparty_chan_id_some, - msg_with_counterparty_chan_id_some_back - ); - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs b/ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs index a671a5352..cb554ee00 100644 --- a/ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs +++ b/ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs @@ -124,125 +124,3 @@ impl From for RawMsgChannelOpenTry { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgChannelOpenTry as RawMsgChannelOpenTry; - use ibc_proto::ibc::core::client::v1::Height; - use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_open_try; - - use crate::msgs::chan_open_try::MsgChannelOpenTry; - - #[test] - fn channel_open_try_from_raw() { - struct Test { - name: String, - raw: RawMsgChannelOpenTry, - want_pass: bool, - } - - let proof_height = 10; - let default_raw_msg = dummy_raw_msg_chan_open_try(proof_height); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_msg.clone(), - want_pass: true, - }, - Test { - name: "Correct port".to_string(), - raw: RawMsgChannelOpenTry { - port_id: "p34".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad port, name too short".to_string(), - raw: RawMsgChannelOpenTry { - port_id: "p".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Bad port, name too long".to_string(), - raw: RawMsgChannelOpenTry { - port_id: "abcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfaabcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfa".to_string(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Empty counterparty version (valid choice)".to_string(), - raw: RawMsgChannelOpenTry { - counterparty_version: " ".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Arbitrary counterparty version (valid choice)".to_string(), - raw: RawMsgChannelOpenTry { - counterparty_version: "anyversion".to_string(), - ..default_raw_msg.clone() - }, - want_pass: true, - }, - Test { - name: "Bad proof height, height = 0".to_string(), - raw: RawMsgChannelOpenTry { - proof_height: Some(Height { - revision_number: 0, - revision_height: 0, - }), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof height".to_string(), - raw: RawMsgChannelOpenTry { - proof_height: None, - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof init (object proof)".to_string(), - raw: RawMsgChannelOpenTry { - proof_init: Vec::new(), - ..default_raw_msg - }, - want_pass: false, - }, - ] - .into_iter() - .collect(); - - for test in tests { - let res_msg = MsgChannelOpenTry::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - res_msg.is_ok(), - "MsgChanOpenTry::try_from failed for test {}, \nraw msg {:?} with error {:?}", - test.name, - test.raw, - res_msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_chan_open_try(10); - let msg = MsgChannelOpenTry::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgChannelOpenTry::from(msg.clone()); - let msg_back = MsgChannelOpenTry::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs b/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs index da5367036..cf4bc4d77 100644 --- a/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs +++ b/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs @@ -72,80 +72,3 @@ impl From for RawMsgRecvPacket { } } } - -#[cfg(test)] -mod test { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgRecvPacket as RawMsgRecvPacket; - use ibc_testkit::utils::core::channel::dummy_raw_msg_recv_packet; - use ibc_testkit::utils::core::signer::dummy_bech32_account; - - use crate::error::PacketError; - use crate::msgs::recv_packet::MsgRecvPacket; - - #[test] - fn msg_recv_packet_try_from_raw() { - struct Test { - name: String, - raw: RawMsgRecvPacket, - want_pass: bool, - } - - let height = 20; - let default_raw_msg = dummy_raw_msg_recv_packet(height); - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_msg.clone(), - want_pass: true, - }, - Test { - name: "Missing proof".to_string(), - raw: RawMsgRecvPacket { - proof_commitment: Vec::new(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof height".to_string(), - raw: RawMsgRecvPacket { - proof_height: None, - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Empty signer".to_string(), - raw: RawMsgRecvPacket { - signer: dummy_bech32_account(), - ..default_raw_msg - }, - want_pass: true, - }, - ]; - - for test in tests { - let res_msg: Result = test.raw.clone().try_into(); - - assert_eq!( - res_msg.is_ok(), - test.want_pass, - "MsgRecvPacket::try_from failed for test {} \nraw message: {:?} with error: {:?}", - test.name, - test.raw, - res_msg.err() - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_msg_recv_packet(15); - let msg = MsgRecvPacket::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgRecvPacket::from(msg.clone()); - let msg_back = MsgRecvPacket::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/timeout.rs b/ibc-core/ics04-channel/types/src/msgs/timeout.rs index 3ae4ba4ce..0404015ab 100644 --- a/ibc-core/ics04-channel/types/src/msgs/timeout.rs +++ b/ibc-core/ics04-channel/types/src/msgs/timeout.rs @@ -76,93 +76,3 @@ impl From for RawMsgTimeout { } } } - -#[cfg(test)] -mod test { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgTimeout as RawMsgTimeout; - use ibc_testkit::utils::core::channel::dummy_raw_msg_timeout; - use ibc_testkit::utils::core::signer::dummy_bech32_account; - - use crate::error::PacketError; - use crate::msgs::timeout::MsgTimeout; - - #[test] - fn msg_timeout_try_from_raw() { - struct Test { - name: String, - raw: RawMsgTimeout, - want_pass: bool, - } - - let proof_height = 50; - let timeout_height = proof_height; - let timeout_timestamp = 0; - let default_raw_msg = - dummy_raw_msg_timeout(proof_height, timeout_height, timeout_timestamp); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_msg.clone(), - want_pass: true, - }, - Test { - name: "Missing packet".to_string(), - raw: RawMsgTimeout { - packet: None, - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof".to_string(), - raw: RawMsgTimeout { - proof_unreceived: Vec::new(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof height".to_string(), - raw: RawMsgTimeout { - proof_height: None, - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Empty signer".to_string(), - raw: RawMsgTimeout { - signer: dummy_bech32_account(), - ..default_raw_msg - }, - want_pass: true, - }, - ]; - - for test in tests { - let res_msg: Result = test.raw.clone().try_into(); - - assert_eq!( - res_msg.is_ok(), - test.want_pass, - "MsgTimeout::try_from failed for test {} \nraw message: {:?} with error: {:?}", - test.name, - test.raw, - res_msg.err() - ); - } - } - - #[test] - fn to_and_from() { - let dummy_raw_msg_timeout = dummy_raw_msg_timeout(15, 20, 0); - let raw = dummy_raw_msg_timeout; - let msg = MsgTimeout::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgTimeout::from(msg.clone()); - let msg_back = MsgTimeout::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs b/ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs index e05cf240d..4b85a87a9 100644 --- a/ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs +++ b/ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs @@ -82,89 +82,3 @@ impl From for RawMsgTimeoutOnClose { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgTimeoutOnClose as RawMsgTimeoutOnClose; - use ibc_testkit::utils::core::channel::dummy_raw_msg_timeout_on_close; - - use crate::msgs::timeout_on_close::MsgTimeoutOnClose; - - #[test] - fn msg_timeout_on_close_try_from_raw() { - let height = 50; - let timeout_timestamp = 5; - let raw = dummy_raw_msg_timeout_on_close(height, timeout_timestamp); - - let msg = MsgTimeoutOnClose::try_from(raw.clone()).unwrap(); - let raw_back = RawMsgTimeoutOnClose::from(msg); - assert_eq!(raw, raw_back); - } - - #[test] - fn parse_timeout_on_close_msg() { - struct Test { - name: String, - raw: RawMsgTimeoutOnClose, - want_pass: bool, - } - - let height = 50; - let timeout_timestamp = 5; - let default_raw_msg = dummy_raw_msg_timeout_on_close(height, timeout_timestamp); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_msg.clone(), - want_pass: true, - }, - Test { - name: "Missing packet".to_string(), - raw: RawMsgTimeoutOnClose { - packet: None, - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof of unreceived packet".to_string(), - raw: RawMsgTimeoutOnClose { - proof_unreceived: Vec::new(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof of channel".to_string(), - raw: RawMsgTimeoutOnClose { - proof_close: Vec::new(), - ..default_raw_msg.clone() - }, - want_pass: false, - }, - Test { - name: "Missing proof height".to_string(), - raw: RawMsgTimeoutOnClose { - proof_height: None, - ..default_raw_msg - }, - want_pass: false, - }, - ]; - - for test in tests { - let res_msg = MsgTimeoutOnClose::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - res_msg.is_ok(), - "MsgTimeoutOnClose::try_from raw failed for test {}, \nraw msg {:?} with error {:?}", - test.name, - test.raw, - res_msg.err(), - ); - } - } -} diff --git a/ibc-core/ics04-channel/types/src/packet.rs b/ibc-core/ics04-channel/types/src/packet.rs index 8c09af4c9..0017e0518 100644 --- a/ibc-core/ics04-channel/types/src/packet.rs +++ b/ibc-core/ics04-channel/types/src/packet.rs @@ -309,194 +309,3 @@ impl From for RawPacketState { } } } - -#[cfg(test)] -mod tests { - use ibc_primitives::prelude::*; - use ibc_proto::ibc::core::channel::v1::Packet as RawPacket; - use ibc_proto::ibc::core::client::v1::Height as RawHeight; - use ibc_testkit::utils::core::channel::dummy_raw_packet; - - use crate::packet::Packet; - - #[test] - fn packet_try_from_raw() { - struct Test { - name: String, - raw: RawPacket, - want_pass: bool, - } - - let proof_height = 10; - let default_raw_packet = dummy_raw_packet(proof_height, 1000); - let raw_packet_no_timeout_or_timestamp = dummy_raw_packet(10, 0); - - let mut raw_packet_invalid_timeout_height = dummy_raw_packet(0, 10); - raw_packet_invalid_timeout_height.timeout_height = Some(RawHeight { - revision_number: 1, - revision_height: 0, - }); - - let tests: Vec = vec![ - Test { - name: "Good parameters".to_string(), - raw: default_raw_packet.clone(), - want_pass: true, - }, - Test { - // Note: ibc-go currently (July 2022) incorrectly rejects this - // case, even though it is allowed in ICS-4. - name: "Packet with no timeout of timestamp".to_string(), - raw: raw_packet_no_timeout_or_timestamp.clone(), - want_pass: true, - }, - Test { - name: "Packet with invalid timeout height".to_string(), - raw: raw_packet_invalid_timeout_height, - want_pass: false, - }, - Test { - name: "Src port validation: correct".to_string(), - raw: RawPacket { - source_port: "srcportp34".to_string(), - ..default_raw_packet.clone() - }, - want_pass: true, - }, - Test { - name: "Bad src port, name too short".to_string(), - raw: RawPacket { - source_port: "p".to_string(), - ..default_raw_packet.clone() - }, - want_pass: false, - }, - Test { - name: "Bad src port, name too long".to_string(), - raw: RawPacket { - source_port: "abcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfasdfasdfaklmnopqrstuabcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfasdfasdfaklmnopqrstu".to_string(), - ..default_raw_packet.clone() - }, - want_pass: false, - }, - Test { - name: "Dst port validation: correct".to_string(), - raw: RawPacket { - destination_port: "destportsrcp34".to_string(), - ..default_raw_packet.clone() - }, - want_pass: true, - }, - Test { - name: "Bad dst port, name too short".to_string(), - raw: RawPacket { - destination_port: "p".to_string(), - ..default_raw_packet.clone() - }, - want_pass: false, - }, - Test { - name: "Bad dst port, name too long".to_string(), - raw: RawPacket { - destination_port: "abcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfasdfasdfaklmnopqrstuabcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfas".to_string(), - ..default_raw_packet.clone() - }, - want_pass: false, - }, - Test { - name: "Src channel validation: correct".to_string(), - raw: RawPacket { - source_channel: "channel-1".to_string(), - ..default_raw_packet.clone() - }, - want_pass: true, - }, - Test { - name: "Bad src channel, name too short".to_string(), - raw: RawPacket { - source_channel: "p".to_string(), - ..default_raw_packet.clone() - }, - want_pass: false, - }, - Test { - name: "Bad src channel, name too long".to_string(), - raw: RawPacket { - source_channel: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), - ..default_raw_packet.clone() - }, - want_pass: false, - }, - Test { - name: "Dst channel validation: correct".to_string(), - raw: RawPacket { - destination_channel: "channel-34".to_string(), - ..default_raw_packet.clone() - }, - want_pass: true, - }, - Test { - name: "Bad dst channel, name too short".to_string(), - raw: RawPacket { - destination_channel: "p".to_string(), - ..default_raw_packet.clone() - }, - want_pass: false, - }, - Test { - name: "Bad dst channel, name too long".to_string(), - raw: RawPacket { - destination_channel: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), - ..default_raw_packet.clone() - }, - want_pass: false, - }, - // Note: `timeout_height == None` is a quirk of protobuf. In - // `proto3` syntax, all structs are "nullable" by default and are - // represented as `Option`. `ibc-go` defines the protobuf file - // with the extension option `gogoproto.nullable = false`, which - // means that they will always generate a field. It is left - // unspecified what a `None` value means. In this case, I believe it - // is best to assume the obvious semantic of "no timeout". - Test { - name: "Missing timeout height".to_string(), - raw: RawPacket { - timeout_height: None, - ..default_raw_packet - }, - want_pass: true, - }, - Test { - name: "Missing both timeout height and timestamp".to_string(), - raw: RawPacket { - timeout_height: None, - ..raw_packet_no_timeout_or_timestamp - }, - want_pass: false, - } - ]; - - for test in tests { - let res_msg = Packet::try_from(test.raw.clone()); - - assert_eq!( - test.want_pass, - res_msg.is_ok(), - "Packet::try_from failed for test {}, \nraw packet {:?} with error {:?}", - test.name, - test.raw, - res_msg.err(), - ); - } - } - - #[test] - fn to_and_from() { - let raw = dummy_raw_packet(15, 0); - let msg = Packet::try_from(raw.clone()).unwrap(); - let raw_back = RawPacket::from(msg.clone()); - let msg_back = Packet::try_from(raw_back.clone()).unwrap(); - assert_eq!(raw, raw_back); - assert_eq!(msg, msg_back); - } -} diff --git a/ibc-core/ics24-host/cosmos/Cargo.toml b/ibc-core/ics24-host/cosmos/Cargo.toml index ee57aab62..45a427b81 100644 --- a/ibc-core/ics24-host/cosmos/Cargo.toml +++ b/ibc-core/ics24-host/cosmos/Cargo.toml @@ -46,10 +46,6 @@ tendermint = { workspace = true } parity-scale-codec = { workspace = true, optional = true } scale-info = { workspace = true, optional = true } -[dev-dependencies] -ibc-testkit = { workspace = true } -rstest = { workspace = true } - [features] default = ["std"] std = [ diff --git a/ibc-core/ics25-handler/types/Cargo.toml b/ibc-core/ics25-handler/types/Cargo.toml index 53eff8b37..5d92949e3 100644 --- a/ibc-core/ics25-handler/types/Cargo.toml +++ b/ibc-core/ics25-handler/types/Cargo.toml @@ -44,9 +44,6 @@ tendermint = { workspace = true } parity-scale-codec = { workspace = true, optional = true } scale-info = { workspace = true, optional = true } -[dev-dependencies] -ibc-testkit = { workspace = true } - [features] default = ["std"] std = [ @@ -63,7 +60,6 @@ std = [ "ibc-primitives/std", "ibc-proto/std", "tendermint/std", - "ibc-testkit/std", ] serde = [ "dep:serde", @@ -75,7 +71,6 @@ serde = [ "ibc-core-router-types/serde", "ibc-primitives/serde", "ibc-proto/serde", - "ibc-testkit/serde", ] schema = [ "dep:schemars", diff --git a/ibc-core/ics25-handler/types/src/events.rs b/ibc-core/ics25-handler/types/src/events.rs index 56c236e91..78c98acbd 100644 --- a/ibc-core/ics25-handler/types/src/events.rs +++ b/ibc-core/ics25-handler/types/src/events.rs @@ -211,30 +211,3 @@ impl From for IbcEvent { IbcEvent::Module(e) } } - -#[cfg(test)] -pub mod tests { - - use ibc_core_channel_types::channel::Order; - use ibc_core_channel_types::events::SendPacket; - use ibc_core_channel_types::packet::Packet; - use ibc_core_host_types::identifiers::ConnectionId; - use ibc_testkit::utils::core::channel::dummy_raw_packet; - - use super::*; - - #[test] - /// Ensures that we don't panic when packet data is not valid UTF-8. - /// See issue [#199](https://github.com/cosmos/ibc-rs/issues/199) - pub fn test_packet_data_non_utf8() { - let mut packet = Packet::try_from(dummy_raw_packet(1, 1)).unwrap(); - packet.data = vec![128]; - - let ibc_event = IbcEvent::SendPacket(SendPacket::new( - packet, - Order::Unordered, - ConnectionId::default(), - )); - let _ = abci::Event::try_from(ibc_event); - } -} diff --git a/ibc-testkit/Cargo.toml b/ibc-testkit/Cargo.toml index 2c8ea9ff5..b2cd443b1 100644 --- a/ibc-testkit/Cargo.toml +++ b/ibc-testkit/Cargo.toml @@ -17,12 +17,14 @@ description = """ [dependencies] # external dependencies +borsh = { workspace = true, optional = true } bytes = { workspace = true } derive_more = { workspace = true } displaydoc = { workspace = true } parking_lot = { version = "0.12.1", default-features = false } primitive-types = { workspace = true } prost = { workspace = true } +schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } serde_json = { workspace = true, optional = true } subtle-encoding = { workspace = true } @@ -62,12 +64,14 @@ serde = [ "serde_json", ] schema = [ + "dep:schemars", "ibc/schema", "ibc-proto/json-schema", "serde", "std", ] borsh = [ + "dep:borsh", "ibc/borsh", "ibc-proto/borsh", ] diff --git a/ibc-testkit/src/utils/dummies/applications/mod.rs b/ibc-testkit/src/fixtures/applications/mod.rs similarity index 100% rename from ibc-testkit/src/utils/dummies/applications/mod.rs rename to ibc-testkit/src/fixtures/applications/mod.rs diff --git a/ibc-testkit/src/utils/dummies/applications/transfer.rs b/ibc-testkit/src/fixtures/applications/transfer.rs similarity index 97% rename from ibc-testkit/src/utils/dummies/applications/transfer.rs rename to ibc-testkit/src/fixtures/applications/transfer.rs index 89c630c79..b352f1a42 100644 --- a/ibc-testkit/src/utils/dummies/applications/transfer.rs +++ b/ibc-testkit/src/fixtures/applications/transfer.rs @@ -9,7 +9,7 @@ use ibc::core::host::types::identifiers::{ChannelId, PortId, Sequence}; use ibc::core::primitives::{Signer, Timestamp}; use typed_builder::TypedBuilder; -use crate::utils::dummies::core::signer::dummy_account_id; +use crate::fixtures::core::signer::dummy_account_id; /// Configuration of the `MsgTransfer` message for building dummy messages. #[derive(TypedBuilder, Debug)] diff --git a/ibc-testkit/src/utils/dummies/clients/mock.rs b/ibc-testkit/src/fixtures/clients/mock.rs similarity index 100% rename from ibc-testkit/src/utils/dummies/clients/mock.rs rename to ibc-testkit/src/fixtures/clients/mock.rs diff --git a/ibc-testkit/src/utils/dummies/clients/mod.rs b/ibc-testkit/src/fixtures/clients/mod.rs similarity index 100% rename from ibc-testkit/src/utils/dummies/clients/mod.rs rename to ibc-testkit/src/fixtures/clients/mod.rs diff --git a/ibc-testkit/src/utils/dummies/clients/tendermint.rs b/ibc-testkit/src/fixtures/clients/tendermint.rs similarity index 75% rename from ibc-testkit/src/utils/dummies/clients/tendermint.rs rename to ibc-testkit/src/fixtures/clients/tendermint.rs index 80bace16f..d64fbd488 100644 --- a/ibc-testkit/src/utils/dummies/clients/tendermint.rs +++ b/ibc-testkit/src/fixtures/clients/tendermint.rs @@ -18,10 +18,7 @@ use tendermint::block::Header as TmHeader; /// Returns a dummy tendermint `ClientState` by given `frozen_height`, for testing purposes only! pub fn dummy_tm_client_state_from_raw(frozen_height: RawHeight) -> Result { - let client_state = - ClientStateType::try_from(dummy_raw_tm_client_state(frozen_height)).expect("Never fails"); - - Ok(TmClientState::from(client_state)) + ClientStateType::try_from(dummy_raw_tm_client_state(frozen_height)).map(TmClientState::from) } /// Returns a dummy tendermint `ClientState` from a `TmHeader`, for testing purposes only! @@ -167,3 +164,57 @@ pub fn dummy_ics07_header() -> Header { trusted_next_validator_set: vs, } } + +#[cfg(test)] +mod tests { + + use ibc::primitives::proto::Any; + + use super::*; + + #[test] + fn tm_client_state_conversions_healthy() { + // check client state creation path from a proto type + let tm_client_state_from_raw = dummy_tm_client_state_from_raw(RawHeight { + revision_number: 0, + revision_height: 0, + }); + assert!(tm_client_state_from_raw.is_ok()); + + let any_from_tm_client_state = Any::from( + tm_client_state_from_raw + .as_ref() + .expect("Never fails") + .clone(), + ); + let tm_client_state_from_any = ClientStateType::try_from(any_from_tm_client_state); + assert!(tm_client_state_from_any.is_ok()); + assert_eq!( + tm_client_state_from_raw.expect("Never fails"), + tm_client_state_from_any.expect("Never fails").into() + ); + + // check client state creation path from a tendermint header + let tm_header = dummy_tendermint_header(); + let tm_client_state_from_header = dummy_tm_client_state_from_header(tm_header); + let any_from_header = Any::from(tm_client_state_from_header.clone()); + let tm_client_state_from_any = ClientStateType::try_from(any_from_header); + assert!(tm_client_state_from_any.is_ok()); + assert_eq!( + tm_client_state_from_header, + tm_client_state_from_any.expect("Never fails").into() + ); + } + + #[test] + fn tm_client_state_malformed_with_frozen_height() { + let tm_client_state_from_raw = dummy_tm_client_state_from_raw(RawHeight { + revision_number: 0, + revision_height: 10, + }); + match tm_client_state_from_raw { + Err(Error::FrozenHeightNotAllowed) => {} + _ => panic!("Expected to fail with FrozenHeightNotAllowed error"), + } + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/acknowledgement.rs b/ibc-testkit/src/fixtures/core/channel/acknowledgement.rs new file mode 100644 index 000000000..299278789 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/acknowledgement.rs @@ -0,0 +1,100 @@ +use ibc::core::channel::types::proto::v1::{ + MsgAcknowledgement as RawMsgAcknowledgement, Packet as RawPacket, +}; +use ibc::core::client::types::proto::v1::Height as RawHeight; + +use super::{dummy_proof, dummy_raw_packet}; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgAcknowledgement`, for testing purposes only! +/// The `height` parametrizes both the proof height as well as the timeout height. +pub fn dummy_raw_msg_acknowledgement(height: u64) -> RawMsgAcknowledgement { + dummy_raw_msg_ack_with_packet(dummy_raw_packet(height, 1), height) +} + +pub fn dummy_raw_msg_ack_with_packet(packet: RawPacket, height: u64) -> RawMsgAcknowledgement { + RawMsgAcknowledgement { + packet: Some(packet), + acknowledgement: dummy_proof(), + proof_acked: dummy_proof(), + proof_height: Some(RawHeight { + revision_number: 0, + revision_height: height, + }), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod test { + use ibc::core::channel::types::error::PacketError; + use ibc::core::channel::types::msgs::MsgAcknowledgement; + use ibc::primitives::prelude::*; + + use super::*; + + #[test] + fn msg_acknowledgment_try_from_raw() { + struct Test { + name: String, + raw: RawMsgAcknowledgement, + want_pass: bool, + } + + let height = 50; + let default_raw_msg = dummy_raw_msg_acknowledgement(height); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_msg.clone(), + want_pass: true, + }, + Test { + name: "Missing packet".to_string(), + raw: RawMsgAcknowledgement { + packet: None, + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof height".to_string(), + raw: RawMsgAcknowledgement { + proof_height: None, + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Empty signer".to_string(), + raw: RawMsgAcknowledgement { + signer: dummy_bech32_account(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Empty proof acked".to_string(), + raw: RawMsgAcknowledgement { + proof_acked: Vec::new(), + ..default_raw_msg + }, + want_pass: false, + }, + ]; + + for test in tests { + let res_msg: Result = test.raw.clone().try_into(); + + assert_eq!( + res_msg.is_ok(), + test.want_pass, + "MsgAcknowledgement::try_from failed for test {} \nraw message: {:?} with error: {:?}", + test.name, + test.raw, + res_msg.err() + ); + } + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs b/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs new file mode 100644 index 000000000..650c735ac --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs @@ -0,0 +1,136 @@ +use ibc::core::channel::types::proto::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm; +use ibc::core::client::types::proto::v1::Height; +use ibc::core::host::types::identifiers::{ChannelId, PortId}; +use ibc::core::primitives::prelude::*; + +use super::dummy_proof; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgChannelCloseConfirm`, for testing purposes only! +pub fn dummy_raw_msg_chan_close_confirm(proof_height: u64) -> RawMsgChannelCloseConfirm { + RawMsgChannelCloseConfirm { + port_id: PortId::transfer().to_string(), + channel_id: ChannelId::default().to_string(), + proof_init: dummy_proof(), + proof_height: Some(Height { + revision_number: 0, + revision_height: proof_height, + }), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::channel::types::msgs::MsgChannelCloseConfirm; + + use super::*; + + #[test] + fn parse_channel_close_confirm_msg() { + struct Test { + name: String, + raw: RawMsgChannelCloseConfirm, + want_pass: bool, + } + + let proof_height = 10; + let default_raw_msg = dummy_raw_msg_chan_close_confirm(proof_height); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_msg.clone(), + want_pass: true, + }, + Test { + name: "Correct port".to_string(), + raw: RawMsgChannelCloseConfirm { + port_id: "p34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad port, name too short".to_string(), + raw: RawMsgChannelCloseConfirm { + port_id: "p".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad port, name too long".to_string(), + raw: RawMsgChannelCloseConfirm { + port_id: + "abcdefghijklmnsdfasdfasdfasdfasdgafgadsfasdfasdfasdasfdasdfsadfopqrstuabcdefghijklmnsdfasdfasdfasdfasdgafgadsfasdfasdfasdasfdasdfsadfopqrstu" + .to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Correct channel identifier".to_string(), + raw: RawMsgChannelCloseConfirm { + channel_id: "channel-34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad channel, name too short".to_string(), + raw: RawMsgChannelCloseConfirm { + channel_id: "chshort".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad channel, name too long".to_string(), + raw: RawMsgChannelCloseConfirm { + channel_id: + "channel-128391283791827398127398791283912837918273981273987912839" + .to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad proof height, height = 0".to_string(), + raw: RawMsgChannelCloseConfirm { + proof_height: Some(Height { + revision_number: 0, + revision_height: 0, + }), + ..default_raw_msg + }, + want_pass: false, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let msg = MsgChannelCloseConfirm::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + msg.is_ok(), + "MsgChanCloseConfirm::try_from raw failed for test {}, \nraw msg {:?} with error {:?}", + test.name, + test.raw, + msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_chan_close_confirm(19); + let msg = MsgChannelCloseConfirm::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgChannelCloseConfirm::from(msg.clone()); + let msg_back = MsgChannelCloseConfirm::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs b/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs new file mode 100644 index 000000000..dd770443d --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs @@ -0,0 +1,113 @@ +use ibc::core::channel::types::proto::v1::MsgChannelCloseInit as RawMsgChannelCloseInit; +use ibc::core::host::types::identifiers::{ChannelId, PortId}; +use ibc::core::primitives::prelude::*; + +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgChannelCloseInit`, for testing purposes only! +pub fn dummy_raw_msg_chan_close_init() -> RawMsgChannelCloseInit { + RawMsgChannelCloseInit { + port_id: PortId::transfer().to_string(), + channel_id: ChannelId::default().to_string(), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::channel::types::msgs::MsgChannelCloseInit; + + use super::*; + + #[test] + fn parse_channel_close_init_msg() { + struct Test { + name: String, + raw: RawMsgChannelCloseInit, + want_pass: bool, + } + + let default_raw_msg = dummy_raw_msg_chan_close_init(); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_msg.clone(), + want_pass: true, + }, + Test { + name: "Correct port".to_string(), + raw: RawMsgChannelCloseInit { + port_id: "p34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad port, name too short".to_string(), + raw: RawMsgChannelCloseInit { + port_id: "p".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad port, name too long".to_string(), + raw: RawMsgChannelCloseInit { + port_id: "abcdefsdfasdfasdfasdfasdfasdfadsfasdgafsgadfasdfasdfasdfsdfasdfaghijklmnopqrstuabcdefsdfasdfasdfasdfasdfasdfadsfasdgafsgadfasdfasdfasdfsdfasdfaghijklmnopqrstu".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Correct channel identifier".to_string(), + raw: RawMsgChannelCloseInit { + channel_id: "channel-34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad channel, name too short".to_string(), + raw: RawMsgChannelCloseInit { + channel_id: "chshort".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad channel, name too long".to_string(), + raw: RawMsgChannelCloseInit { + channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), + ..default_raw_msg + }, + want_pass: false, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let msg = MsgChannelCloseInit::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + msg.is_ok(), + "MsgChanCloseInit::try_from failed for test {}, \nmsg {:?} with error {:?}", + test.name, + test.raw, + msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_chan_close_init(); + let msg = MsgChannelCloseInit::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgChannelCloseInit::from(msg.clone()); + let msg_back = MsgChannelCloseInit::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs new file mode 100644 index 000000000..8b9a0b952 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs @@ -0,0 +1,190 @@ +use ibc::core::channel::types::proto::v1::MsgChannelOpenAck as RawMsgChannelOpenAck; +use ibc::core::client::types::proto::v1::Height; +use ibc::core::host::types::identifiers::{ChannelId, PortId}; +use ibc::core::primitives::prelude::*; + +use super::dummy_proof; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgChannelOpenAck`, for testing purposes only! +pub fn dummy_raw_msg_chan_open_ack(proof_height: u64) -> RawMsgChannelOpenAck { + RawMsgChannelOpenAck { + port_id: PortId::transfer().to_string(), + channel_id: ChannelId::default().to_string(), + counterparty_channel_id: ChannelId::default().to_string(), + counterparty_version: "".to_string(), + proof_try: dummy_proof(), + proof_height: Some(Height { + revision_number: 0, + revision_height: proof_height, + }), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::channel::types::msgs::MsgChannelOpenAck; + + use super::*; + + #[test] + fn parse_channel_open_ack_msg() { + struct Test { + name: String, + raw: RawMsgChannelOpenAck, + want_pass: bool, + } + + let proof_height = 20; + let default_raw_msg = dummy_raw_msg_chan_open_ack(proof_height); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_msg.clone(), + want_pass: true, + }, + Test { + name: "Correct port identifier".to_string(), + raw: RawMsgChannelOpenAck { + port_id: "p34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad port, name too short".to_string(), + raw: RawMsgChannelOpenAck { + port_id: "p".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad port, name too long".to_string(), + raw: RawMsgChannelOpenAck { + port_id: "abcdezdfDfsdfgfddsfsfdsdfdfvxcvzxcvsgdfsdfwefwvsdfdsfdasgagadgsadgsdffghijklmnopqrstuabcdezdfDfsdfgfddsfsfdsdfdfvxcvzxcvsgdfsdfwefwvsdfdsfdasgagadgsadgsdffghijklmnopqrstu".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Correct channel identifier".to_string(), + raw: RawMsgChannelOpenAck { + channel_id: "channel-34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad channel, name too short".to_string(), + raw: RawMsgChannelOpenAck { + channel_id: "chshort".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad channel, name too long".to_string(), + raw: RawMsgChannelOpenAck { + channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "[Counterparty] Correct channel identifier".to_string(), + raw: RawMsgChannelOpenAck { + counterparty_channel_id: "channel-34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "[Counterparty] Bad channel, name too short".to_string(), + raw: RawMsgChannelOpenAck { + counterparty_channel_id: "chshort".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "[Counterparty] Bad channel, name too long".to_string(), + raw: RawMsgChannelOpenAck { + counterparty_channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Empty counterparty version (allowed)".to_string(), + raw: RawMsgChannelOpenAck { + counterparty_version: " ".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Arbitrary counterparty version (allowed)".to_string(), + raw: RawMsgChannelOpenAck { + counterparty_version: "v1.1.23-alpha".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad proof height, height = 0".to_string(), + raw: RawMsgChannelOpenAck { + proof_height: Some(Height { + revision_number: 0, + revision_height: 0, + }), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof height".to_string(), + raw: RawMsgChannelOpenAck { + proof_height: None, + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof try (object proof)".to_string(), + raw: RawMsgChannelOpenAck { + proof_try: Vec::new(), + ..default_raw_msg + }, + want_pass: false, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let res_msg = MsgChannelOpenAck::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + res_msg.is_ok(), + "MsgChanOpenAck::try_from raw failed for test {}, \nraw msg {:?} with error {:?}", + test.name, + test.raw, + res_msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_chan_open_ack(100); + let msg = MsgChannelOpenAck::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgChannelOpenAck::from(msg.clone()); + let msg_back = MsgChannelOpenAck::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs new file mode 100644 index 000000000..dfb1c797e --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs @@ -0,0 +1,140 @@ +use ibc::core::channel::types::proto::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm; +use ibc::core::client::types::proto::v1::Height; +use ibc::core::host::types::identifiers::{ChannelId, PortId}; +use ibc::core::primitives::prelude::*; + +use super::dummy_proof; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgChannelOpenConfirm`, for testing purposes only! +pub fn dummy_raw_msg_chan_open_confirm(proof_height: u64) -> RawMsgChannelOpenConfirm { + RawMsgChannelOpenConfirm { + port_id: PortId::transfer().to_string(), + channel_id: ChannelId::default().to_string(), + proof_ack: dummy_proof(), + proof_height: Some(Height { + revision_number: 0, + revision_height: proof_height, + }), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::channel::types::msgs::MsgChannelOpenConfirm; + + use super::*; + + #[test] + fn parse_channel_open_confirm_msg() { + struct Test { + name: String, + raw: RawMsgChannelOpenConfirm, + want_pass: bool, + } + + let proof_height = 78; + let default_raw_msg = dummy_raw_msg_chan_open_confirm(proof_height); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_msg.clone(), + want_pass: true, + }, + Test { + name: "Correct port".to_string(), + raw: RawMsgChannelOpenConfirm { + port_id: "p34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad port, name too short".to_string(), + raw: RawMsgChannelOpenConfirm { + port_id: "p".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad port, name too long".to_string(), + raw: RawMsgChannelOpenConfirm { + port_id: "abcdesdfasdsdffasdfasdfasfasdgasdfgasdfasdfasdfasdfasdfasdffghijklmnopqrstuabcdesdfasdsdffasdfasdfasfasdgasdfgasdfasdfasdfasdfasdfasdffghijklmnopqrstu".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Correct channel identifier".to_string(), + raw: RawMsgChannelOpenConfirm { + channel_id: "channel-34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad channel, name too short".to_string(), + raw: RawMsgChannelOpenConfirm { + channel_id: "chshort".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad channel, name too long".to_string(), + raw: RawMsgChannelOpenConfirm { + channel_id: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad proof height, height = 0".to_string(), + raw: RawMsgChannelOpenConfirm { + proof_height: Some(Height { + revision_number: 0, + revision_height: 0, + }), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing object proof".to_string(), + raw: RawMsgChannelOpenConfirm { + proof_ack: Vec::new(), + ..default_raw_msg + }, + want_pass: false, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let res_msg = MsgChannelOpenConfirm::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + res_msg.is_ok(), + "MsgChanOpenConfirm::try_from failed for test {}, \nraw msg {:?} with error {:?}", + test.name, + test.raw, + res_msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_chan_open_confirm(19); + let msg = MsgChannelOpenConfirm::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgChannelOpenConfirm::from(msg.clone()); + let msg_back = MsgChannelOpenConfirm::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_init.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_init.rs new file mode 100644 index 000000000..a40f5afa8 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_init.rs @@ -0,0 +1,106 @@ +use ibc::core::channel::types::proto::v1::MsgChannelOpenInit as RawMsgChannelOpenInit; +use ibc::core::host::types::identifiers::PortId; +use ibc::core::primitives::prelude::*; + +use super::dummy_raw_channel_end; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgChannelOpenInit`, for testing purposes only! +pub fn dummy_raw_msg_chan_open_init(counterparty_channel_id: Option) -> RawMsgChannelOpenInit { + RawMsgChannelOpenInit { + port_id: PortId::transfer().to_string(), + channel: Some(dummy_raw_channel_end(1, counterparty_channel_id)), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::channel::types::msgs::MsgChannelOpenInit; + + use super::*; + + #[test] + fn channel_open_init_from_raw() { + struct Test { + name: String, + raw: RawMsgChannelOpenInit, + want_pass: bool, + } + + let default_raw_init_msg = dummy_raw_msg_chan_open_init(None); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_init_msg.clone(), + want_pass: true, + }, + Test { + name: "Incorrect port identifier, slash (separator) prohibited".to_string(), + raw: RawMsgChannelOpenInit { + port_id: "p34/".to_string(), + ..default_raw_init_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing channel".to_string(), + raw: RawMsgChannelOpenInit { + channel: None, + ..default_raw_init_msg + }, + want_pass: false, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let res_msg = MsgChannelOpenInit::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + res_msg.is_ok(), + "MsgChanOpenInit::try_from failed for test {}, \nraw msg {:?} with error {:?}", + test.name, + test.raw, + res_msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + // Check if raw and domain types are equal after conversions + let raw = dummy_raw_msg_chan_open_init(None); + let msg = MsgChannelOpenInit::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgChannelOpenInit::from(msg.clone()); + let msg_back = MsgChannelOpenInit::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + + // Check if handler sets counterparty channel id to `None` + // in case relayer passes `MsgChannelOpenInit` message with it set to `Some(_)` + let raw_with_counterparty_chan_id_some = dummy_raw_msg_chan_open_init(None); + let msg_with_counterparty_chan_id_some = + MsgChannelOpenInit::try_from(raw_with_counterparty_chan_id_some).unwrap(); + let raw_with_counterparty_chan_id_some_back = + RawMsgChannelOpenInit::from(msg_with_counterparty_chan_id_some.clone()); + let msg_with_counterparty_chan_id_some_back = + MsgChannelOpenInit::try_from(raw_with_counterparty_chan_id_some_back.clone()).unwrap(); + assert_eq!( + raw_with_counterparty_chan_id_some_back + .channel + .unwrap() + .counterparty + .unwrap() + .channel_id, + "".to_string() + ); + assert_eq!( + msg_with_counterparty_chan_id_some, + msg_with_counterparty_chan_id_some_back + ); + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_try.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_try.rs new file mode 100644 index 000000000..8b4185df6 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_try.rs @@ -0,0 +1,143 @@ +use ibc::core::channel::types::proto::v1::MsgChannelOpenTry as RawMsgChannelOpenTry; +use ibc::core::client::types::proto::v1::Height; +use ibc::core::host::types::identifiers::PortId; +use ibc::core::primitives::prelude::*; + +use super::{dummy_proof, dummy_raw_channel_end}; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgChannelOpenTry`, for testing purposes only! +pub fn dummy_raw_msg_chan_open_try(proof_height: u64) -> RawMsgChannelOpenTry { + #[allow(deprecated)] + RawMsgChannelOpenTry { + port_id: PortId::transfer().to_string(), + previous_channel_id: "".to_string(), + channel: Some(dummy_raw_channel_end(2, Some(0))), + counterparty_version: "".to_string(), + proof_init: dummy_proof(), + proof_height: Some(Height { + revision_number: 0, + revision_height: proof_height, + }), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::channel::types::msgs::MsgChannelOpenTry; + + use super::*; + + #[test] + fn channel_open_try_from_raw() { + struct Test { + name: String, + raw: RawMsgChannelOpenTry, + want_pass: bool, + } + + let proof_height = 10; + let default_raw_msg = dummy_raw_msg_chan_open_try(proof_height); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_msg.clone(), + want_pass: true, + }, + Test { + name: "Correct port".to_string(), + raw: RawMsgChannelOpenTry { + port_id: "p34".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad port, name too short".to_string(), + raw: RawMsgChannelOpenTry { + port_id: "p".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad port, name too long".to_string(), + raw: RawMsgChannelOpenTry { + port_id: "abcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfaabcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfa".to_string(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Empty counterparty version (valid choice)".to_string(), + raw: RawMsgChannelOpenTry { + counterparty_version: " ".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Arbitrary counterparty version (valid choice)".to_string(), + raw: RawMsgChannelOpenTry { + counterparty_version: "anyversion".to_string(), + ..default_raw_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad proof height, height = 0".to_string(), + raw: RawMsgChannelOpenTry { + proof_height: Some(Height { + revision_number: 0, + revision_height: 0, + }), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof height".to_string(), + raw: RawMsgChannelOpenTry { + proof_height: None, + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof init (object proof)".to_string(), + raw: RawMsgChannelOpenTry { + proof_init: Vec::new(), + ..default_raw_msg + }, + want_pass: false, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let res_msg = MsgChannelOpenTry::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + res_msg.is_ok(), + "MsgChanOpenTry::try_from failed for test {}, \nraw msg {:?} with error {:?}", + test.name, + test.raw, + res_msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_chan_open_try(10); + let msg = MsgChannelOpenTry::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgChannelOpenTry::from(msg.clone()); + let msg_back = MsgChannelOpenTry::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/mod.rs b/ibc-testkit/src/fixtures/core/channel/mod.rs new file mode 100644 index 000000000..0f0df1bf4 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/mod.rs @@ -0,0 +1,194 @@ +mod acknowledgement; +mod chan_close_confirm; +mod chan_close_init; +mod chan_open_ack; +mod chan_open_confirm; +mod chan_open_init; +mod chan_open_try; +mod packet; +mod recv_packet; +mod timeout; +mod timeout_on_close; + +pub use acknowledgement::*; +pub use chan_close_confirm::*; +pub use chan_close_init::*; +pub use chan_open_ack::*; +pub use chan_open_confirm::*; +pub use chan_open_init::*; +pub use chan_open_try::*; +use ibc::core::channel::types::proto::v1::{ + Channel as RawChannel, Counterparty as RawCounterparty, +}; +use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; +use ibc::primitives::prelude::*; +pub use packet::*; +pub use recv_packet::*; +pub use timeout::*; +pub use timeout_on_close::*; + +/// Returns a dummy `RawCounterparty`, for testing purposes only! +/// Can be optionally parametrized with a specific channel identifier. +pub fn dummy_raw_counterparty_chan(channel_id: String) -> RawCounterparty { + RawCounterparty { + port_id: PortId::transfer().to_string(), + channel_id, + } +} + +/// Returns a dummy `RawChannel`, for testing purposes only! +pub fn dummy_raw_channel_end(state: i32, channel_id: Option) -> RawChannel { + let channel_id = match channel_id { + Some(id) => ChannelId::new(id).to_string(), + None => "".to_string(), + }; + RawChannel { + state, + ordering: 2, + counterparty: Some(dummy_raw_counterparty_chan(channel_id)), + connection_hops: vec![ConnectionId::default().to_string()], + version: "".to_string(), // The version is not validated. + } +} + +#[cfg(test)] +mod tests { + use core::str::FromStr; + + use ibc::core::channel::types::channel::ChannelEnd; + + use super::*; + #[test] + fn channel_end_try_from_raw() { + let raw_channel_end = dummy_raw_channel_end(2, Some(0)); + + let empty_raw_channel_end = RawChannel { + counterparty: None, + ..raw_channel_end.clone() + }; + + struct Test { + name: String, + params: RawChannel, + want_pass: bool, + } + + let tests: Vec = vec![ + Test { + name: "Raw channel end with missing counterparty".to_string(), + params: empty_raw_channel_end, + want_pass: false, + }, + Test { + name: "Raw channel end with incorrect state".to_string(), + params: RawChannel { + state: -1, + ..raw_channel_end.clone() + }, + want_pass: false, + }, + Test { + name: "Raw channel end with incorrect ordering".to_string(), + params: RawChannel { + ordering: -1, + ..raw_channel_end.clone() + }, + want_pass: false, + }, + Test { + name: "Raw channel end with incorrect connection id in connection hops".to_string(), + params: RawChannel { + connection_hops: vec!["connection*".to_string()].into_iter().collect(), + ..raw_channel_end.clone() + }, + want_pass: false, + }, + Test { + name: "Raw channel end with incorrect connection id (has blank space)".to_string(), + params: RawChannel { + connection_hops: vec!["con nection".to_string()].into_iter().collect(), + ..raw_channel_end.clone() + }, + want_pass: false, + }, + Test { + name: "Raw channel end with two correct connection ids in connection hops" + .to_string(), + params: RawChannel { + connection_hops: vec!["connection-1".to_string(), "connection-2".to_string()] + .into_iter() + .collect(), + ..raw_channel_end.clone() + }, + want_pass: true, + }, + Test { + name: "Raw channel end with correct params".to_string(), + params: raw_channel_end, + want_pass: true, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let p = test.params.clone(); + + let ce_result = ChannelEnd::try_from(p); + + assert_eq!( + test.want_pass, + ce_result.is_ok(), + "ChannelEnd::try_from() failed for test {}, \nmsg{:?} with error {:?}", + test.name, + test.params.clone(), + ce_result.err(), + ); + } + } + + #[test] + fn parse_channel_ordering_type() { + use ibc::core::channel::types::channel::Order; + + struct Test { + ordering: &'static str, + want_res: Order, + want_err: bool, + } + let tests: Vec = vec![ + Test { + ordering: "UNINITIALIZED", + want_res: Order::None, + want_err: false, + }, + Test { + ordering: "UNORDERED", + want_res: Order::Unordered, + want_err: false, + }, + Test { + ordering: "ORDERED", + want_res: Order::Ordered, + want_err: false, + }, + Test { + ordering: "UNKNOWN_ORDER", + want_res: Order::None, + want_err: true, + }, + ] + .into_iter() + .collect(); + + for test in tests { + match Order::from_str(test.ordering) { + Ok(res) => { + assert!(!test.want_err); + assert_eq!(test.want_res, res); + } + Err(_) => assert!(test.want_err, "parse failed"), + } + } + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/packet.rs b/ibc-testkit/src/fixtures/core/channel/packet.rs new file mode 100644 index 000000000..caa094c5a --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/packet.rs @@ -0,0 +1,275 @@ +use ibc::core::channel::types::packet::Packet; +use ibc::core::channel::types::proto::v1::Packet as RawPacket; +use ibc::core::channel::types::timeout::TimeoutHeight; +use ibc::core::client::types::proto::v1::Height as RawHeight; +use ibc::core::host::types::identifiers::{ChannelId, PortId, Sequence}; +use ibc::core::primitives::prelude::*; +use ibc::core::primitives::Timestamp; +use typed_builder::TypedBuilder; + +/// Configuration of the `PacketData` type for building dummy packets. +#[derive(TypedBuilder, Debug)] +#[builder(build_method(into = Packet))] +pub struct PacketConfig { + #[builder(default)] + pub seq_on_a: Sequence, + #[builder(default = PortId::transfer())] + pub port_id_on_a: PortId, + #[builder(default)] + pub chan_id_on_a: ChannelId, + #[builder(default = PortId::transfer())] + pub port_id_on_b: PortId, + #[builder(default)] + pub chan_id_on_b: ChannelId, + #[builder(default)] + pub data: Vec, + #[builder(default)] + pub timeout_height_on_b: TimeoutHeight, + #[builder(default)] + pub timeout_timestamp_on_b: Timestamp, +} + +impl From for Packet { + fn from(config: PacketConfig) -> Self { + Packet { + seq_on_a: config.seq_on_a, + port_id_on_a: config.port_id_on_a, + chan_id_on_a: config.chan_id_on_a, + port_id_on_b: config.port_id_on_b, + chan_id_on_b: config.chan_id_on_b, + data: config.data, + timeout_height_on_b: config.timeout_height_on_b, + timeout_timestamp_on_b: config.timeout_timestamp_on_b, + } + } +} + +/// Returns a dummy `RawPacket`, for testing purposes only! +pub fn dummy_raw_packet(timeout_height: u64, timeout_timestamp: u64) -> RawPacket { + RawPacket { + sequence: 1, + source_port: PortId::transfer().to_string(), + source_channel: ChannelId::default().to_string(), + destination_port: PortId::transfer().to_string(), + destination_channel: ChannelId::default().to_string(), + data: vec![0], + timeout_height: Some(RawHeight { + revision_number: 0, + revision_height: timeout_height, + }), + timeout_timestamp, + } +} + +pub fn dummy_proof() -> Vec { + "Y29uc2Vuc3VzU3RhdGUvaWJjb25lY2xpZW50LzIy" + .as_bytes() + .to_vec() +} + +#[cfg(test)] +mod tests { + use ibc::core::channel::types::channel::Order; + use ibc::core::channel::types::events::SendPacket; + use ibc::core::channel::types::packet::Packet; + use ibc::core::handler::types::events::IbcEvent; + use ibc::core::host::types::identifiers::ConnectionId; + + use super::*; + + #[test] + fn packet_try_from_raw() { + struct Test { + name: String, + raw: RawPacket, + want_pass: bool, + } + + let proof_height = 10; + let default_raw_packet = dummy_raw_packet(proof_height, 1000); + let raw_packet_no_timeout_or_timestamp = dummy_raw_packet(10, 0); + + let mut raw_packet_invalid_timeout_height = dummy_raw_packet(0, 10); + raw_packet_invalid_timeout_height.timeout_height = Some(RawHeight { + revision_number: 1, + revision_height: 0, + }); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_packet.clone(), + want_pass: true, + }, + Test { + // Note: ibc-go currently (July 2022) incorrectly rejects this + // case, even though it is allowed in ICS-4. + name: "Packet with no timeout of timestamp".to_string(), + raw: raw_packet_no_timeout_or_timestamp.clone(), + want_pass: true, + }, + Test { + name: "Packet with invalid timeout height".to_string(), + raw: raw_packet_invalid_timeout_height, + want_pass: false, + }, + Test { + name: "Src port validation: correct".to_string(), + raw: RawPacket { + source_port: "srcportp34".to_string(), + ..default_raw_packet.clone() + }, + want_pass: true, + }, + Test { + name: "Bad src port, name too short".to_string(), + raw: RawPacket { + source_port: "p".to_string(), + ..default_raw_packet.clone() + }, + want_pass: false, + }, + Test { + name: "Bad src port, name too long".to_string(), + raw: RawPacket { + source_port: "abcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfasdfasdfaklmnopqrstuabcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfasdfasdfaklmnopqrstu".to_string(), + ..default_raw_packet.clone() + }, + want_pass: false, + }, + Test { + name: "Dst port validation: correct".to_string(), + raw: RawPacket { + destination_port: "destportsrcp34".to_string(), + ..default_raw_packet.clone() + }, + want_pass: true, + }, + Test { + name: "Bad dst port, name too short".to_string(), + raw: RawPacket { + destination_port: "p".to_string(), + ..default_raw_packet.clone() + }, + want_pass: false, + }, + Test { + name: "Bad dst port, name too long".to_string(), + raw: RawPacket { + destination_port: "abcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfasdfasdfasdfaklmnopqrstuabcdefghijasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadgasgasdfas".to_string(), + ..default_raw_packet.clone() + }, + want_pass: false, + }, + Test { + name: "Src channel validation: correct".to_string(), + raw: RawPacket { + source_channel: "channel-1".to_string(), + ..default_raw_packet.clone() + }, + want_pass: true, + }, + Test { + name: "Bad src channel, name too short".to_string(), + raw: RawPacket { + source_channel: "p".to_string(), + ..default_raw_packet.clone() + }, + want_pass: false, + }, + Test { + name: "Bad src channel, name too long".to_string(), + raw: RawPacket { + source_channel: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), + ..default_raw_packet.clone() + }, + want_pass: false, + }, + Test { + name: "Dst channel validation: correct".to_string(), + raw: RawPacket { + destination_channel: "channel-34".to_string(), + ..default_raw_packet.clone() + }, + want_pass: true, + }, + Test { + name: "Bad dst channel, name too short".to_string(), + raw: RawPacket { + destination_channel: "p".to_string(), + ..default_raw_packet.clone() + }, + want_pass: false, + }, + Test { + name: "Bad dst channel, name too long".to_string(), + raw: RawPacket { + destination_channel: "channel-128391283791827398127398791283912837918273981273987912839".to_string(), + ..default_raw_packet.clone() + }, + want_pass: false, + }, + // Note: `timeout_height == None` is a quirk of protobuf. In + // `proto3` syntax, all structs are "nullable" by default and are + // represented as `Option`. `ibc-go` defines the protobuf file + // with the extension option `gogoproto.nullable = false`, which + // means that they will always generate a field. It is left + // unspecified what a `None` value means. In this case, I believe it + // is best to assume the obvious semantic of "no timeout". + Test { + name: "Missing timeout height".to_string(), + raw: RawPacket { + timeout_height: None, + ..default_raw_packet + }, + want_pass: true, + }, + Test { + name: "Missing both timeout height and timestamp".to_string(), + raw: RawPacket { + timeout_height: None, + ..raw_packet_no_timeout_or_timestamp + }, + want_pass: false, + } + ]; + + for test in tests { + let res_msg = Packet::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + res_msg.is_ok(), + "Packet::try_from failed for test {}, \nraw packet {:?} with error {:?}", + test.name, + test.raw, + res_msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_packet(15, 0); + let msg = Packet::try_from(raw.clone()).unwrap(); + let raw_back = RawPacket::from(msg.clone()); + let msg_back = Packet::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } + + #[test] + /// Ensures that we don't panic when packet data is not valid UTF-8. + /// See issue [#199](https://github.com/cosmos/ibc-rs/issues/199) + pub fn test_packet_data_non_utf8() { + let mut packet = Packet::try_from(dummy_raw_packet(1, 1)).unwrap(); + packet.data = vec![128]; + + let ibc_event = IbcEvent::SendPacket(SendPacket::new( + packet, + Order::Unordered, + ConnectionId::default(), + )); + let _ = tendermint::abci::Event::try_from(ibc_event); + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/recv_packet.rs b/ibc-testkit/src/fixtures/core/channel/recv_packet.rs new file mode 100644 index 000000000..0faeff71a --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/recv_packet.rs @@ -0,0 +1,119 @@ +use core::ops::Add; +use core::time::Duration; + +use ibc::core::channel::types::msgs::MsgRecvPacket; +use ibc::core::channel::types::packet::Packet; +use ibc::core::channel::types::proto::v1::MsgRecvPacket as RawMsgRecvPacket; +use ibc::core::client::types::proto::v1::Height as RawHeight; +use ibc::core::client::types::Height; +use ibc::core::commitment_types::commitment::CommitmentProofBytes; +use ibc::core::primitives::{Signer, Timestamp}; + +use super::{dummy_proof, dummy_raw_packet}; +use crate::fixtures::core::signer::dummy_bech32_account; + +pub fn dummy_msg_recv_packet( + packet: Packet, + proof_commitment_on_a: CommitmentProofBytes, + proof_height_on_a: Height, + signer: Signer, +) -> MsgRecvPacket { + MsgRecvPacket { + packet, + proof_commitment_on_a, + proof_height_on_a, + signer, + } +} + +/// Returns a dummy `RawMsgRecvPacket`, for testing purposes only! The `height` +/// parametrizes both the proof height as well as the timeout height. +pub fn dummy_raw_msg_recv_packet(height: u64) -> RawMsgRecvPacket { + let timestamp = Timestamp::now().add(Duration::from_secs(9)); + RawMsgRecvPacket { + packet: Some(dummy_raw_packet( + height, + timestamp.expect("timestamp").nanoseconds(), + )), + proof_commitment: dummy_proof(), + proof_height: Some(RawHeight { + revision_number: 0, + revision_height: height, + }), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod test { + use ibc::core::channel::types::error::PacketError; + use ibc::primitives::prelude::*; + + use super::*; + + #[test] + fn msg_recv_packet_try_from_raw() { + struct Test { + name: String, + raw: RawMsgRecvPacket, + want_pass: bool, + } + + let height = 20; + let default_raw_msg = dummy_raw_msg_recv_packet(height); + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_msg.clone(), + want_pass: true, + }, + Test { + name: "Missing proof".to_string(), + raw: RawMsgRecvPacket { + proof_commitment: Vec::new(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof height".to_string(), + raw: RawMsgRecvPacket { + proof_height: None, + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Empty signer".to_string(), + raw: RawMsgRecvPacket { + signer: dummy_bech32_account(), + ..default_raw_msg + }, + want_pass: true, + }, + ]; + + for test in tests { + let res_msg: Result = test.raw.clone().try_into(); + + assert_eq!( + res_msg.is_ok(), + test.want_pass, + "MsgRecvPacket::try_from failed for test {} \nraw message: {:?} with error: {:?}", + test.name, + test.raw, + res_msg.err() + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_recv_packet(15); + let msg = MsgRecvPacket::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgRecvPacket::from(msg.clone()); + let msg_back = MsgRecvPacket::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/timeout.rs b/ibc-testkit/src/fixtures/core/channel/timeout.rs new file mode 100644 index 000000000..960dd4d57 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/timeout.rs @@ -0,0 +1,112 @@ +use ibc::core::channel::types::proto::v1::MsgTimeout as RawMsgTimeout; +use ibc::core::client::types::proto::v1::Height as RawHeight; + +use super::{dummy_proof, dummy_raw_packet}; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgTimeout`, for testing purposes only! +/// The `height` parametrizes both the proof height as well as the timeout height. +pub fn dummy_raw_msg_timeout( + proof_height: u64, + timeout_height: u64, + timeout_timestamp: u64, +) -> RawMsgTimeout { + RawMsgTimeout { + packet: Some(dummy_raw_packet(timeout_height, timeout_timestamp)), + proof_unreceived: dummy_proof(), + proof_height: Some(RawHeight { + revision_number: 0, + revision_height: proof_height, + }), + next_sequence_recv: 1, + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod test { + use ibc::core::channel::types::error::PacketError; + use ibc::core::channel::types::msgs::MsgTimeout; + use ibc::primitives::prelude::*; + + use super::*; + + #[test] + fn msg_timeout_try_from_raw() { + struct Test { + name: String, + raw: RawMsgTimeout, + want_pass: bool, + } + + let proof_height = 50; + let timeout_height = proof_height; + let timeout_timestamp = 0; + let default_raw_msg = + dummy_raw_msg_timeout(proof_height, timeout_height, timeout_timestamp); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_msg.clone(), + want_pass: true, + }, + Test { + name: "Missing packet".to_string(), + raw: RawMsgTimeout { + packet: None, + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof".to_string(), + raw: RawMsgTimeout { + proof_unreceived: Vec::new(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof height".to_string(), + raw: RawMsgTimeout { + proof_height: None, + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Empty signer".to_string(), + raw: RawMsgTimeout { + signer: dummy_bech32_account(), + ..default_raw_msg + }, + want_pass: true, + }, + ]; + + for test in tests { + let res_msg: Result = test.raw.clone().try_into(); + + assert_eq!( + res_msg.is_ok(), + test.want_pass, + "MsgTimeout::try_from failed for test {} \nraw message: {:?} with error: {:?}", + test.name, + test.raw, + res_msg.err() + ); + } + } + + #[test] + fn to_and_from() { + let dummy_raw_msg_timeout = dummy_raw_msg_timeout(15, 20, 0); + let raw = dummy_raw_msg_timeout; + let msg = MsgTimeout::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgTimeout::from(msg.clone()); + let msg_back = MsgTimeout::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/channel/timeout_on_close.rs b/ibc-testkit/src/fixtures/core/channel/timeout_on_close.rs new file mode 100644 index 000000000..42db0e35f --- /dev/null +++ b/ibc-testkit/src/fixtures/core/channel/timeout_on_close.rs @@ -0,0 +1,106 @@ +use ibc::core::channel::types::proto::v1::MsgTimeoutOnClose as RawMsgTimeoutOnClose; +use ibc::core::client::types::proto::v1::Height as RawHeight; + +use super::{dummy_proof, dummy_raw_packet}; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgTimeoutOnClose`, for testing purposes only! +/// The `height` parametrizes both the proof height as well as the timeout height. +pub fn dummy_raw_msg_timeout_on_close(height: u64, timeout_timestamp: u64) -> RawMsgTimeoutOnClose { + RawMsgTimeoutOnClose { + packet: Some(dummy_raw_packet(height, timeout_timestamp)), + proof_unreceived: dummy_proof(), + proof_close: dummy_proof(), + proof_height: Some(RawHeight { + revision_number: 0, + revision_height: height, + }), + next_sequence_recv: 1, + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::channel::types::msgs::MsgTimeoutOnClose; + use ibc::primitives::prelude::*; + + use super::*; + + #[test] + fn msg_timeout_on_close_try_from_raw() { + let height = 50; + let timeout_timestamp = 5; + let raw = dummy_raw_msg_timeout_on_close(height, timeout_timestamp); + + let msg = MsgTimeoutOnClose::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgTimeoutOnClose::from(msg); + assert_eq!(raw, raw_back); + } + + #[test] + fn parse_timeout_on_close_msg() { + struct Test { + name: String, + raw: RawMsgTimeoutOnClose, + want_pass: bool, + } + + let height = 50; + let timeout_timestamp = 5; + let default_raw_msg = dummy_raw_msg_timeout_on_close(height, timeout_timestamp); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_raw_msg.clone(), + want_pass: true, + }, + Test { + name: "Missing packet".to_string(), + raw: RawMsgTimeoutOnClose { + packet: None, + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof of unreceived packet".to_string(), + raw: RawMsgTimeoutOnClose { + proof_unreceived: Vec::new(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof of channel".to_string(), + raw: RawMsgTimeoutOnClose { + proof_close: Vec::new(), + ..default_raw_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Missing proof height".to_string(), + raw: RawMsgTimeoutOnClose { + proof_height: None, + ..default_raw_msg + }, + want_pass: false, + }, + ]; + + for test in tests { + let res_msg = MsgTimeoutOnClose::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + res_msg.is_ok(), + "MsgTimeoutOnClose::try_from raw failed for test {}, \nraw msg {:?} with error {:?}", + test.name, + test.raw, + res_msg.err(), + ); + } + } +} diff --git a/ibc-testkit/src/fixtures/core/client/mod.rs b/ibc-testkit/src/fixtures/core/client/mod.rs new file mode 100644 index 000000000..e6807a097 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/client/mod.rs @@ -0,0 +1,113 @@ +#[cfg(feature = "serde")] +mod msg_create_client; +#[cfg(feature = "serde")] +mod msg_update_client; +mod msg_upgrade_client; + +#[cfg(feature = "serde")] +pub use msg_create_client::*; +#[cfg(feature = "serde")] +pub use msg_update_client::*; +pub use msg_upgrade_client::*; + +#[cfg(test)] +mod tests { + use core::str::FromStr; + + use ibc::core::client::types::events::*; + use ibc::core::client::types::Height; + use ibc::core::host::types::identifiers::*; + use ibc::primitives::prelude::*; + use ibc_proto::google::protobuf::Any; + use prost::Message; + use tendermint::abci::Event as AbciEvent; + + use crate::fixtures::clients::mock::dummy_new_mock_header; + + #[test] + fn ibc_to_abci_client_events() { + struct Test { + event_kind: &'static str, + event: AbciEvent, + expected_keys: Vec<&'static str>, + expected_values: Vec<&'static str>, + } + + let client_type = ClientType::from_str("07-tendermint") + .expect("never fails because it's a valid client type"); + let client_id = ClientId::new(client_type.clone(), 0).unwrap(); + let consensus_height = Height::new(0, 5).unwrap(); + let consensus_heights = vec![Height::new(0, 5).unwrap(), Height::new(0, 7).unwrap()]; + let header: Any = dummy_new_mock_header(5).into(); + let expected_keys = vec![ + "client_id", + "client_type", + "consensus_height", + "consensus_heights", + "header", + ]; + + let expected_values = vec![ + "07-tendermint-0", + "07-tendermint", + "0-5", + "0-5,0-7", + "0a102f6962632e6d6f636b2e48656164657212040a021005", + ]; + + let tests: Vec = vec![ + Test { + event_kind: CREATE_CLIENT_EVENT, + event: CreateClient::new(client_id.clone(), client_type.clone(), consensus_height) + .into(), + expected_keys: expected_keys[0..3].to_vec(), + expected_values: expected_values[0..3].to_vec(), + }, + Test { + event_kind: UPDATE_CLIENT_EVENT, + event: UpdateClient::new( + client_id.clone(), + client_type.clone(), + consensus_height, + consensus_heights, + header.encode_to_vec(), + ) + .into(), + expected_keys: expected_keys.clone(), + expected_values: expected_values.clone(), + }, + Test { + event_kind: UPGRADE_CLIENT_EVENT, + event: UpgradeClient::new(client_id.clone(), client_type.clone(), consensus_height) + .into(), + expected_keys: expected_keys[0..3].to_vec(), + expected_values: expected_values[0..3].to_vec(), + }, + Test { + event_kind: CLIENT_MISBEHAVIOUR_EVENT, + event: ClientMisbehaviour::new(client_id, client_type).into(), + expected_keys: expected_keys[0..2].to_vec(), + expected_values: expected_values[0..2].to_vec(), + }, + ]; + + for t in tests { + assert_eq!(t.event.kind, t.event_kind); + assert_eq!(t.expected_keys.len(), t.event.attributes.len()); + for (i, e) in t.event.attributes.iter().enumerate() { + assert_eq!( + e.key, t.expected_keys[i], + "key mismatch for {:?}", + t.event_kind + ); + } + for (i, e) in t.event.attributes.iter().enumerate() { + assert_eq!( + e.value, t.expected_values[i], + "value mismatch for {:?}", + t.event_kind + ); + } + } + } +} diff --git a/ibc-testkit/src/fixtures/core/client/msg_create_client.rs b/ibc-testkit/src/fixtures/core/client/msg_create_client.rs new file mode 100644 index 000000000..bc1cfbc31 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/client/msg_create_client.rs @@ -0,0 +1,38 @@ +use ibc::clients::tendermint::types::ConsensusState as TmConsensusState; +use ibc::core::client::types::proto::v1::MsgCreateClient as RawMsgCreateClient; +use ibc::primitives::proto::Any; + +use crate::fixtures::clients::tendermint::{ + dummy_tendermint_header, dummy_tm_client_state_from_header, +}; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgCreateClient`, for testing purposes only! +pub fn dummy_raw_msg_create_client() -> RawMsgCreateClient { + let tm_header = dummy_tendermint_header(); + + let tm_client_state = dummy_tm_client_state_from_header(tm_header.clone()); + + RawMsgCreateClient { + client_state: Some(Any::from(tm_client_state)), + consensus_state: Some(Any::from(TmConsensusState::from(tm_header))), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::client::types::msgs::MsgCreateClient; + + use super::*; + + #[test] + fn msg_create_client_serialization() { + let raw = dummy_raw_msg_create_client(); + let msg = MsgCreateClient::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgCreateClient::from(msg.clone()); + let msg_back = MsgCreateClient::try_from(raw_back.clone()).unwrap(); + assert_eq!(msg, msg_back); + assert_eq!(raw, raw_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/client/msg_update_client.rs b/ibc-testkit/src/fixtures/core/client/msg_update_client.rs new file mode 100644 index 000000000..980dee50b --- /dev/null +++ b/ibc-testkit/src/fixtures/core/client/msg_update_client.rs @@ -0,0 +1,35 @@ +use ibc::core::client::types::proto::v1::MsgUpdateClient as RawMsgUpdateClient; +use ibc::primitives::proto::Any; + +use crate::fixtures::clients::tendermint::dummy_ics07_header; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `RawMsgUpdateClient`, for testing purposes only! +pub fn dummy_raw_msg_update_client() -> RawMsgUpdateClient { + let client_id = "07-tendermint-0".parse().unwrap(); + + let tm_header = dummy_ics07_header(); + + RawMsgUpdateClient { + client_id, + client_message: Some(Any::from(tm_header)), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::client::types::msgs::MsgUpdateClient; + + use super::*; + + #[test] + fn msg_update_client_serialization() { + let raw = dummy_raw_msg_update_client(); + let msg = MsgUpdateClient::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgUpdateClient::from(msg.clone()); + let msg_back = MsgUpdateClient::try_from(raw_back.clone()).unwrap(); + assert_eq!(msg, msg_back); + assert_eq!(raw, raw_back); + } +} diff --git a/ibc-testkit/src/utils/dummies/core/client/msg_upgrade_client.rs b/ibc-testkit/src/fixtures/core/client/msg_upgrade_client.rs similarity index 71% rename from ibc-testkit/src/utils/dummies/core/client/msg_upgrade_client.rs rename to ibc-testkit/src/fixtures/core/client/msg_upgrade_client.rs index c5e75aae3..29ac5e080 100644 --- a/ibc-testkit/src/utils/dummies/core/client/msg_upgrade_client.rs +++ b/ibc-testkit/src/fixtures/core/client/msg_upgrade_client.rs @@ -3,11 +3,11 @@ use ibc::core::client::types::proto::v1::MsgUpgradeClient as RawMsgUpgradeClient use ibc::core::client::types::Height; use ibc::core::host::types::identifiers::ClientId; +use crate::fixtures::core::commitment::dummy_commitment_proof_bytes; +use crate::fixtures::core::signer::{dummy_account_id, dummy_bech32_account}; use crate::testapp::ibc::clients::mock::client_state::MockClientState; use crate::testapp::ibc::clients::mock::consensus_state::MockConsensusState; use crate::testapp::ibc::clients::mock::header::MockHeader; -use crate::utils::dummies::core::commitment::dummy_commitment_proof_bytes; -use crate::utils::dummies::core::signer::{dummy_account_id, dummy_bech32_account}; /// Returns a dummy `MsgUpgradeClient`, for testing purposes only! pub fn dummy_msg_upgrade_client(client_id: ClientId, upgrade_height: Height) -> MsgUpgradeClient { @@ -36,3 +36,21 @@ pub fn dummy_raw_msg_upgrade_client() -> RawMsgUpgradeClient { signer: dummy_bech32_account(), } } + +#[cfg(test)] +mod tests { + + use ibc::core::client::types::msgs::MsgUpgradeClient; + + use super::*; + + #[test] + fn msg_upgrade_client_serialization() { + let raw = dummy_raw_msg_upgrade_client(); + let msg = MsgUpgradeClient::try_from(raw.clone()).unwrap(); + let raw_back: RawMsgUpgradeClient = RawMsgUpgradeClient::from(msg.clone()); + let msg_back = MsgUpgradeClient::try_from(raw_back.clone()).unwrap(); + assert_eq!(msg, msg_back); + assert_eq!(raw, raw_back); + } +} diff --git a/ibc-testkit/src/utils/dummies/core/commitment.rs b/ibc-testkit/src/fixtures/core/commitment.rs similarity index 100% rename from ibc-testkit/src/utils/dummies/core/commitment.rs rename to ibc-testkit/src/fixtures/core/commitment.rs diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs new file mode 100644 index 000000000..f690e430a --- /dev/null +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs @@ -0,0 +1,133 @@ +use ibc::core::client::types::proto::v1::Height as RawHeight; +use ibc::core::client::types::Height; +use ibc::core::connection::types::msgs::MsgConnectionOpenAck; +use ibc::core::connection::types::proto::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; +use ibc::core::connection::types::version::Version; +use ibc::core::host::types::identifiers::ConnectionId; +use ibc::core::primitives::prelude::*; + +use crate::fixtures::core::channel::dummy_proof; +use crate::fixtures::core::signer::dummy_bech32_account; +use crate::testapp::ibc::clients::mock::client_state::MockClientState; +use crate::testapp::ibc::clients::mock::header::MockHeader; + +/// Returns a dummy `MsgConnectionOpenAck` with dummy values. +pub fn dummy_msg_conn_open_ack(proof_height: u64, consensus_height: u64) -> MsgConnectionOpenAck { + MsgConnectionOpenAck::try_from(dummy_raw_msg_conn_open_ack(proof_height, consensus_height)) + .expect("Never fails") +} + +/// Returns a dummy `RawMsgConnectionOpenAck`, for testing purposes only! +pub fn dummy_raw_msg_conn_open_ack( + proof_height: u64, + consensus_height: u64, +) -> RawMsgConnectionOpenAck { + let client_state_height = Height::new(0, consensus_height).expect("invalid height"); + RawMsgConnectionOpenAck { + connection_id: ConnectionId::new(0).to_string(), + counterparty_connection_id: ConnectionId::new(1).to_string(), + proof_try: dummy_proof(), + proof_height: Some(RawHeight { + revision_number: 0, + revision_height: proof_height, + }), + proof_consensus: dummy_proof(), + consensus_height: Some(RawHeight { + revision_number: 0, + revision_height: consensus_height, + }), + client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), + proof_client: dummy_proof(), + version: Some(Version::default().into()), + signer: dummy_bech32_account(), + host_consensus_state_proof: vec![], + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_connection_open_ack_msg() { + #[derive(Clone, Debug, PartialEq)] + struct Test { + name: String, + raw: RawMsgConnectionOpenAck, + want_pass: bool, + } + + let default_ack_msg = dummy_raw_msg_conn_open_ack(5, 5); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_ack_msg.clone(), + want_pass: true, + }, + Test { + name: "Bad connection id, non-alpha".to_string(), + raw: RawMsgConnectionOpenAck { + connection_id: "con007".to_string(), + ..default_ack_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad version, missing version".to_string(), + raw: RawMsgConnectionOpenAck { + version: None, + ..default_ack_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad proof height, height is 0".to_string(), + raw: RawMsgConnectionOpenAck { + proof_height: Some(RawHeight { + revision_number: 1, + revision_height: 0, + }), + ..default_ack_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad consensus height, height is 0".to_string(), + raw: RawMsgConnectionOpenAck { + consensus_height: Some(RawHeight { + revision_number: 1, + revision_height: 0, + }), + ..default_ack_msg + }, + want_pass: false, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let msg = MsgConnectionOpenAck::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + msg.is_ok(), + "MsgConnOpenAck::new failed for test {}, \nmsg {:?} with error {:?}", + test.name, + test.raw, + msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_conn_open_ack(5, 6); + let msg = MsgConnectionOpenAck::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgConnectionOpenAck::from(msg.clone()); + let msg_back = MsgConnectionOpenAck::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_confirm.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_confirm.rs new file mode 100644 index 000000000..151ab7e37 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_confirm.rs @@ -0,0 +1,93 @@ +use ibc::core::client::types::proto::v1::Height; +use ibc::core::connection::types::msgs::MsgConnectionOpenConfirm; +use ibc::core::connection::types::proto::v1::MsgConnectionOpenConfirm as RawMsgConnectionOpenConfirm; +use ibc::primitives::prelude::*; + +use crate::fixtures::core::channel::dummy_proof; +use crate::fixtures::core::signer::dummy_bech32_account; + +/// Returns a dummy `MsgConnectionOpenConfirm` for testing purposes only! +pub fn dummy_conn_open_confirm() -> MsgConnectionOpenConfirm { + MsgConnectionOpenConfirm::try_from(dummy_raw_msg_conn_open_confirm()).expect("Never fails") +} + +/// Returns a dummy `RawMsgConnectionOpenConfirm` for testing purposes only! +pub fn dummy_raw_msg_conn_open_confirm() -> RawMsgConnectionOpenConfirm { + RawMsgConnectionOpenConfirm { + connection_id: "srcconnection".to_string(), + proof_ack: dummy_proof(), + proof_height: Some(Height { + revision_number: 0, + revision_height: 10, + }), + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_connection_open_confirm_msg() { + #[derive(Clone, Debug, PartialEq)] + struct Test { + name: String, + raw: RawMsgConnectionOpenConfirm, + want_pass: bool, + } + + let default_ack_msg = dummy_raw_msg_conn_open_confirm(); + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_ack_msg.clone(), + want_pass: true, + }, + Test { + name: "Bad connection id, non-alpha".to_string(), + raw: RawMsgConnectionOpenConfirm { + connection_id: "con007".to_string(), + ..default_ack_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad proof height, height is 0".to_string(), + raw: RawMsgConnectionOpenConfirm { + proof_height: Some(Height { + revision_number: 1, + revision_height: 0, + }), + ..default_ack_msg + }, + want_pass: false, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let msg = MsgConnectionOpenConfirm::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + msg.is_ok(), + "MsgConnOpenTry::new failed for test {}, \nmsg {:?} with error {:?}", + test.name, + test.raw, + msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_conn_open_confirm(); + let msg = MsgConnectionOpenConfirm::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgConnectionOpenConfirm::from(msg.clone()); + let msg_back = MsgConnectionOpenConfirm::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } +} diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs new file mode 100644 index 000000000..07302e0de --- /dev/null +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs @@ -0,0 +1,192 @@ +use ibc::core::connection::types::msgs::MsgConnectionOpenInit; +use ibc::core::connection::types::proto::v1::{ + MsgConnectionOpenInit as RawMsgConnectionOpenInit, Version as RawVersion, +}; +use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::Counterparty; +use ibc::core::host::types::identifiers::ClientId; +use ibc::core::primitives::prelude::*; + +use super::dummy_raw_counterparty_conn; +use crate::fixtures::core::signer::dummy_bech32_account; + +pub fn raw_version_from_identifier(identifier: &str) -> Option { + if identifier.is_empty() { + return None; + } + + Some(RawVersion { + identifier: identifier.to_string(), + features: vec![], + }) +} + +/// Returns a dummy `MsgConnectionOpenInit` for testing purposes only! +pub fn dummy_msg_conn_open_init() -> MsgConnectionOpenInit { + MsgConnectionOpenInit::try_from(dummy_raw_msg_conn_open_init()).expect("Never fails") +} + +/// Setter for `client_id`. Amenable to chaining, since it consumes the input message. +pub fn dummy_msg_conn_open_init_with_client_id( + msg: MsgConnectionOpenInit, + client_id: ClientId, +) -> MsgConnectionOpenInit { + MsgConnectionOpenInit { + client_id_on_a: client_id, + ..msg + } +} + +/// Setter for `counterparty`. Amenable to chaining, since it consumes the input message. +pub fn msg_conn_open_init_with_counterparty_conn_id( + msg: MsgConnectionOpenInit, + counterparty_conn_id: u64, +) -> MsgConnectionOpenInit { + let counterparty = + Counterparty::try_from(dummy_raw_counterparty_conn(Some(counterparty_conn_id))) + .expect("Never fails"); + MsgConnectionOpenInit { + counterparty, + ..msg + } +} + +/// Setter for the connection `version` +pub fn msg_conn_open_with_version( + msg: MsgConnectionOpenInit, + identifier: Option<&str>, +) -> MsgConnectionOpenInit { + let version = match identifier { + Some(v) => Version::try_from(RawVersion { + identifier: v.to_string(), + features: vec![], + }) + .expect("could not create version from identifier") + .into(), + None => None, + }; + MsgConnectionOpenInit { version, ..msg } +} + +/// Returns a dummy `RawMsgConnectionOpenInit`, for testing purposes only! +pub fn dummy_raw_msg_conn_open_init() -> RawMsgConnectionOpenInit { + RawMsgConnectionOpenInit { + client_id: ClientId::default().to_string(), + counterparty: Some(dummy_raw_counterparty_conn(None)), + version: Some(Version::default().into()), + delay_period: 0, + signer: dummy_bech32_account(), + } +} + +#[cfg(test)] +mod tests { + use ibc::core::connection::types::proto::v1::Counterparty as RawCounterparty; + + use super::*; + + #[test] + fn parse_connection_open_init_msg() { + #[derive(Clone, Debug, PartialEq)] + struct Test { + name: String, + raw: RawMsgConnectionOpenInit, + want_pass: bool, + } + + let default_init_msg = dummy_raw_msg_conn_open_init(); + + let tests: Vec = vec![ + Test { + name: "Good parameters".to_string(), + raw: default_init_msg.clone(), + want_pass: true, + }, + Test { + name: "Bad client id, name too short".to_string(), + raw: RawMsgConnectionOpenInit { + client_id: "client".to_string(), + ..default_init_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad destination connection id, name too long".to_string(), + raw: RawMsgConnectionOpenInit { + counterparty: Some(RawCounterparty { + connection_id: + "abcdefghijksdffjssdkflweldflsfladfsfwjkrekcmmsdfsdfjflddmnopqrstu" + .to_string(), + ..dummy_raw_counterparty_conn(None) + }), + ..default_init_msg + }, + want_pass: false, + }, + ] + .into_iter() + .collect(); + + for test in tests { + let msg = MsgConnectionOpenInit::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + msg.is_ok(), + "MsgConnOpenInit::new failed for test {}, \nmsg {:?} with error {:?}", + test.name, + test.raw, + msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_conn_open_init(); + let msg = MsgConnectionOpenInit::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgConnectionOpenInit::from(msg.clone()); + let msg_back = MsgConnectionOpenInit::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + + // Check if handler sets counterparty connection id to `None` + // in case relayer passes `MsgConnectionOpenInit` message with it set to `Some(_)`. + let raw_with_counterparty_conn_id_some = dummy_raw_msg_conn_open_init(); + let msg_with_counterparty_conn_id_some = + MsgConnectionOpenInit::try_from(raw_with_counterparty_conn_id_some).unwrap(); + let raw_with_counterparty_conn_id_some_back = + RawMsgConnectionOpenInit::from(msg_with_counterparty_conn_id_some.clone()); + let msg_with_counterparty_conn_id_some_back = + MsgConnectionOpenInit::try_from(raw_with_counterparty_conn_id_some_back.clone()) + .unwrap(); + assert_eq!( + raw_with_counterparty_conn_id_some_back + .counterparty + .unwrap() + .connection_id, + "".to_string() + ); + assert_eq!( + msg_with_counterparty_conn_id_some, + msg_with_counterparty_conn_id_some_back + ); + } + + /// Test that borsh serialization/deserialization works well with delay periods up to u64::MAX + #[cfg(feature = "borsh")] + #[test] + fn test_borsh() { + let mut raw = dummy_raw_msg_conn_open_init(); + raw.delay_period = u64::MAX; + let msg = MsgConnectionOpenInit::try_from(raw.clone()).unwrap(); + + let serialized = borsh::to_vec(&msg).unwrap(); + + let msg_deserialized = + ::try_from_slice(&serialized) + .unwrap(); + + assert_eq!(msg, msg_deserialized); + } +} diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs new file mode 100644 index 000000000..5780dd928 --- /dev/null +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs @@ -0,0 +1,208 @@ +use ibc::core::client::types::proto::v1::Height as RawHeight; +use ibc::core::client::types::Height; +use ibc::core::connection::types::msgs::MsgConnectionOpenTry; +use ibc::core::connection::types::proto::v1::MsgConnectionOpenTry as RawMsgConnectionOpenTry; +use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; +use ibc::core::primitives::prelude::*; + +use super::dummy_raw_counterparty_conn; +use crate::fixtures::core::channel::dummy_proof; +use crate::fixtures::core::signer::dummy_bech32_account; +use crate::testapp::ibc::clients::mock::client_state::MockClientState; +use crate::testapp::ibc::clients::mock::header::MockHeader; + +/// Returns a dummy `MsgConnectionOpenTry` for testing purposes only! +pub fn dummy_msg_conn_open_try(proof_height: u64, consensus_height: u64) -> MsgConnectionOpenTry { + MsgConnectionOpenTry::try_from(dummy_raw_msg_conn_open_try(proof_height, consensus_height)) + .expect("Never fails") +} +/// Setter for the `client_id` +pub fn msg_conn_open_try_with_client_id( + msg: MsgConnectionOpenTry, + client_id: ClientId, +) -> MsgConnectionOpenTry { + MsgConnectionOpenTry { + client_id_on_b: client_id, + ..msg + } +} + +/// Returns a dummy `RawMsgConnectionOpenTry` with parametrized heights. The parameter +/// `proof_height` represents the height, on the source chain, at which this chain produced the +/// proof. Parameter `consensus_height` represents the height of destination chain which a +/// client on the source chain stores. +pub fn dummy_raw_msg_conn_open_try( + proof_height: u64, + consensus_height: u64, +) -> RawMsgConnectionOpenTry { + let client_state_height = Height::new(0, consensus_height).expect("could not create height"); + + #[allow(deprecated)] + RawMsgConnectionOpenTry { + client_id: ClientId::default().to_string(), + previous_connection_id: ConnectionId::default().to_string(), + client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), + counterparty: Some(dummy_raw_counterparty_conn(Some(0))), + delay_period: 0, + counterparty_versions: get_compatible_versions() + .iter() + .map(|v| v.clone().into()) + .collect(), + proof_init: dummy_proof(), + proof_height: Some(RawHeight { + revision_number: 0, + revision_height: proof_height, + }), + proof_consensus: dummy_proof(), + consensus_height: Some(RawHeight { + revision_number: 0, + revision_height: consensus_height, + }), + proof_client: dummy_proof(), + signer: dummy_bech32_account(), + host_consensus_state_proof: vec![], + } +} + +#[cfg(test)] +mod tests { + use ibc::core::connection::types::proto::v1::Counterparty as RawCounterparty; + + use super::*; + + #[test] + fn parse_connection_open_try_msg() { + #[derive(Clone, Debug, PartialEq)] + struct Test { + name: String, + raw: RawMsgConnectionOpenTry, + want_pass: bool, + } + + let default_try_msg = dummy_raw_msg_conn_open_try(10, 34); + + let tests: Vec = + vec![ + Test { + name: "Good parameters".to_string(), + raw: default_try_msg.clone(), + want_pass: true, + }, + Test { + name: "Bad client id, name too short".to_string(), + raw: RawMsgConnectionOpenTry { + client_id: "client".to_string(), + ..default_try_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad destination connection id, name too long".to_string(), + raw: RawMsgConnectionOpenTry { + counterparty: Some(RawCounterparty { + connection_id: + "abcdasdfasdfsdfasfdwefwfsdfsfsfasfwewvxcvdvwgadvaadsefghijklmnopqrstu" + .to_string(), + ..dummy_raw_counterparty_conn(Some(0)) + }), + ..default_try_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Correct destination client id with lower/upper case and special chars" + .to_string(), + raw: RawMsgConnectionOpenTry { + counterparty: Some(RawCounterparty { + client_id: "ClientId_".to_string(), + ..dummy_raw_counterparty_conn(Some(0)) + }), + ..default_try_msg.clone() + }, + want_pass: true, + }, + Test { + name: "Bad counterparty versions, empty versions vec".to_string(), + raw: RawMsgConnectionOpenTry { + counterparty_versions: Vec::new(), + ..default_try_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad counterparty versions, empty version string".to_string(), + raw: RawMsgConnectionOpenTry { + counterparty_versions: Vec::new(), + ..default_try_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad proof height, height is 0".to_string(), + raw: RawMsgConnectionOpenTry { + proof_height: Some(RawHeight { revision_number: 1, revision_height: 0 }), + ..default_try_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Bad consensus height, height is 0".to_string(), + raw: RawMsgConnectionOpenTry { + proof_height: Some(RawHeight { revision_number: 1, revision_height: 0 }), + ..default_try_msg.clone() + }, + want_pass: false, + }, + Test { + name: "Empty proof".to_string(), + raw: RawMsgConnectionOpenTry { + proof_init: b"".to_vec(), + ..default_try_msg + }, + want_pass: false, + } + ] + .into_iter() + .collect(); + + for test in tests { + let msg = MsgConnectionOpenTry::try_from(test.raw.clone()); + + assert_eq!( + test.want_pass, + msg.is_ok(), + "MsgConnOpenTry::new failed for test {}, \nmsg {:?} with error {:?}", + test.name, + test.raw, + msg.err(), + ); + } + } + + #[test] + fn to_and_from() { + let raw = dummy_raw_msg_conn_open_try(10, 34); + let msg = MsgConnectionOpenTry::try_from(raw.clone()).unwrap(); + let raw_back = RawMsgConnectionOpenTry::from(msg.clone()); + let msg_back = MsgConnectionOpenTry::try_from(raw_back.clone()).unwrap(); + assert_eq!(raw, raw_back); + assert_eq!(msg, msg_back); + } + + /// Test that borsh serialization/deserialization works well with delay periods up to u64::MAX + #[cfg(feature = "borsh")] + #[test] + fn test_borsh() { + let mut raw = dummy_raw_msg_conn_open_try(10, 34); + raw.delay_period = u64::MAX; + let msg = MsgConnectionOpenTry::try_from(raw.clone()).unwrap(); + + let serialized = borsh::to_vec(&msg).unwrap(); + + let msg_deserialized = + ::try_from_slice(&serialized).unwrap(); + + assert_eq!(msg, msg_deserialized); + } +} diff --git a/ibc-testkit/src/utils/dummies/core/connection/mod.rs b/ibc-testkit/src/fixtures/core/connection/mod.rs similarity index 100% rename from ibc-testkit/src/utils/dummies/core/connection/mod.rs rename to ibc-testkit/src/fixtures/core/connection/mod.rs diff --git a/ibc-testkit/src/utils/dummies/core/context.rs b/ibc-testkit/src/fixtures/core/context.rs similarity index 100% rename from ibc-testkit/src/utils/dummies/core/context.rs rename to ibc-testkit/src/fixtures/core/context.rs diff --git a/ibc-testkit/src/utils/dummies/core/mod.rs b/ibc-testkit/src/fixtures/core/mod.rs similarity index 100% rename from ibc-testkit/src/utils/dummies/core/mod.rs rename to ibc-testkit/src/fixtures/core/mod.rs diff --git a/ibc-testkit/src/utils/dummies/core/signer.rs b/ibc-testkit/src/fixtures/core/signer.rs similarity index 100% rename from ibc-testkit/src/utils/dummies/core/signer.rs rename to ibc-testkit/src/fixtures/core/signer.rs diff --git a/ibc-testkit/src/utils/fixture.rs b/ibc-testkit/src/fixtures/mod.rs similarity index 91% rename from ibc-testkit/src/utils/fixture.rs rename to ibc-testkit/src/fixtures/mod.rs index 6b3a5eb1a..af14cadb9 100644 --- a/ibc-testkit/src/utils/fixture.rs +++ b/ibc-testkit/src/fixtures/mod.rs @@ -1,4 +1,7 @@ -use core::fmt::Debug; +pub mod applications; +pub mod clients; +pub mod core; +use alloc::fmt::Debug; use ibc::core::handler::types::error::ContextError; use ibc::core::primitives::prelude::*; diff --git a/ibc-testkit/src/lib.rs b/ibc-testkit/src/lib.rs index 3b42e390e..1ae269367 100644 --- a/ibc-testkit/src/lib.rs +++ b/ibc-testkit/src/lib.rs @@ -12,9 +12,10 @@ extern crate alloc; +#[cfg(feature = "std")] extern crate std; +pub mod fixtures; pub mod hosts; pub mod relayer; pub mod testapp; -pub mod utils; diff --git a/ibc-testkit/src/testapp/ibc/core/types.rs b/ibc-testkit/src/testapp/ibc/core/types.rs index be31e896a..40b44c34a 100644 --- a/ibc-testkit/src/testapp/ibc/core/types.rs +++ b/ibc-testkit/src/testapp/ibc/core/types.rs @@ -30,6 +30,9 @@ use tracing::debug; use typed_builder::TypedBuilder; use super::client_ctx::{MockClientRecord, PortChannelIdMap}; +use crate::fixtures::clients::tendermint::{ + dummy_tm_client_state_from_header, ClientStateConfig as TmClientStateConfig, +}; use crate::hosts::block::{HostBlock, HostType}; use crate::relayer::error::RelayerError; use crate::testapp::ibc::clients::mock::client_state::{ @@ -38,9 +41,6 @@ use crate::testapp::ibc::clients::mock::client_state::{ use crate::testapp::ibc::clients::mock::consensus_state::MockConsensusState; use crate::testapp::ibc::clients::mock::header::MockHeader; use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState}; -use crate::utils::clients::tendermint::{ - dummy_tm_client_state_from_header, ClientStateConfig as TmClientStateConfig, -}; pub const DEFAULT_BLOCK_TIME_SECS: u64 = 3; /// An object that stores all IBC related data. @@ -796,9 +796,9 @@ mod tests { use test_log::test; use super::*; + use crate::fixtures::core::channel::PacketConfig; + use crate::fixtures::core::signer::dummy_bech32_account; use crate::testapp::ibc::core::router::MockRouter; - use crate::utils::core::channel::PacketConfig; - use crate::utils::core::signer::dummy_bech32_account; #[test] fn test_history_manipulation() { diff --git a/ibc-testkit/src/utils/dummies/core/channel/acknowledgement.rs b/ibc-testkit/src/utils/dummies/core/channel/acknowledgement.rs deleted file mode 100644 index 64314696a..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/acknowledgement.rs +++ /dev/null @@ -1,26 +0,0 @@ -use ibc::core::channel::types::proto::v1::{ - MsgAcknowledgement as RawMsgAcknowledgement, Packet as RawPacket, -}; -use ibc::core::client::types::proto::v1::Height as RawHeight; - -use super::{dummy_proof, dummy_raw_packet}; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgAcknowledgement`, for testing purposes only! -/// The `height` parametrizes both the proof height as well as the timeout height. -pub fn dummy_raw_msg_acknowledgement(height: u64) -> RawMsgAcknowledgement { - dummy_raw_msg_ack_with_packet(dummy_raw_packet(height, 1), height) -} - -pub fn dummy_raw_msg_ack_with_packet(packet: RawPacket, height: u64) -> RawMsgAcknowledgement { - RawMsgAcknowledgement { - packet: Some(packet), - acknowledgement: dummy_proof(), - proof_acked: dummy_proof(), - proof_height: Some(RawHeight { - revision_number: 0, - revision_height: height, - }), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/chan_close_confirm.rs b/ibc-testkit/src/utils/dummies/core/channel/chan_close_confirm.rs deleted file mode 100644 index 1ee818729..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/chan_close_confirm.rs +++ /dev/null @@ -1,21 +0,0 @@ -use ibc::core::channel::types::proto::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm; -use ibc::core::client::types::proto::v1::Height; -use ibc::core::host::types::identifiers::{ChannelId, PortId}; -use ibc::core::primitives::prelude::*; - -use super::dummy_proof; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgChannelCloseConfirm`, for testing purposes only! -pub fn dummy_raw_msg_chan_close_confirm(proof_height: u64) -> RawMsgChannelCloseConfirm { - RawMsgChannelCloseConfirm { - port_id: PortId::transfer().to_string(), - channel_id: ChannelId::default().to_string(), - proof_init: dummy_proof(), - proof_height: Some(Height { - revision_number: 0, - revision_height: proof_height, - }), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/chan_close_init.rs b/ibc-testkit/src/utils/dummies/core/channel/chan_close_init.rs deleted file mode 100644 index 9753b02a5..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/chan_close_init.rs +++ /dev/null @@ -1,14 +0,0 @@ -use ibc::core::channel::types::proto::v1::MsgChannelCloseInit as RawMsgChannelCloseInit; -use ibc::core::host::types::identifiers::{ChannelId, PortId}; -use ibc::core::primitives::prelude::*; - -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgChannelCloseInit`, for testing purposes only! -pub fn dummy_raw_msg_chan_close_init() -> RawMsgChannelCloseInit { - RawMsgChannelCloseInit { - port_id: PortId::transfer().to_string(), - channel_id: ChannelId::default().to_string(), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/chan_open_ack.rs b/ibc-testkit/src/utils/dummies/core/channel/chan_open_ack.rs deleted file mode 100644 index 0436fc1b2..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/chan_open_ack.rs +++ /dev/null @@ -1,23 +0,0 @@ -use ibc::core::channel::types::proto::v1::MsgChannelOpenAck as RawMsgChannelOpenAck; -use ibc::core::client::types::proto::v1::Height; -use ibc::core::host::types::identifiers::{ChannelId, PortId}; -use ibc::core::primitives::prelude::*; - -use super::dummy_proof; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgChannelOpenAck`, for testing purposes only! -pub fn dummy_raw_msg_chan_open_ack(proof_height: u64) -> RawMsgChannelOpenAck { - RawMsgChannelOpenAck { - port_id: PortId::transfer().to_string(), - channel_id: ChannelId::default().to_string(), - counterparty_channel_id: ChannelId::default().to_string(), - counterparty_version: "".to_string(), - proof_try: dummy_proof(), - proof_height: Some(Height { - revision_number: 0, - revision_height: proof_height, - }), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/chan_open_confirm.rs b/ibc-testkit/src/utils/dummies/core/channel/chan_open_confirm.rs deleted file mode 100644 index 03c661f6d..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/chan_open_confirm.rs +++ /dev/null @@ -1,21 +0,0 @@ -use ibc::core::channel::types::proto::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm; -use ibc::core::client::types::proto::v1::Height; -use ibc::core::host::types::identifiers::{ChannelId, PortId}; -use ibc::core::primitives::prelude::*; - -use super::dummy_proof; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgChannelOpenConfirm`, for testing purposes only! -pub fn dummy_raw_msg_chan_open_confirm(proof_height: u64) -> RawMsgChannelOpenConfirm { - RawMsgChannelOpenConfirm { - port_id: PortId::transfer().to_string(), - channel_id: ChannelId::default().to_string(), - proof_ack: dummy_proof(), - proof_height: Some(Height { - revision_number: 0, - revision_height: proof_height, - }), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/chan_open_init.rs b/ibc-testkit/src/utils/dummies/core/channel/chan_open_init.rs deleted file mode 100644 index 090027aba..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/chan_open_init.rs +++ /dev/null @@ -1,15 +0,0 @@ -use ibc::core::channel::types::proto::v1::MsgChannelOpenInit as RawMsgChannelOpenInit; -use ibc::core::host::types::identifiers::PortId; -use ibc::core::primitives::prelude::*; - -use super::dummy_raw_channel_end; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgChannelOpenInit`, for testing purposes only! -pub fn dummy_raw_msg_chan_open_init(counterparty_channel_id: Option) -> RawMsgChannelOpenInit { - RawMsgChannelOpenInit { - port_id: PortId::transfer().to_string(), - channel: Some(dummy_raw_channel_end(1, counterparty_channel_id)), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/chan_open_try.rs b/ibc-testkit/src/utils/dummies/core/channel/chan_open_try.rs deleted file mode 100644 index 85a4fa036..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/chan_open_try.rs +++ /dev/null @@ -1,24 +0,0 @@ -use ibc::core::channel::types::proto::v1::MsgChannelOpenTry as RawMsgChannelOpenTry; -use ibc::core::client::types::proto::v1::Height; -use ibc::core::host::types::identifiers::PortId; -use ibc::core::primitives::prelude::*; - -use super::{dummy_proof, dummy_raw_channel_end}; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgChannelOpenTry`, for testing purposes only! -pub fn dummy_raw_msg_chan_open_try(proof_height: u64) -> RawMsgChannelOpenTry { - #[allow(deprecated)] - RawMsgChannelOpenTry { - port_id: PortId::transfer().to_string(), - previous_channel_id: "".to_string(), - channel: Some(dummy_raw_channel_end(2, Some(0))), - counterparty_version: "".to_string(), - proof_init: dummy_proof(), - proof_height: Some(Height { - revision_number: 0, - revision_height: proof_height, - }), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/mod.rs b/ibc-testkit/src/utils/dummies/core/channel/mod.rs deleted file mode 100644 index fad50ad02..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/mod.rs +++ /dev/null @@ -1,52 +0,0 @@ -mod acknowledgement; -mod chan_close_confirm; -mod chan_close_init; -mod chan_open_ack; -mod chan_open_confirm; -mod chan_open_init; -mod chan_open_try; -mod packet; -mod recv_packet; -mod timeout; -mod timeout_on_close; - -pub use acknowledgement::*; -pub use chan_close_confirm::*; -pub use chan_close_init::*; -pub use chan_open_ack::*; -pub use chan_open_confirm::*; -pub use chan_open_init::*; -pub use chan_open_try::*; -use ibc::core::channel::types::proto::v1::{ - Channel as RawChannel, Counterparty as RawCounterparty, -}; -use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; -use ibc::core::primitives::prelude::*; -pub use packet::*; -pub use recv_packet::*; -pub use timeout::*; -pub use timeout_on_close::*; - -/// Returns a dummy `RawCounterparty`, for testing purposes only! -/// Can be optionally parametrized with a specific channel identifier. -pub fn dummy_raw_counterparty_chan(channel_id: String) -> RawCounterparty { - RawCounterparty { - port_id: PortId::transfer().to_string(), - channel_id, - } -} - -/// Returns a dummy `RawChannel`, for testing purposes only! -pub fn dummy_raw_channel_end(state: i32, channel_id: Option) -> RawChannel { - let channel_id = match channel_id { - Some(id) => ChannelId::new(id).to_string(), - None => "".to_string(), - }; - RawChannel { - state, - ordering: 2, - counterparty: Some(dummy_raw_counterparty_chan(channel_id)), - connection_hops: vec![ConnectionId::default().to_string()], - version: "".to_string(), // The version is not validated. - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/packet.rs b/ibc-testkit/src/utils/dummies/core/channel/packet.rs deleted file mode 100644 index 7682c4200..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/packet.rs +++ /dev/null @@ -1,68 +0,0 @@ -use ibc::core::channel::types::packet::Packet; -use ibc::core::channel::types::proto::v1::Packet as RawPacket; -use ibc::core::channel::types::timeout::TimeoutHeight; -use ibc::core::client::types::proto::v1::Height as RawHeight; -use ibc::core::host::types::identifiers::{ChannelId, PortId, Sequence}; -use ibc::core::primitives::prelude::*; -use ibc::core::primitives::Timestamp; -use typed_builder::TypedBuilder; - -/// Configuration of the `PacketData` type for building dummy packets. -#[derive(TypedBuilder, Debug)] -#[builder(build_method(into = Packet))] -pub struct PacketConfig { - #[builder(default)] - pub seq_on_a: Sequence, - #[builder(default = PortId::transfer())] - pub port_id_on_a: PortId, - #[builder(default)] - pub chan_id_on_a: ChannelId, - #[builder(default = PortId::transfer())] - pub port_id_on_b: PortId, - #[builder(default)] - pub chan_id_on_b: ChannelId, - #[builder(default)] - pub data: Vec, - #[builder(default)] - pub timeout_height_on_b: TimeoutHeight, - #[builder(default)] - pub timeout_timestamp_on_b: Timestamp, -} - -impl From for Packet { - fn from(config: PacketConfig) -> Self { - Packet { - seq_on_a: config.seq_on_a, - port_id_on_a: config.port_id_on_a, - chan_id_on_a: config.chan_id_on_a, - port_id_on_b: config.port_id_on_b, - chan_id_on_b: config.chan_id_on_b, - data: config.data, - timeout_height_on_b: config.timeout_height_on_b, - timeout_timestamp_on_b: config.timeout_timestamp_on_b, - } - } -} - -/// Returns a dummy `RawPacket`, for testing purposes only! -pub fn dummy_raw_packet(timeout_height: u64, timeout_timestamp: u64) -> RawPacket { - RawPacket { - sequence: 1, - source_port: PortId::transfer().to_string(), - source_channel: ChannelId::default().to_string(), - destination_port: PortId::transfer().to_string(), - destination_channel: ChannelId::default().to_string(), - data: vec![0], - timeout_height: Some(RawHeight { - revision_number: 0, - revision_height: timeout_height, - }), - timeout_timestamp, - } -} - -pub fn dummy_proof() -> Vec { - "Y29uc2Vuc3VzU3RhdGUvaWJjb25lY2xpZW50LzIy" - .as_bytes() - .to_vec() -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/recv_packet.rs b/ibc-testkit/src/utils/dummies/core/channel/recv_packet.rs deleted file mode 100644 index a758961c4..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/recv_packet.rs +++ /dev/null @@ -1,45 +0,0 @@ -use core::ops::Add; -use core::time::Duration; - -use ibc::core::channel::types::msgs::MsgRecvPacket; -use ibc::core::channel::types::packet::Packet; -use ibc::core::channel::types::proto::v1::MsgRecvPacket as RawMsgRecvPacket; -use ibc::core::client::types::proto::v1::Height as RawHeight; -use ibc::core::client::types::Height; -use ibc::core::commitment_types::commitment::CommitmentProofBytes; -use ibc::core::primitives::{Signer, Timestamp}; - -use super::{dummy_proof, dummy_raw_packet}; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -pub fn dummy_msg_recv_packet( - packet: Packet, - proof_commitment_on_a: CommitmentProofBytes, - proof_height_on_a: Height, - signer: Signer, -) -> MsgRecvPacket { - MsgRecvPacket { - packet, - proof_commitment_on_a, - proof_height_on_a, - signer, - } -} - -/// Returns a dummy `RawMsgRecvPacket`, for testing purposes only! The `height` -/// parametrizes both the proof height as well as the timeout height. -pub fn dummy_raw_msg_recv_packet(height: u64) -> RawMsgRecvPacket { - let timestamp = Timestamp::now().add(Duration::from_secs(9)); - RawMsgRecvPacket { - packet: Some(dummy_raw_packet( - height, - timestamp.expect("timestamp").nanoseconds(), - )), - proof_commitment: dummy_proof(), - proof_height: Some(RawHeight { - revision_number: 0, - revision_height: height, - }), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/timeout.rs b/ibc-testkit/src/utils/dummies/core/channel/timeout.rs deleted file mode 100644 index 1c24f7ec1..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/timeout.rs +++ /dev/null @@ -1,24 +0,0 @@ -use ibc::core::channel::types::proto::v1::MsgTimeout as RawMsgTimeout; -use ibc::core::client::types::proto::v1::Height as RawHeight; - -use super::{dummy_proof, dummy_raw_packet}; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgTimeout`, for testing purposes only! -/// The `height` parametrizes both the proof height as well as the timeout height. -pub fn dummy_raw_msg_timeout( - proof_height: u64, - timeout_height: u64, - timeout_timestamp: u64, -) -> RawMsgTimeout { - RawMsgTimeout { - packet: Some(dummy_raw_packet(timeout_height, timeout_timestamp)), - proof_unreceived: dummy_proof(), - proof_height: Some(RawHeight { - revision_number: 0, - revision_height: proof_height, - }), - next_sequence_recv: 1, - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/channel/timeout_on_close.rs b/ibc-testkit/src/utils/dummies/core/channel/timeout_on_close.rs deleted file mode 100644 index 0aca9f223..000000000 --- a/ibc-testkit/src/utils/dummies/core/channel/timeout_on_close.rs +++ /dev/null @@ -1,21 +0,0 @@ -use ibc::core::channel::types::proto::v1::MsgTimeoutOnClose as RawMsgTimeoutOnClose; -use ibc::core::client::types::proto::v1::Height as RawHeight; - -use super::{dummy_proof, dummy_raw_packet}; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgTimeoutOnClose`, for testing purposes only! -/// The `height` parametrizes both the proof height as well as the timeout height. -pub fn dummy_raw_msg_timeout_on_close(height: u64, timeout_timestamp: u64) -> RawMsgTimeoutOnClose { - RawMsgTimeoutOnClose { - packet: Some(dummy_raw_packet(height, timeout_timestamp)), - proof_unreceived: dummy_proof(), - proof_close: dummy_proof(), - proof_height: Some(RawHeight { - revision_number: 0, - revision_height: height, - }), - next_sequence_recv: 1, - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/client/mod.rs b/ibc-testkit/src/utils/dummies/core/client/mod.rs deleted file mode 100644 index aaacce78c..000000000 --- a/ibc-testkit/src/utils/dummies/core/client/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[cfg(feature = "serde")] -mod msg_create_client; -#[cfg(feature = "serde")] -mod msg_update_client; -mod msg_upgrade_client; - -#[cfg(feature = "serde")] -pub use msg_create_client::*; -#[cfg(feature = "serde")] -pub use msg_update_client::*; -pub use msg_upgrade_client::*; diff --git a/ibc-testkit/src/utils/dummies/core/client/msg_create_client.rs b/ibc-testkit/src/utils/dummies/core/client/msg_create_client.rs deleted file mode 100644 index 75bf4fa9f..000000000 --- a/ibc-testkit/src/utils/dummies/core/client/msg_create_client.rs +++ /dev/null @@ -1,21 +0,0 @@ -use ibc::clients::tendermint::types::ConsensusState as TmConsensusState; -use ibc::core::client::types::proto::v1::MsgCreateClient; -use ibc::primitives::proto::Any; - -use crate::utils::dummies::clients::tendermint::{ - dummy_tendermint_header, dummy_tm_client_state_from_header, -}; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgCreateClient`, for testing purposes only! -pub fn dummy_raw_msg_create_client() -> MsgCreateClient { - let tm_header = dummy_tendermint_header(); - - let tm_client_state = dummy_tm_client_state_from_header(tm_header.clone()); - - MsgCreateClient { - client_state: Some(Any::from(tm_client_state)), - consensus_state: Some(Any::from(TmConsensusState::from(tm_header))), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/client/msg_update_client.rs b/ibc-testkit/src/utils/dummies/core/client/msg_update_client.rs deleted file mode 100644 index 18ca4243e..000000000 --- a/ibc-testkit/src/utils/dummies/core/client/msg_update_client.rs +++ /dev/null @@ -1,18 +0,0 @@ -use ibc::core::client::types::proto::v1::MsgUpdateClient; -use ibc::primitives::proto::Any; - -use crate::utils::dummies::clients::tendermint::dummy_ics07_header; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `RawMsgUpdateClient`, for testing purposes only! -pub fn dummy_raw_msg_update_client() -> MsgUpdateClient { - let client_id = "07-tendermint-0".parse().unwrap(); - - let tm_header = dummy_ics07_header(); - - MsgUpdateClient { - client_id, - client_message: Some(Any::from(tm_header)), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/connection/conn_open_ack.rs b/ibc-testkit/src/utils/dummies/core/connection/conn_open_ack.rs deleted file mode 100644 index f0782cae2..000000000 --- a/ibc-testkit/src/utils/dummies/core/connection/conn_open_ack.rs +++ /dev/null @@ -1,45 +0,0 @@ -use ibc::core::client::types::proto::v1::Height as RawHeight; -use ibc::core::client::types::Height; -use ibc::core::connection::types::msgs::MsgConnectionOpenAck; -use ibc::core::connection::types::proto::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; -use ibc::core::connection::types::version::Version; -use ibc::core::host::types::identifiers::ConnectionId; -use ibc::core::primitives::prelude::*; - -use crate::testapp::ibc::clients::mock::client_state::MockClientState; -use crate::testapp::ibc::clients::mock::header::MockHeader; -use crate::utils::dummies::core::channel::dummy_proof; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `MsgConnectionOpenAck` with dummy values. -pub fn dummy_msg_conn_open_ack(proof_height: u64, consensus_height: u64) -> MsgConnectionOpenAck { - MsgConnectionOpenAck::try_from(dummy_raw_msg_conn_open_ack(proof_height, consensus_height)) - .expect("Never fails") -} - -/// Returns a dummy `RawMsgConnectionOpenAck`, for testing purposes only! -pub fn dummy_raw_msg_conn_open_ack( - proof_height: u64, - consensus_height: u64, -) -> RawMsgConnectionOpenAck { - let client_state_height = Height::new(0, consensus_height).expect("invalid height"); - RawMsgConnectionOpenAck { - connection_id: ConnectionId::new(0).to_string(), - counterparty_connection_id: ConnectionId::new(1).to_string(), - proof_try: dummy_proof(), - proof_height: Some(RawHeight { - revision_number: 0, - revision_height: proof_height, - }), - proof_consensus: dummy_proof(), - consensus_height: Some(RawHeight { - revision_number: 0, - revision_height: consensus_height, - }), - client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), - proof_client: dummy_proof(), - version: Some(Version::default().into()), - signer: dummy_bech32_account(), - host_consensus_state_proof: vec![], - } -} diff --git a/ibc-testkit/src/utils/dummies/core/connection/conn_open_confirm.rs b/ibc-testkit/src/utils/dummies/core/connection/conn_open_confirm.rs deleted file mode 100644 index 58a0348f9..000000000 --- a/ibc-testkit/src/utils/dummies/core/connection/conn_open_confirm.rs +++ /dev/null @@ -1,26 +0,0 @@ -use alloc::string::ToString; - -use ibc::core::client::types::proto::v1::Height; -use ibc::core::connection::types::msgs::MsgConnectionOpenConfirm; -use ibc::core::connection::types::proto::v1::MsgConnectionOpenConfirm as RawMsgConnectionOpenConfirm; - -use crate::utils::dummies::core::channel::dummy_proof; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `MsgConnectionOpenConfirm` for testing purposes only! -pub fn dummy_conn_open_confirm() -> MsgConnectionOpenConfirm { - MsgConnectionOpenConfirm::try_from(dummy_raw_msg_conn_open_confirm()).expect("Never fails") -} - -/// Returns a dummy `RawMsgConnectionOpenConfirm` for testing purposes only! -pub fn dummy_raw_msg_conn_open_confirm() -> RawMsgConnectionOpenConfirm { - RawMsgConnectionOpenConfirm { - connection_id: "srcconnection".to_string(), - proof_ack: dummy_proof(), - proof_height: Some(Height { - revision_number: 0, - revision_height: 10, - }), - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/connection/conn_open_init.rs b/ibc-testkit/src/utils/dummies/core/connection/conn_open_init.rs deleted file mode 100644 index 24eadd989..000000000 --- a/ibc-testkit/src/utils/dummies/core/connection/conn_open_init.rs +++ /dev/null @@ -1,80 +0,0 @@ -use ibc::core::connection::types::msgs::MsgConnectionOpenInit; -use ibc::core::connection::types::proto::v1::{ - MsgConnectionOpenInit as RawMsgConnectionOpenInit, Version as RawVersion, -}; -use ibc::core::connection::types::version::Version; -use ibc::core::connection::types::Counterparty; -use ibc::core::host::types::identifiers::ClientId; -use ibc::core::primitives::prelude::*; - -use super::dummy_raw_counterparty_conn; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -pub fn raw_version_from_identifier(identifier: &str) -> Option { - if identifier.is_empty() { - return None; - } - - Some(RawVersion { - identifier: identifier.to_string(), - features: vec![], - }) -} - -/// Returns a dummy `MsgConnectionOpenInit` for testing purposes only! -pub fn dummy_msg_conn_open_init() -> MsgConnectionOpenInit { - MsgConnectionOpenInit::try_from(dummy_raw_msg_conn_open_init()).expect("Never fails") -} - -/// Setter for `client_id`. Amenable to chaining, since it consumes the input message. -pub fn dummy_msg_conn_open_init_with_client_id( - msg: MsgConnectionOpenInit, - client_id: ClientId, -) -> MsgConnectionOpenInit { - MsgConnectionOpenInit { - client_id_on_a: client_id, - ..msg - } -} - -/// Setter for `counterparty`. Amenable to chaining, since it consumes the input message. -pub fn msg_conn_open_init_with_counterparty_conn_id( - msg: MsgConnectionOpenInit, - counterparty_conn_id: u64, -) -> MsgConnectionOpenInit { - let counterparty = - Counterparty::try_from(dummy_raw_counterparty_conn(Some(counterparty_conn_id))) - .expect("Never fails"); - MsgConnectionOpenInit { - counterparty, - ..msg - } -} - -/// Setter for the connection `version` -pub fn msg_conn_open_with_version( - msg: MsgConnectionOpenInit, - identifier: Option<&str>, -) -> MsgConnectionOpenInit { - let version = match identifier { - Some(v) => Version::try_from(RawVersion { - identifier: v.to_string(), - features: vec![], - }) - .expect("could not create version from identifier") - .into(), - None => None, - }; - MsgConnectionOpenInit { version, ..msg } -} - -/// Returns a dummy `RawMsgConnectionOpenInit`, for testing purposes only! -pub fn dummy_raw_msg_conn_open_init() -> RawMsgConnectionOpenInit { - RawMsgConnectionOpenInit { - client_id: ClientId::default().to_string(), - counterparty: Some(dummy_raw_counterparty_conn(None)), - version: Some(Version::default().into()), - delay_period: 0, - signer: dummy_bech32_account(), - } -} diff --git a/ibc-testkit/src/utils/dummies/core/connection/conn_open_try.rs b/ibc-testkit/src/utils/dummies/core/connection/conn_open_try.rs deleted file mode 100644 index 464e2c7f0..000000000 --- a/ibc-testkit/src/utils/dummies/core/connection/conn_open_try.rs +++ /dev/null @@ -1,66 +0,0 @@ -use ibc::core::client::types::proto::v1::Height as RawHeight; -use ibc::core::client::types::Height; -use ibc::core::connection::types::msgs::MsgConnectionOpenTry; -use ibc::core::connection::types::proto::v1::MsgConnectionOpenTry as RawMsgConnectionOpenTry; -use ibc::core::connection::types::version::get_compatible_versions; -use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; -use ibc::core::primitives::prelude::*; - -use super::dummy_raw_counterparty_conn; -use crate::testapp::ibc::clients::mock::client_state::MockClientState; -use crate::testapp::ibc::clients::mock::header::MockHeader; -use crate::utils::dummies::core::channel::dummy_proof; -use crate::utils::dummies::core::signer::dummy_bech32_account; - -/// Returns a dummy `MsgConnectionOpenTry` for testing purposes only! -pub fn dummy_msg_conn_open_try(proof_height: u64, consensus_height: u64) -> MsgConnectionOpenTry { - MsgConnectionOpenTry::try_from(dummy_raw_msg_conn_open_try(proof_height, consensus_height)) - .expect("Never fails") -} -/// Setter for the `client_id` -pub fn msg_conn_open_try_with_client_id( - msg: MsgConnectionOpenTry, - client_id: ClientId, -) -> MsgConnectionOpenTry { - MsgConnectionOpenTry { - client_id_on_b: client_id, - ..msg - } -} - -/// Returns a dummy `RawMsgConnectionOpenTry` with parametrized heights. The parameter -/// `proof_height` represents the height, on the source chain, at which this chain produced the -/// proof. Parameter `consensus_height` represents the height of destination chain which a -/// client on the source chain stores. -pub fn dummy_raw_msg_conn_open_try( - proof_height: u64, - consensus_height: u64, -) -> RawMsgConnectionOpenTry { - let client_state_height = Height::new(0, consensus_height).expect("could not create height"); - - #[allow(deprecated)] - RawMsgConnectionOpenTry { - client_id: ClientId::default().to_string(), - previous_connection_id: ConnectionId::default().to_string(), - client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), - counterparty: Some(dummy_raw_counterparty_conn(Some(0))), - delay_period: 0, - counterparty_versions: get_compatible_versions() - .iter() - .map(|v| v.clone().into()) - .collect(), - proof_init: dummy_proof(), - proof_height: Some(RawHeight { - revision_number: 0, - revision_height: proof_height, - }), - proof_consensus: dummy_proof(), - consensus_height: Some(RawHeight { - revision_number: 0, - revision_height: consensus_height, - }), - proof_client: dummy_proof(), - signer: dummy_bech32_account(), - host_consensus_state_proof: vec![], - } -} diff --git a/ibc-testkit/src/utils/dummies/mod.rs b/ibc-testkit/src/utils/dummies/mod.rs deleted file mode 100644 index f13a3c645..000000000 --- a/ibc-testkit/src/utils/dummies/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod applications; -pub mod clients; -pub mod core; diff --git a/ibc-testkit/src/utils/mod.rs b/ibc-testkit/src/utils/mod.rs deleted file mode 100644 index 35f40c216..000000000 --- a/ibc-testkit/src/utils/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod dummies; -mod fixture; - -pub use dummies::*; -pub use fixture::*; diff --git a/ibc-testkit/tests/core/ics02_client/create_client.rs b/ibc-testkit/tests/core/ics02_client/create_client.rs index 103dd06c7..fe69a4a05 100644 --- a/ibc-testkit/tests/core/ics02_client/create_client.rs +++ b/ibc-testkit/tests/core/ics02_client/create_client.rs @@ -8,6 +8,10 @@ use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::ClientId; use ibc::core::host::ValidationContext; +use ibc_testkit::fixtures::clients::tendermint::{ + dummy_tendermint_header, dummy_tm_client_state_from_header, +}; +use ibc_testkit::fixtures::core::signer::dummy_account_id; use ibc_testkit::testapp::ibc::clients::mock::client_state::{ client_type as mock_client_type, MockClientState, }; @@ -15,10 +19,6 @@ use ibc_testkit::testapp::ibc::clients::mock::consensus_state::MockConsensusStat use ibc_testkit::testapp::ibc::clients::mock::header::MockHeader; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::clients::tendermint::{ - dummy_tendermint_header, dummy_tm_client_state_from_header, -}; -use ibc_testkit::utils::core::signer::dummy_account_id; use test_log::test; #[test] diff --git a/ibc-testkit/tests/core/ics02_client/update_client.rs b/ibc-testkit/tests/core/ics02_client/update_client.rs index b629adeed..1011b7a3c 100644 --- a/ibc-testkit/tests/core/ics02_client/update_client.rs +++ b/ibc-testkit/tests/core/ics02_client/update_client.rs @@ -20,6 +20,8 @@ use ibc::core::host::types::path::ClientConsensusStatePath; use ibc::core::host::ValidationContext; use ibc::core::primitives::{downcast, Timestamp}; use ibc::primitives::proto::Any; +use ibc_testkit::fixtures::core::context::MockContextConfig; +use ibc_testkit::fixtures::core::signer::dummy_account_id; use ibc_testkit::hosts::block::{HostBlock, HostType}; use ibc_testkit::testapp::ibc::clients::mock::client_state::{ client_type as mock_client_type, MockClientState, @@ -29,8 +31,6 @@ use ibc_testkit::testapp::ibc::clients::mock::misbehaviour::Misbehaviour as Mock use ibc_testkit::testapp::ibc::clients::AnyConsensusState; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::{MockClientConfig, MockContext}; -use ibc_testkit::utils::core::context::MockContextConfig; -use ibc_testkit::utils::core::signer::dummy_account_id; use prost::Message; use tendermint_testgen::Validator as TestgenValidator; use test_log::test; diff --git a/ibc-testkit/tests/core/ics02_client/upgrade_client.rs b/ibc-testkit/tests/core/ics02_client/upgrade_client.rs index 1f86d410c..6b7b3eff2 100644 --- a/ibc-testkit/tests/core/ics02_client/upgrade_client.rs +++ b/ibc-testkit/tests/core/ics02_client/upgrade_client.rs @@ -10,15 +10,15 @@ use ibc::core::host::types::identifiers::ClientId; use ibc::core::host::types::path::ClientConsensusStatePath; use ibc::core::host::ValidationContext; use ibc::core::primitives::downcast; +use ibc_testkit::fixtures::clients::tendermint::{ + dummy_tendermint_header, dummy_tm_client_state_from_header, +}; +use ibc_testkit::fixtures::core::client::dummy_msg_upgrade_client; +use ibc_testkit::fixtures::{Expect, Fixture}; use ibc_testkit::testapp::ibc::clients::mock::client_state::client_type as mock_client_type; use ibc_testkit::testapp::ibc::clients::{AnyClientState, AnyConsensusState}; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::clients::tendermint::{ - dummy_tendermint_header, dummy_tm_client_state_from_header, -}; -use ibc_testkit::utils::core::client::dummy_msg_upgrade_client; -use ibc_testkit::utils::{Expect, Fixture}; enum Ctx { Default, diff --git a/ibc-testkit/tests/core/ics03_connection/conn_open_ack.rs b/ibc-testkit/tests/core/ics03_connection/conn_open_ack.rs index 51617f664..7987f355e 100644 --- a/ibc-testkit/tests/core/ics03_connection/conn_open_ack.rs +++ b/ibc-testkit/tests/core/ics03_connection/conn_open_ack.rs @@ -13,11 +13,11 @@ use ibc::core::host::types::identifiers::{ChainId, ClientId}; use ibc::core::host::ValidationContext; use ibc::core::primitives::prelude::*; use ibc::core::primitives::ZERO_DURATION; +use ibc_testkit::fixtures::core::connection::dummy_msg_conn_open_ack; +use ibc_testkit::fixtures::{Expect, Fixture}; use ibc_testkit::hosts::block::HostType; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::connection::dummy_msg_conn_open_ack; -use ibc_testkit::utils::{Expect, Fixture}; use test_log::test; enum Ctx { diff --git a/ibc-testkit/tests/core/ics03_connection/conn_open_confirm.rs b/ibc-testkit/tests/core/ics03_connection/conn_open_confirm.rs index f39417b8a..94321028d 100644 --- a/ibc-testkit/tests/core/ics03_connection/conn_open_confirm.rs +++ b/ibc-testkit/tests/core/ics03_connection/conn_open_confirm.rs @@ -11,10 +11,10 @@ use ibc::core::host::types::identifiers::ClientId; use ibc::core::host::ValidationContext; use ibc::core::primitives::prelude::*; use ibc::core::primitives::ZERO_DURATION; +use ibc_testkit::fixtures::core::connection::dummy_conn_open_confirm; +use ibc_testkit::fixtures::{Expect, Fixture}; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::connection::dummy_conn_open_confirm; -use ibc_testkit::utils::{Expect, Fixture}; use test_log::test; enum Ctx { diff --git a/ibc-testkit/tests/core/ics03_connection/conn_open_init.rs b/ibc-testkit/tests/core/ics03_connection/conn_open_init.rs index 1e78e4dcd..deee41dba 100644 --- a/ibc-testkit/tests/core/ics03_connection/conn_open_init.rs +++ b/ibc-testkit/tests/core/ics03_connection/conn_open_init.rs @@ -7,13 +7,13 @@ use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::ValidationContext; use ibc::core::primitives::prelude::*; -use ibc_testkit::testapp::ibc::core::router::MockRouter; -use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::connection::{ +use ibc_testkit::fixtures::core::connection::{ dummy_msg_conn_open_init, msg_conn_open_init_with_counterparty_conn_id, msg_conn_open_with_version, }; -use ibc_testkit::utils::{Expect, Fixture}; +use ibc_testkit::fixtures::{Expect, Fixture}; +use ibc_testkit::testapp::ibc::core::router::MockRouter; +use ibc_testkit::testapp::ibc::core::types::MockContext; use test_log::test; enum Ctx { diff --git a/ibc-testkit/tests/core/ics03_connection/conn_open_try.rs b/ibc-testkit/tests/core/ics03_connection/conn_open_try.rs index e1a662c6c..44a5160cc 100644 --- a/ibc-testkit/tests/core/ics03_connection/conn_open_try.rs +++ b/ibc-testkit/tests/core/ics03_connection/conn_open_try.rs @@ -7,11 +7,11 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::ChainId; use ibc::core::host::ValidationContext; use ibc::core::primitives::prelude::*; +use ibc_testkit::fixtures::core::connection::dummy_msg_conn_open_try; +use ibc_testkit::fixtures::{Expect, Fixture}; use ibc_testkit::hosts::block::HostType; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::connection::dummy_msg_conn_open_try; -use ibc_testkit::utils::{Expect, Fixture}; use test_log::test; enum Ctx { diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index 11fed0970..2f5872bfe 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -14,9 +14,9 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; +use ibc_testkit::fixtures::core::channel::dummy_raw_msg_acknowledgement; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_msg_acknowledgement; use rstest::*; use test_log::test; diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs index b308a2d29..5e91a7be9 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs @@ -11,11 +11,11 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; use ibc::core::host::ValidationContext; use ibc::core::primitives::*; +use ibc_testkit::fixtures::core::channel::dummy_raw_msg_chan_close_confirm; +use ibc_testkit::fixtures::core::connection::dummy_raw_counterparty_conn; use ibc_testkit::testapp::ibc::clients::mock::client_state::client_type as mock_client_type; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_close_confirm; -use ibc_testkit::utils::core::connection::dummy_raw_counterparty_conn; #[test] fn test_chan_close_confirm_validate() { diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs index 286a84c15..8ede99523 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs @@ -11,11 +11,11 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; use ibc::core::host::ValidationContext; use ibc::core::primitives::*; +use ibc_testkit::fixtures::core::channel::dummy_raw_msg_chan_close_init; +use ibc_testkit::fixtures::core::connection::dummy_raw_counterparty_conn; use ibc_testkit::testapp::ibc::clients::mock::client_state::client_type as mock_client_type; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_close_init; -use ibc_testkit::utils::core::connection::dummy_raw_counterparty_conn; #[test] fn test_chan_close_init_validate() { diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs index b5932d227..aec54f2ba 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs @@ -12,11 +12,11 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; use ibc::core::primitives::*; use ibc::core::router::types::module::ModuleId; +use ibc_testkit::fixtures::core::channel::dummy_raw_msg_chan_open_ack; +use ibc_testkit::fixtures::core::connection::dummy_raw_counterparty_conn; use ibc_testkit::testapp::ibc::clients::mock::client_state::client_type as mock_client_type; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_open_ack; -use ibc_testkit::utils::core::connection::dummy_raw_counterparty_conn; use rstest::*; use test_log::test; diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs index 6b3513571..c077c1e9e 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs @@ -11,11 +11,11 @@ use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId}; use ibc::core::primitives::*; +use ibc_testkit::fixtures::core::channel::dummy_raw_msg_chan_open_confirm; +use ibc_testkit::fixtures::core::connection::dummy_raw_counterparty_conn; use ibc_testkit::testapp::ibc::clients::mock::client_state::client_type as mock_client_type; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_open_confirm; -use ibc_testkit::utils::core::connection::dummy_raw_counterparty_conn; use rstest::*; use test_log::test; diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs index 590f68e56..8d6b6172f 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs @@ -8,10 +8,10 @@ use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; use ibc::core::host::ValidationContext; +use ibc_testkit::fixtures::core::channel::dummy_raw_msg_chan_open_init; +use ibc_testkit::fixtures::core::connection::dummy_msg_conn_open_init; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_open_init; -use ibc_testkit::utils::core::connection::dummy_msg_conn_open_init; use rstest::*; use test_log::test; diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs index 3ebe68460..09db155f7 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs @@ -10,11 +10,11 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; use ibc::core::host::ValidationContext; use ibc::core::primitives::*; +use ibc_testkit::fixtures::core::channel::dummy_raw_msg_chan_open_try; +use ibc_testkit::fixtures::core::connection::dummy_raw_counterparty_conn; use ibc_testkit::testapp::ibc::clients::mock::client_state::client_type as mock_client_type; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_msg_chan_open_try; -use ibc_testkit::utils::core::connection::dummy_raw_counterparty_conn; use rstest::*; use test_log::test; diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index 90fda5f92..20a7c97ab 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -14,11 +14,11 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; +use ibc_testkit::fixtures::core::channel::{dummy_msg_recv_packet, dummy_raw_msg_recv_packet}; +use ibc_testkit::fixtures::core::signer::dummy_account_id; use ibc_testkit::relayer::context::RelayerContext; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::{dummy_msg_recv_packet, dummy_raw_msg_recv_packet}; -use ibc_testkit::utils::core::signer::dummy_account_id; use rstest::*; use test_log::test; diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index d3b1fcbc4..2ae01f6cf 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -13,8 +13,8 @@ use ibc::core::connection::types::{ use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::primitives::*; +use ibc_testkit::fixtures::core::channel::dummy_raw_packet; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_packet; use test_log::test; #[test] diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 10cbe83c8..37556b612 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -14,9 +14,9 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; +use ibc_testkit::fixtures::core::channel::dummy_raw_msg_timeout; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_msg_timeout; use rstest::*; struct Fixture { diff --git a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs index 5e7a1b538..9c32642b9 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -13,9 +13,9 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; +use ibc_testkit::fixtures::core::channel::dummy_raw_msg_timeout_on_close; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::core::channel::dummy_raw_msg_timeout_on_close; use rstest::*; pub struct Fixture { diff --git a/ibc-testkit/tests/core/router.rs b/ibc-testkit/tests/core/router.rs index 59708282d..68969ba0f 100644 --- a/ibc-testkit/tests/core/router.rs +++ b/ibc-testkit/tests/core/router.rs @@ -20,26 +20,26 @@ use ibc::core::host::types::path::CommitmentPath; use ibc::core::host::ValidationContext; use ibc::core::primitives::prelude::*; use ibc::core::primitives::Timestamp; -use ibc_testkit::testapp::ibc::applications::transfer::types::DummyTransferModule; -use ibc_testkit::testapp::ibc::clients::mock::client_state::MockClientState; -use ibc_testkit::testapp::ibc::clients::mock::consensus_state::MockConsensusState; -use ibc_testkit::testapp::ibc::clients::mock::header::MockHeader; -use ibc_testkit::testapp::ibc::core::router::MockRouter; -use ibc_testkit::testapp::ibc::core::types::MockContext; -use ibc_testkit::utils::applications::transfer::{ +use ibc_testkit::fixtures::applications::transfer::{ extract_transfer_packet, MsgTransferConfig, PacketDataConfig, }; -use ibc_testkit::utils::core::channel::{ +use ibc_testkit::fixtures::core::channel::{ dummy_raw_msg_ack_with_packet, dummy_raw_msg_chan_close_confirm, dummy_raw_msg_chan_close_init, dummy_raw_msg_chan_open_ack, dummy_raw_msg_chan_open_init, dummy_raw_msg_chan_open_try, dummy_raw_msg_recv_packet, dummy_raw_msg_timeout_on_close, }; -use ibc_testkit::utils::core::client::dummy_msg_upgrade_client; -use ibc_testkit::utils::core::connection::{ +use ibc_testkit::fixtures::core::client::dummy_msg_upgrade_client; +use ibc_testkit::fixtures::core::connection::{ dummy_msg_conn_open_ack, dummy_msg_conn_open_init, dummy_msg_conn_open_init_with_client_id, dummy_msg_conn_open_try, msg_conn_open_try_with_client_id, }; -use ibc_testkit::utils::core::signer::dummy_account_id; +use ibc_testkit::fixtures::core::signer::dummy_account_id; +use ibc_testkit::testapp::ibc::applications::transfer::types::DummyTransferModule; +use ibc_testkit::testapp::ibc::clients::mock::client_state::MockClientState; +use ibc_testkit::testapp::ibc::clients::mock::consensus_state::MockConsensusState; +use ibc_testkit::testapp::ibc::clients::mock::header::MockHeader; +use ibc_testkit::testapp::ibc::core::router::MockRouter; +use ibc_testkit::testapp::ibc::core::types::MockContext; use primitive_types::U256; use test_log::test;