diff --git a/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md b/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md new file mode 100644 index 000000000..fcf1cafe6 --- /dev/null +++ b/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md @@ -0,0 +1,2 @@ +- [types] Refactor `Default` implementations with concrete names + ([\#1074](https://github.com/cosmos/ibc-rs/issues/1074)) diff --git a/docs/architecture/adr-005-handlers-redesign.md b/docs/architecture/adr-005-handlers-redesign.md index a4c25890a..855a2b668 100644 --- a/docs/architecture/adr-005-handlers-redesign.md +++ b/docs/architecture/adr-005-handlers-redesign.md @@ -296,7 +296,7 @@ trait ValidationContext { /// Function required by ICS 03. Returns the list of all possible versions that the connection /// handshake protocol supports. fn get_compatible_versions(&self) -> Vec { - get_compatible_versions() + ConnectionVersion::compatibles() } /// Function required by ICS 03. Returns one version out of the supplied list of versions, which the diff --git a/ibc-apps/ics20-transfer/types/src/denom.rs b/ibc-apps/ics20-transfer/types/src/denom.rs index c76eaf062..65b38fe67 100644 --- a/ibc-apps/ics20-transfer/types/src/denom.rs +++ b/ibc-apps/ics20-transfer/types/src/denom.rs @@ -109,7 +109,7 @@ impl Display for TracePrefix { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, From)] +#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, From)] pub struct TracePath(Vec); impl TracePath { @@ -134,6 +134,11 @@ impl TracePath { pub fn is_empty(&self) -> bool { self.0.is_empty() } + + /// Return empty trace path + pub fn empty() -> Self { + Self(vec![]) + } } impl<'a> TryFrom> for TracePath { @@ -294,7 +299,7 @@ impl FromStr for PrefixedDenom { let (base_denom, trace_path) = { if last_part == s { - (BaseDenom::from_str(s)?, TracePath::default()) + (BaseDenom::from_str(s)?, TracePath::empty()) } else { let base_denom = BaseDenom::from_str(last_part)?; let trace_path = TracePath::try_from(parts)?; @@ -334,7 +339,7 @@ impl From for RawDenomTrace { impl From for PrefixedDenom { fn from(denom: BaseDenom) -> Self { Self { - trace_path: Default::default(), + trace_path: TracePath::empty(), base_denom: denom, } } diff --git a/ibc-apps/ics20-transfer/types/src/memo.rs b/ibc-apps/ics20-transfer/types/src/memo.rs index 9a3caea74..a49c40beb 100644 --- a/ibc-apps/ics20-transfer/types/src/memo.rs +++ b/ibc-apps/ics20-transfer/types/src/memo.rs @@ -45,6 +45,12 @@ impl From for Memo { } } +impl From<&str> for Memo { + fn from(memo: &str) -> Self { + Self(memo.to_owned()) + } +} + impl FromStr for Memo { type Err = Infallible; diff --git a/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs b/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs index 270164701..4cf1a759c 100644 --- a/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs +++ b/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs @@ -81,14 +81,14 @@ where &msg.chan_id_on_a, class_id, token_id, - &packet_data.memo.clone().unwrap_or_default(), + &packet_data.memo.clone().unwrap_or("".into()), )?; } else { transfer_ctx.burn_nft_validate( &sender, class_id, token_id, - &packet_data.memo.clone().unwrap_or_default(), + &packet_data.memo.clone().unwrap_or("".into()), )?; } let nft = transfer_ctx.get_nft(class_id, token_id)?; @@ -184,14 +184,14 @@ where &msg.chan_id_on_a, class_id, token_id, - &packet_data.memo.clone().unwrap_or_default(), + &packet_data.memo.clone().unwrap_or("".into()), )?; } else { transfer_ctx.burn_nft_execute( &sender, class_id, token_id, - &packet_data.memo.clone().unwrap_or_default(), + &packet_data.memo.clone().unwrap_or("".into()), )?; } let nft = transfer_ctx.get_nft(class_id, token_id)?; @@ -242,7 +242,7 @@ where receiver: packet_data.receiver, class: packet_data.class_id, tokens: packet_data.token_ids, - memo: packet_data.memo.unwrap_or_default(), + memo: packet_data.memo.unwrap_or("".into()), }; send_packet_ctx_a.emit_ibc_event(ModuleEvent::from(transfer_event).into())?; diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index 337bffcad..074e7c869 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -1,5 +1,4 @@ //! Provides IBC module callbacks implementation for the ICS-721 transfer. - use ibc_core::channel::types::acknowledgement::{Acknowledgement, AcknowledgementStatus}; use ibc_core::channel::types::channel::{Counterparty, Order}; use ibc_core::channel::types::packet::Packet; @@ -190,7 +189,7 @@ pub fn on_recv_packet_execute( receiver: data.receiver, class: data.class_id, tokens: data.token_ids, - memo: data.memo.unwrap_or_default(), + memo: data.memo.unwrap_or("".into()), success: ack.is_successful(), }; extras.events.push(recv_event.into()); @@ -250,7 +249,7 @@ pub fn on_acknowledgement_packet_execute( receiver: data.receiver, class: data.class_id, tokens: data.token_ids, - memo: data.memo.unwrap_or_default(), + memo: data.memo.unwrap_or("".into()), acknowledgement: acknowledgement.clone(), }; @@ -295,7 +294,7 @@ pub fn on_timeout_packet_execute( refund_receiver: data.sender, refund_class: data.class_id, refund_tokens: data.token_ids, - memo: data.memo.unwrap_or_default(), + memo: data.memo.unwrap_or("".into()), }; let extras = ModuleExtras { diff --git a/ibc-apps/ics721-nft-transfer/types/src/class.rs b/ibc-apps/ics721-nft-transfer/types/src/class.rs index adbc95f92..c2ff9afd4 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/class.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/class.rs @@ -106,7 +106,7 @@ impl Display for TracePrefix { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, From)] +#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, From)] pub struct TracePath(Vec); impl TracePath { @@ -131,6 +131,11 @@ impl TracePath { pub fn is_empty(&self) -> bool { self.0.is_empty() } + + /// Return empty trace path + pub fn empty() -> Self { + Self(vec![]) + } } impl<'a> TryFrom> for TracePath { @@ -268,7 +273,7 @@ impl FromStr for PrefixedClassId { let (base_class_id, trace_path) = { if last_part == s { - (ClassId::from_str(s)?, TracePath::default()) + (ClassId::from_str(s)?, TracePath::empty()) } else { let base_class_id = ClassId::from_str(last_part)?; let trace_path = TracePath::try_from(parts)?; @@ -308,7 +313,7 @@ impl From for RawClassTrace { impl From for PrefixedClassId { fn from(class_id: ClassId) -> Self { Self { - trace_path: Default::default(), + trace_path: TracePath::empty(), base_class_id: class_id, } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/data.rs b/ibc-apps/ics721-nft-transfer/types/src/data.rs index e6e4afbee..ef4b86e55 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/data.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/data.rs @@ -24,7 +24,7 @@ use crate::error::NftTransferError; derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, PartialEq, Eq, derive_more::From)] +#[derive(Clone, Debug, PartialEq, Eq, derive_more::From)] pub struct Data(String); #[cfg(feature = "serde")] @@ -88,7 +88,7 @@ impl<'de> serde::Deserialize<'de> for Data { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Ics721Data(BTreeMap); #[cfg(feature = "serde")] @@ -100,7 +100,7 @@ impl FromStr for Ics721Data { } } -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct DataValue { value: String, mime: Option, diff --git a/ibc-apps/ics721-nft-transfer/types/src/memo.rs b/ibc-apps/ics721-nft-transfer/types/src/memo.rs index 432dd4fc6..b18f2027d 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/memo.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/memo.rs @@ -24,7 +24,7 @@ use ibc_core::primitives::prelude::*; )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Memo(String); impl AsRef for Memo { @@ -45,6 +45,12 @@ impl From for Memo { } } +impl From<&str> for Memo { + fn from(memo: &str) -> Self { + Self(memo.to_owned()) + } +} + impl FromStr for Memo { type Err = Infallible; diff --git a/ibc-clients/ics07-tendermint/src/client_state.rs b/ibc-clients/ics07-tendermint/src/client_state.rs index 13c10b963..9f1fe3139 100644 --- a/ibc-clients/ics07-tendermint/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/src/client_state.rs @@ -111,8 +111,8 @@ mod tests { unbonding_period: Duration::new(128_000, 0), max_clock_drift: Duration::new(3, 0), latest_height: Height::new(1, 10).expect("Never fails"), - proof_specs: ProofSpecs::default(), - upgrade_path: Default::default(), + proof_specs: ProofSpecs::cosmos(), + upgrade_path: Vec::new(), allow_update: AllowUpdate { after_expiry: false, after_misbehaviour: false, diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index a533858a2..0208d0426 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -438,8 +438,8 @@ mod tests { unbonding_period: Duration::new(128_000, 0), max_clock_drift: Duration::new(3, 0), latest_height: Height::new(0, 10).expect("Never fails"), - proof_specs: ProofSpecs::default(), - upgrade_path: Default::default(), + proof_specs: ProofSpecs::cosmos(), + upgrade_path: Vec::new(), allow_update: AllowUpdate { after_expiry: false, after_misbehaviour: false, diff --git a/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs b/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs index 9ca77a660..07f2bbb70 100644 --- a/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs +++ b/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs @@ -134,12 +134,6 @@ impl TryFrom for TrustThreshold { } } -impl Default for TrustThreshold { - fn default() -> Self { - Self::ONE_THIRD - } -} - impl Display for TrustThreshold { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { write!(f, "{}/{}", self.numerator, self.denominator) diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index d73d53930..8225763a4 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -1,6 +1,7 @@ //! Defines the types that define a connection use core::fmt::{Display, Error as FmtError, Formatter}; +use core::str::FromStr; use core::time::Duration; use core::u64; @@ -200,18 +201,6 @@ mod sealed { } } -impl Default for ConnectionEnd { - fn default() -> Self { - Self { - state: State::Uninitialized, - client_id: Default::default(), - counterparty: Default::default(), - versions: Vec::new(), - delay_period: ZERO_DURATION, - } - } -} - impl Protobuf for ConnectionEnd {} impl TryFrom for ConnectionEnd { @@ -220,7 +209,17 @@ impl TryFrom for ConnectionEnd { let state = value.state.try_into()?; if state == State::Uninitialized { - return Ok(ConnectionEnd::default()); + return ConnectionEnd::new( + State::Uninitialized, + ClientId::from_str("07-tendermint-0").expect("should not fail"), + Counterparty::new( + ClientId::from_str("07-tendermint-0").expect("should not fail"), + None, + CommitmentPrefix::empty(), + ), + Vec::new(), + ZERO_DURATION, + ); } if value.client_id.is_empty() { @@ -378,7 +377,7 @@ impl ConnectionEnd { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Counterparty { pub client_id: ClientId, pub connection_id: Option, diff --git a/ibc-core/ics03-connection/types/src/events.rs b/ibc-core/ics03-connection/types/src/events.rs index 1866a3982..1c2879852 100644 --- a/ibc-core/ics03-connection/types/src/events.rs +++ b/ibc-core/ics03-connection/types/src/events.rs @@ -29,7 +29,7 @@ pub const COUNTERPARTY_CLIENT_ID_ATTRIBUTE_KEY: &str = "counterparty_client_id"; derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] struct Attributes { pub connection_id: ConnectionId, pub client_id: ClientId, @@ -323,7 +323,7 @@ mod tests { let client_type = ClientType::from_str("07-tendermint") .expect("never fails because it's a valid client type"); - let conn_id_on_a = ConnectionId::default(); + let conn_id_on_a = ConnectionId::zero(); let client_id_on_a = client_type.build_client_id(0); let conn_id_on_b = ConnectionId::new(1); let client_id_on_b = client_type.build_client_id(1); diff --git a/ibc-core/ics03-connection/types/src/version.rs b/ibc-core/ics03-connection/types/src/version.rs index 46029c68c..2979e2622 100644 --- a/ibc-core/ics03-connection/types/src/version.rs +++ b/ibc-core/ics03-connection/types/src/version.rs @@ -58,6 +58,14 @@ impl Version { } Ok(()) } + + /// Returns the lists of supported versions + pub fn compatibles() -> Vec { + vec![Self { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + }] + } } impl Protobuf for Version {} @@ -89,15 +97,6 @@ impl From for RawVersion { } } -impl Default for Version { - fn default() -> Self { - Version { - identifier: "1".to_string(), - features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], - } - } -} - impl Display for Version { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!( @@ -109,11 +108,6 @@ impl Display for Version { } } -/// Returns the lists of supported versions -pub fn get_compatible_versions() -> Vec { - vec![Version::default()] -} - /// Iterates over the descending ordered set of compatible IBC versions and /// selects the first version with a version identifier that is supported by the /// counterparty. The returned version contains a feature set with the @@ -189,7 +183,7 @@ mod tests { use ibc_proto::ibc::core::connection::v1::Version as RawVersion; use crate::error::ConnectionError; - use crate::version::{get_compatible_versions, pick_version, Version}; + use crate::version::{pick_version, Version}; fn get_dummy_features() -> Vec { vec!["ORDER_RANDOM".to_string(), "ORDER_UNORDERED".to_string()] @@ -197,7 +191,11 @@ mod tests { fn good_versions() -> Vec { vec![ - Version::default().into(), + Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + } + .into(), RawVersion { identifier: "2".to_string(), features: get_dummy_features(), @@ -228,7 +226,10 @@ mod tests { fn overlapping() -> (Vec, Vec, Version) { ( vec![ - Version::default(), + Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + }, Version { identifier: "3".to_string(), features: get_dummy_features(), @@ -291,7 +292,11 @@ mod tests { let tests: Vec = vec![ Test { name: "Compatible versions".to_string(), - versions: vec![Version::default().into()], + versions: vec![Version { + identifier: "1".to_string(), + features: get_dummy_features(), + } + .into()], want_pass: true, }, Test { @@ -344,9 +349,12 @@ mod tests { let tests: Vec = vec![ Test { name: "Compatible versions".to_string(), - supported: get_compatible_versions(), - counterparty: get_compatible_versions(), - picked: Ok(Version::default()), + supported: Version::compatibles(), + counterparty: Version::compatibles(), + picked: Ok(Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + }), want_pass: true, }, Test { @@ -382,7 +390,10 @@ mod tests { } #[test] fn serialize() { - let def = Version::default(); + let def = Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + }; let def_raw: RawVersion = def.clone().into(); let def_back = def_raw.try_into().unwrap(); assert_eq!(def, def_back); diff --git a/ibc-core/ics04-channel/types/src/channel.rs b/ibc-core/ics04-channel/types/src/channel.rs index 732e17185..20c3957ff 100644 --- a/ibc-core/ics04-channel/types/src/channel.rs +++ b/ibc-core/ics04-channel/types/src/channel.rs @@ -439,10 +439,9 @@ impl From for RawCounterparty { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Order { None = 0isize, - #[default] Unordered = 1isize, Ordered = 2isize, } diff --git a/ibc-core/ics04-channel/types/src/events/mod.rs b/ibc-core/ics04-channel/types/src/events/mod.rs index fbb78d6e7..3fee6bb6e 100644 --- a/ibc-core/ics04-channel/types/src/events/mod.rs +++ b/ibc-core/ics04-channel/types/src/events/mod.rs @@ -1132,8 +1132,8 @@ mod tests { } let port_id = PortId::transfer(); - let channel_id = ChannelId::new(0); - let connection_id = ConnectionId::new(0); + let channel_id = ChannelId::zero(); + let connection_id = ConnectionId::zero(); let counterparty_port_id = PortId::transfer(); let counterparty_channel_id = ChannelId::new(1); let version = Version::new("ics20-1".to_string()); diff --git a/ibc-core/ics04-channel/types/src/timeout.rs b/ibc-core/ics04-channel/types/src/timeout.rs index 3a7e825ce..e20ccf0d8 100644 --- a/ibc-core/ics04-channel/types/src/timeout.rs +++ b/ibc-core/ics04-channel/types/src/timeout.rs @@ -84,12 +84,6 @@ impl TimeoutHeight { } } -impl Default for TimeoutHeight { - fn default() -> Self { - Self::Never - } -} - impl TryFrom for TimeoutHeight { type Error = ClientError; diff --git a/ibc-core/ics04-channel/types/src/version.rs b/ibc-core/ics04-channel/types/src/version.rs index bf41109da..2cfc1e46c 100644 --- a/ibc-core/ics04-channel/types/src/version.rs +++ b/ibc-core/ics04-channel/types/src/version.rs @@ -74,13 +74,6 @@ impl FromStr for Version { } } -/// The default version is empty (unspecified). -impl Default for Version { - fn default() -> Self { - Version::empty() - } -} - impl Display for Version { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { write!(f, "{}", self.0) diff --git a/ibc-core/ics23-commitment/types/src/commitment.rs b/ibc-core/ics23-commitment/types/src/commitment.rs index e4ae8fcf0..25f4ca579 100644 --- a/ibc-core/ics23-commitment/types/src/commitment.rs +++ b/ibc-core/ics23-commitment/types/src/commitment.rs @@ -143,7 +143,7 @@ impl<'a> TryFrom<&'a CommitmentProofBytes> for MerkleProof { )] #[cfg_attr(feature = "serde", derive(serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, PartialEq, Eq, Hash, Default)] +#[derive(Clone, PartialEq, Eq, Hash)] pub struct CommitmentPrefix { bytes: Vec, } @@ -156,6 +156,10 @@ impl CommitmentPrefix { pub fn into_vec(self) -> Vec { self.bytes } + + pub fn empty() -> Self { + Self { bytes: Vec::new() } + } } impl TryFrom> for CommitmentPrefix { diff --git a/ibc-core/ics23-commitment/types/src/specs.rs b/ibc-core/ics23-commitment/types/src/specs.rs index b7789cebc..3cd40ac84 100644 --- a/ibc-core/ics23-commitment/types/src/specs.rs +++ b/ibc-core/ics23-commitment/types/src/specs.rs @@ -45,12 +45,6 @@ impl ProofSpecs { } } -impl Default for ProofSpecs { - fn default() -> Self { - Self::cosmos() - } -} - impl From> for ProofSpecs { fn from(ics23_specs: Vec) -> Self { Self(ics23_specs.into_iter().map(Into::into).collect()) diff --git a/ibc-core/ics24-host/src/context.rs b/ibc-core/ics24-host/src/context.rs index 9335fce60..b390d6b83 100644 --- a/ibc-core/ics24-host/src/context.rs +++ b/ibc-core/ics24-host/src/context.rs @@ -6,9 +6,7 @@ use ibc_core_channel_types::packet::Receipt; use ibc_core_client_context::prelude::*; use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentPrefix; -use ibc_core_connection_types::version::{ - get_compatible_versions, pick_version, Version as ConnectionVersion, -}; +use ibc_core_connection_types::version::{pick_version, Version as ConnectionVersion}; use ibc_core_connection_types::ConnectionEnd; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::IbcEvent; @@ -78,7 +76,7 @@ pub trait ValidationContext { /// Function required by ICS-03. Returns the list of all possible versions that the connection /// handshake protocol supports. fn get_compatible_versions(&self) -> Vec { - get_compatible_versions() + ConnectionVersion::compatibles() } /// Function required by ICS-03. Returns one version out of the supplied list of versions, which the diff --git a/ibc-core/ics24-host/types/src/identifiers/channel_id.rs b/ibc-core/ics24-host/types/src/identifiers/channel_id.rs index 3cfeacb7b..5d4583dc6 100644 --- a/ibc-core/ics24-host/types/src/identifiers/channel_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/channel_id.rs @@ -57,6 +57,10 @@ impl ChannelId { pub fn as_bytes(&self) -> &[u8] { self.0.as_bytes() } + + pub fn zero() -> Self { + Self::new(0) + } } /// This implementation provides a `to_string` method. @@ -80,12 +84,6 @@ impl AsRef for ChannelId { } } -impl Default for ChannelId { - fn default() -> Self { - Self::new(0) - } -} - /// Equality check against string literal (satisfies &ChannelId == &str). /// ``` /// use core::str::FromStr; diff --git a/ibc-core/ics24-host/types/src/identifiers/client_id.rs b/ibc-core/ics24-host/types/src/identifiers/client_id.rs index 62a5662d6..ecbfe1cca 100644 --- a/ibc-core/ics24-host/types/src/identifiers/client_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/client_id.rs @@ -76,12 +76,6 @@ impl FromStr for ClientId { } } -impl Default for ClientId { - fn default() -> Self { - Self::from_str("07-tendermint-0").expect("Never fails because we use a valid client id") - } -} - /// Equality check against string literal (satisfies &ClientId == &str). /// ``` /// use core::str::FromStr; diff --git a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs index a0283f5f4..883c41138 100644 --- a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs @@ -56,6 +56,11 @@ impl ConnectionId { pub fn as_bytes(&self) -> &[u8] { self.0.as_bytes() } + + /// Return ConnectionId with identifier 0 + pub fn zero() -> Self { + Self::new(0) + } } /// This implementation provides a `to_string` method. @@ -73,12 +78,6 @@ impl FromStr for ConnectionId { } } -impl Default for ConnectionId { - fn default() -> Self { - Self::new(0) - } -} - /// Equality check against string literal (satisfies &ConnectionId == &str). /// ``` /// use core::str::FromStr; diff --git a/ibc-core/ics24-host/types/src/identifiers/sequence.rs b/ibc-core/ics24-host/types/src/identifiers/sequence.rs index 7919ba56e..9e8b2ccbc 100644 --- a/ibc-core/ics24-host/types/src/identifiers/sequence.rs +++ b/ibc-core/ics24-host/types/src/identifiers/sequence.rs @@ -17,7 +17,7 @@ use crate::error::IdentifierError; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] /// The sequence number of a packet enforces ordering among packets from the same source. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Sequence(u64); impl core::str::FromStr for Sequence { diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index 3247f5a63..43e99347e 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1074,7 +1074,13 @@ fn parse_upgrades(components: &[&str]) -> Option { #[cfg(test)] mod tests { use super::*; - + const DEFAULT_CLIENT_ID_STR: &str = "07-tendermint-0"; + impl ClientId { + pub fn new_dummy() -> Self { + ClientId::from_str(DEFAULT_CLIENT_ID_STR) + .expect("should not fail since we use a valid client id") + } + } #[rstest::rstest] #[case(NEXT_CLIENT_SEQUENCE, Path::NextClientSequence(NextClientSequencePath))] #[case( @@ -1087,12 +1093,12 @@ mod tests { )] #[case( "clients/07-tendermint-0/clientState", - Path::ClientState(ClientStatePath(ClientId::default())) + Path::ClientState(ClientStatePath(ClientId::new_dummy())) )] #[case( "clients/07-tendermint-0/consensusStates/15-31", Path::ClientConsensusState(ClientConsensusStatePath { - client_id: ClientId::default(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, }) @@ -1100,7 +1106,7 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedTime", Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: ClientId::default(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, }) @@ -1108,58 +1114,58 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedHeight", Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: ClientId::default(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, }) )] #[case( "clients/07-tendermint-0/connections", - Path::ClientConnection(ClientConnectionPath(ClientId::default())) + Path::ClientConnection(ClientConnectionPath(ClientId::new_dummy())) )] #[case( "connections/connection-0", - Path::Connection(ConnectionPath(ConnectionId::new(0))) + Path::Connection(ConnectionPath(ConnectionId::zero())) )] #[case("ports/transfer", Path::Ports(PortPath(PortId::transfer())))] #[case( "channelEnds/ports/transfer/channels/channel-0", - Path::ChannelEnd(ChannelEndPath(PortId::transfer(), ChannelId::default())) + Path::ChannelEnd(ChannelEndPath(PortId::transfer(), ChannelId::zero())) )] #[case( "nextSequenceSend/ports/transfer/channels/channel-0", - Path::SeqSend(SeqSendPath(PortId::transfer(), ChannelId::default())) + Path::SeqSend(SeqSendPath(PortId::transfer(), ChannelId::zero())) )] #[case( "nextSequenceRecv/ports/transfer/channels/channel-0", - Path::SeqRecv(SeqRecvPath(PortId::transfer(), ChannelId::default())) + Path::SeqRecv(SeqRecvPath(PortId::transfer(), ChannelId::zero())) )] #[case( "nextSequenceAck/ports/transfer/channels/channel-0", - Path::SeqAck(SeqAckPath(PortId::transfer(), ChannelId::default())) + Path::SeqAck(SeqAckPath(PortId::transfer(), ChannelId::zero())) )] #[case( "commitments/ports/transfer/channels/channel-0/sequences/0", Path::Commitment(CommitmentPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), - sequence: Sequence::default(), + channel_id: ChannelId::zero(), + sequence: Sequence::from(0), }) )] #[case( "acks/ports/transfer/channels/channel-0/sequences/0", Path::Ack(AckPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), - sequence: Sequence::default(), + channel_id: ChannelId::zero(), + sequence: Sequence::from(0), }) )] #[case( "receipts/ports/transfer/channels/channel-0/sequences/0", Path::Receipt(ReceiptPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), - sequence: Sequence::default(), + channel_id: ChannelId::zero(), + sequence: Sequence::from(0), }) )] #[case( @@ -1193,7 +1199,7 @@ mod tests { assert_eq!( parse_client_paths(&components), - Some(Path::ClientState(ClientStatePath(ClientId::default()))) + Some(Path::ClientState(ClientStatePath(ClientId::new_dummy()))) ); let path = "clients/07-tendermint-0/consensusStates/15-31"; @@ -1202,7 +1208,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientConsensusState(ClientConsensusStatePath { - client_id: ClientId::default(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, })) @@ -1217,7 +1223,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: ClientId::default(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, })) @@ -1229,7 +1235,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: ClientId::default(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, })) @@ -1243,7 +1249,7 @@ mod tests { assert_eq!( parse_connections(&components), - Some(Path::Connection(ConnectionPath(ConnectionId::new(0)))), + Some(Path::Connection(ConnectionPath(ConnectionId::zero()))), ); } @@ -1265,7 +1271,7 @@ mod tests { assert_eq!( parse_channels(&components), - Some(SubPath::Channels(ChannelId::default())), + Some(SubPath::Channels(ChannelId::zero())), ); } @@ -1276,7 +1282,7 @@ mod tests { assert_eq!( parse_sequences(&components), - Some(SubPath::Sequences(Sequence::default())) + Some(SubPath::Sequences(Sequence::from(0))) ); } @@ -1289,7 +1295,7 @@ mod tests { parse_channel_ends(&components), Some(Path::ChannelEnd(ChannelEndPath( PortId::transfer(), - ChannelId::default() + ChannelId::zero() ))), ); } @@ -1303,7 +1309,7 @@ mod tests { parse_seqs(&components), Some(Path::SeqSend(SeqSendPath( PortId::transfer(), - ChannelId::default() + ChannelId::zero() ))), ); @@ -1314,7 +1320,7 @@ mod tests { parse_seqs(&components), Some(Path::SeqRecv(SeqRecvPath( PortId::transfer(), - ChannelId::default() + ChannelId::zero() ))), ); @@ -1325,7 +1331,7 @@ mod tests { parse_seqs(&components), Some(Path::SeqAck(SeqAckPath( PortId::transfer(), - ChannelId::default() + ChannelId::zero() ))), ); } @@ -1339,8 +1345,8 @@ mod tests { parse_commitments(&components), Some(Path::Commitment(CommitmentPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), - sequence: Sequence::default(), + channel_id: ChannelId::zero(), + sequence: Sequence::from(0), })), ); } @@ -1354,8 +1360,8 @@ mod tests { parse_acks(&components), Some(Path::Ack(AckPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), - sequence: Sequence::default(), + channel_id: ChannelId::zero(), + sequence: Sequence::from(0), })), ); } @@ -1369,8 +1375,8 @@ mod tests { parse_receipts(&components), Some(Path::Receipt(ReceiptPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), - sequence: Sequence::default(), + channel_id: ChannelId::zero(), + sequence: Sequence::from(0), })), ); } diff --git a/ibc-primitives/src/types/timestamp.rs b/ibc-primitives/src/types/timestamp.rs index 9454b2b91..7023c948e 100644 --- a/ibc-primitives/src/types/timestamp.rs +++ b/ibc-primitives/src/types/timestamp.rs @@ -24,7 +24,7 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0); /// of timestamp. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(PartialEq, Eq, Copy, Clone, Debug, Default, PartialOrd, Ord, Hash)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, PartialOrd, Ord, Hash)] pub struct Timestamp { // Note: The schema representation is the timestamp in nanoseconds (as we do with borsh). #[cfg_attr(feature = "schema", schemars(with = "u64"))] @@ -169,7 +169,7 @@ impl Timestamp { /// let ti = Timestamp::from_nanoseconds(min).unwrap(); /// let uti = ti.nanoseconds(); /// assert_eq!(uti, min); - /// let tz = Timestamp::default(); + /// let tz = Timestamp::none(); /// let utz = tz.nanoseconds(); /// assert_eq!(utz, 0); /// ``` diff --git a/ibc-testkit/src/fixtures/applications/transfer.rs b/ibc-testkit/src/fixtures/applications/transfer.rs index b352f1a42..35e71fac0 100644 --- a/ibc-testkit/src/fixtures/applications/transfer.rs +++ b/ibc-testkit/src/fixtures/applications/transfer.rs @@ -1,5 +1,3 @@ -use alloc::string::ToString; - use ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use ibc::apps::transfer::types::packet::PacketData; use ibc::apps::transfer::types::{Memo, PrefixedCoin}; @@ -17,12 +15,12 @@ use crate::fixtures::core::signer::dummy_account_id; pub struct MsgTransferConfig { #[builder(default = PortId::transfer())] pub port_id_on_a: PortId, - #[builder(default)] + #[builder(default = ChannelId::zero())] pub chan_id_on_a: ChannelId, pub packet_data: PacketData, - #[builder(default)] + #[builder(default = TimeoutHeight::Never)] pub timeout_height_on_b: TimeoutHeight, - #[builder(default)] + #[builder(default = Timestamp::none())] pub timeout_timestamp_on_b: Timestamp, } @@ -47,7 +45,7 @@ pub fn extract_transfer_packet(msg: &MsgTransfer, sequence: Sequence) -> Packet port_id_on_a: msg.port_id_on_a.clone(), chan_id_on_a: msg.chan_id_on_a.clone(), port_id_on_b: PortId::transfer(), - chan_id_on_b: ChannelId::default(), + chan_id_on_b: ChannelId::zero(), data, timeout_height_on_b: msg.timeout_height_on_b, timeout_timestamp_on_b: msg.timeout_timestamp_on_b, @@ -63,7 +61,7 @@ pub struct PacketDataConfig { pub sender: Signer, #[builder(default = dummy_account_id())] pub receiver: Signer, - #[builder(default = Memo::from("".to_string()))] + #[builder(default = "".into())] pub memo: Memo, } diff --git a/ibc-testkit/src/fixtures/clients/tendermint.rs b/ibc-testkit/src/fixtures/clients/tendermint.rs index 0e4aa261a..f96ad0e6b 100644 --- a/ibc-testkit/src/fixtures/clients/tendermint.rs +++ b/ibc-testkit/src/fixtures/clients/tendermint.rs @@ -26,13 +26,13 @@ pub fn dummy_tm_client_state_from_header(tm_header: TmHeader) -> TmClientState { let chain_id = ChainId::from_str(tm_header.chain_id.as_str()).expect("Never fails"); let client_state = ClientStateType::new( chain_id.clone(), - Default::default(), + TrustThreshold::ONE_THIRD, Duration::from_secs(64000), Duration::from_secs(128_000), Duration::from_millis(3000), Height::new(chain_id.revision_number(), u64::from(tm_header.height)).expect("Never fails"), - Default::default(), - Default::default(), + ProofSpecs::cosmos(), + Vec::new(), AllowUpdate { after_expiry: false, after_misbehaviour: false, @@ -56,8 +56,8 @@ pub fn dummy_raw_tm_client_state(frozen_height: RawHeight) -> RawTmClientState { unbonding_period: Some(Duration::from_secs(128_000).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(), + proof_specs: ProofSpecs::cosmos().into(), + upgrade_path: Vec::new(), frozen_height: Some(frozen_height), allow_update_after_expiry: false, allow_update_after_misbehaviour: false, @@ -67,7 +67,7 @@ pub fn dummy_raw_tm_client_state(frozen_height: RawHeight) -> RawTmClientState { #[derive(typed_builder::TypedBuilder, Debug)] pub struct ClientStateConfig { pub chain_id: ChainId, - #[builder(default)] + #[builder(default = TrustThreshold::ONE_THIRD)] pub trust_level: TrustThreshold, #[builder(default = Duration::from_secs(64000))] pub trusting_period: Duration, @@ -76,7 +76,7 @@ pub struct ClientStateConfig { #[builder(default = Duration::from_millis(3000))] max_clock_drift: Duration, pub latest_height: Height, - #[builder(default)] + #[builder(default = ProofSpecs::cosmos())] pub proof_specs: ProofSpecs, #[builder(default)] pub upgrade_path: Vec, diff --git a/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs b/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs index 650c735ac..df833f545 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs @@ -10,7 +10,7 @@ use crate::fixtures::core::signer::dummy_bech32_account; 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(), + channel_id: ChannelId::zero().to_string(), proof_init: dummy_proof(), proof_height: Some(Height { revision_number: 0, diff --git a/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs b/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs index dd770443d..89956ddab 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs @@ -8,7 +8,7 @@ use crate::fixtures::core::signer::dummy_bech32_account; pub fn dummy_raw_msg_chan_close_init() -> RawMsgChannelCloseInit { RawMsgChannelCloseInit { port_id: PortId::transfer().to_string(), - channel_id: ChannelId::default().to_string(), + channel_id: ChannelId::zero().to_string(), signer: dummy_bech32_account(), } } diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs index 8b9a0b952..2b89bd3b4 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs @@ -10,8 +10,8 @@ use crate::fixtures::core::signer::dummy_bech32_account; 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(), + channel_id: ChannelId::zero().to_string(), + counterparty_channel_id: ChannelId::zero().to_string(), counterparty_version: "".to_string(), proof_try: dummy_proof(), proof_height: Some(Height { diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs index dfb1c797e..3871fc9f2 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs @@ -10,7 +10,7 @@ use crate::fixtures::core::signer::dummy_bech32_account; 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(), + channel_id: ChannelId::zero().to_string(), proof_ack: dummy_proof(), proof_height: Some(Height { revision_number: 0, diff --git a/ibc-testkit/src/fixtures/core/channel/mod.rs b/ibc-testkit/src/fixtures/core/channel/mod.rs index 0f0df1bf4..a1375cd72 100644 --- a/ibc-testkit/src/fixtures/core/channel/mod.rs +++ b/ibc-testkit/src/fixtures/core/channel/mod.rs @@ -46,7 +46,7 @@ pub fn dummy_raw_channel_end(state: i32, channel_id: Option) -> RawChannel state, ordering: 2, counterparty: Some(dummy_raw_counterparty_chan(channel_id)), - connection_hops: vec![ConnectionId::default().to_string()], + connection_hops: vec![ConnectionId::zero().to_string()], version: "".to_string(), // The version is not validated. } } diff --git a/ibc-testkit/src/fixtures/core/channel/packet.rs b/ibc-testkit/src/fixtures/core/channel/packet.rs index 02b99a8bc..b33e1b2a4 100644 --- a/ibc-testkit/src/fixtures/core/channel/packet.rs +++ b/ibc-testkit/src/fixtures/core/channel/packet.rs @@ -11,21 +11,21 @@ use typed_builder::TypedBuilder; #[derive(TypedBuilder, Debug)] #[builder(build_method(into = Packet))] pub struct PacketConfig { - #[builder(default)] + #[builder(default = Sequence::from(0))] pub seq_on_a: Sequence, #[builder(default = PortId::transfer())] pub port_id_on_a: PortId, - #[builder(default)] + #[builder(default = ChannelId::zero())] pub chan_id_on_a: ChannelId, #[builder(default = PortId::transfer())] pub port_id_on_b: PortId, - #[builder(default)] + #[builder(default = ChannelId::zero())] pub chan_id_on_b: ChannelId, #[builder(default)] pub data: Vec, - #[builder(default)] + #[builder(default = TimeoutHeight::Never)] pub timeout_height_on_b: TimeoutHeight, - #[builder(default)] + #[builder(default = Timestamp::none())] pub timeout_timestamp_on_b: Timestamp, } @@ -49,9 +49,9 @@ pub fn dummy_raw_packet(timeout_height: u64, timeout_timestamp: u64) -> RawPacke RawPacket { sequence: 1, source_port: PortId::transfer().to_string(), - source_channel: ChannelId::default().to_string(), + source_channel: ChannelId::zero().to_string(), destination_port: PortId::transfer().to_string(), - destination_channel: ChannelId::default().to_string(), + destination_channel: ChannelId::zero().to_string(), data: vec![0], timeout_height: Some(RawHeight { revision_number: 0, @@ -265,7 +265,7 @@ mod tests { let ibc_event = IbcEvent::SendPacket(SendPacket::new( packet, Order::Unordered, - ConnectionId::default(), + ConnectionId::zero(), )); let _ = tendermint::abci::Event::try_from(ibc_event); } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs index f690e430a..863e79343 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs @@ -2,7 +2,7 @@ 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::connection::types::version::Version as ConnectionVersion; use ibc::core::host::types::identifiers::ConnectionId; use ibc::core::primitives::prelude::*; @@ -24,7 +24,7 @@ pub fn dummy_raw_msg_conn_open_ack( ) -> RawMsgConnectionOpenAck { let client_state_height = Height::new(0, consensus_height).expect("invalid height"); RawMsgConnectionOpenAck { - connection_id: ConnectionId::new(0).to_string(), + connection_id: ConnectionId::zero().to_string(), counterparty_connection_id: ConnectionId::new(1).to_string(), proof_try: dummy_proof(), proof_height: Some(RawHeight { @@ -38,7 +38,7 @@ pub fn dummy_raw_msg_conn_open_ack( }), client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), proof_client: dummy_proof(), - version: Some(Version::default().into()), + version: Some(ConnectionVersion::compatibles()[0].clone().into()), signer: dummy_bech32_account(), host_consensus_state_proof: vec![], } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs index 07302e0de..07036f4fc 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs @@ -2,7 +2,7 @@ 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::version::Version as ConnectionVersion; use ibc::core::connection::types::Counterparty; use ibc::core::host::types::identifiers::ClientId; use ibc::core::primitives::prelude::*; @@ -57,7 +57,7 @@ pub fn msg_conn_open_with_version( identifier: Option<&str>, ) -> MsgConnectionOpenInit { let version = match identifier { - Some(v) => Version::try_from(RawVersion { + Some(v) => ConnectionVersion::try_from(RawVersion { identifier: v.to_string(), features: vec![], }) @@ -71,9 +71,9 @@ pub fn msg_conn_open_with_version( /// Returns a dummy `RawMsgConnectionOpenInit`, for testing purposes only! pub fn dummy_raw_msg_conn_open_init() -> RawMsgConnectionOpenInit { RawMsgConnectionOpenInit { - client_id: ClientId::default().to_string(), + client_id: "07-tendermint-0".into(), counterparty: Some(dummy_raw_counterparty_conn(None)), - version: Some(Version::default().into()), + version: Some(ConnectionVersion::compatibles()[0].clone().into()), delay_period: 0, signer: dummy_bech32_account(), } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs index 5780dd928..d3f9f60ea 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs @@ -2,7 +2,7 @@ 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::connection::types::version::Version as ConnectionVersion; use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; use ibc::core::primitives::prelude::*; @@ -40,12 +40,12 @@ pub fn dummy_raw_msg_conn_open_try( #[allow(deprecated)] RawMsgConnectionOpenTry { - client_id: ClientId::default().to_string(), - previous_connection_id: ConnectionId::default().to_string(), + client_id: "07-tendermint-0".into(), + previous_connection_id: ConnectionId::zero().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() + counterparty_versions: ConnectionVersion::compatibles() .iter() .map(|v| v.clone().into()) .collect(), diff --git a/ibc-testkit/src/fixtures/core/connection/mod.rs b/ibc-testkit/src/fixtures/core/connection/mod.rs index 0567705c0..5b8388147 100644 --- a/ibc-testkit/src/fixtures/core/connection/mod.rs +++ b/ibc-testkit/src/fixtures/core/connection/mod.rs @@ -9,7 +9,7 @@ pub use conn_open_init::*; pub use conn_open_try::*; use ibc::core::commitment_types::proto::v1::MerklePrefix; use ibc::core::connection::types::proto::v1::Counterparty as RawCounterparty; -use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; +use ibc::core::host::types::identifiers::ConnectionId; use ibc::core::primitives::prelude::*; use typed_builder::TypedBuilder; @@ -42,7 +42,7 @@ pub fn dummy_raw_counterparty_conn(conn_id: Option) -> RawCounterparty { None => "".to_string(), }; RawCounterparty { - client_id: ClientId::default().to_string(), + client_id: "07-tendermint-0".into(), connection_id, prefix: Some(MerklePrefix { key_prefix: b"ibc".to_vec(), diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs index 072b7bba7..a861ac311 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs @@ -21,7 +21,7 @@ impl Default for MockHeader { fn default() -> Self { Self { height: Height::min(0), - timestamp: Default::default(), + timestamp: Timestamp::none(), } } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index f0769e4df..15ea17a40 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -23,7 +23,7 @@ impl TryFrom for Misbehaviour { fn try_from(raw: RawMisbehaviour) -> Result { Ok(Self { - client_id: Default::default(), + client_id: ClientId::new("07-tendermint", 0).expect("no error"), header1: raw .header1 .ok_or(ClientError::MissingRawMisbehaviour)? diff --git a/ibc-testkit/src/testapp/ibc/core/types.rs b/ibc-testkit/src/testapp/ibc/core/types.rs index 549e39f8f..7e365c49c 100644 --- a/ibc-testkit/src/testapp/ibc/core/types.rs +++ b/ibc-testkit/src/testapp/ibc/core/types.rs @@ -125,7 +125,7 @@ pub struct MockContext { pub struct MockClientConfig { #[builder(default = ChainId::new("mockZ-1").expect("no error"))] client_chain_id: ChainId, - #[builder(default)] + #[builder(default = ClientId::new("07-tendermint", 0).expect("no error"))] client_id: ClientId, #[builder(default = mock_client_type())] client_type: ClientType, diff --git a/ibc-testkit/tests/core/ics02_client/update_client.rs b/ibc-testkit/tests/core/ics02_client/update_client.rs index 61956e336..20828b529 100644 --- a/ibc-testkit/tests/core/ics02_client/update_client.rs +++ b/ibc-testkit/tests/core/ics02_client/update_client.rs @@ -43,7 +43,7 @@ struct Fixture { #[fixture] fn fixture() -> Fixture { - let client_id = ClientId::default(); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let ctx = MockContext::default().with_client_config( MockClientConfig::builder() @@ -82,7 +82,7 @@ fn test_update_client_ok(fixture: Fixture) { mut router, } = fixture; - let client_id = ClientId::default(); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let signer = dummy_account_id(); let timestamp = Timestamp::now(); @@ -114,7 +114,7 @@ fn test_update_client_ok(fixture: Fixture) { // client's height and ensures that `ConsensusState` is stored at the correct // path (header height). fn test_update_client_with_prev_header() { - let client_id = ClientId::default(); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let chain_id_b = ChainId::new("mockgaiaA-0").unwrap(); let latest_height = Height::new(0, 42).unwrap(); let height_1 = Height::new(0, 43).unwrap(); @@ -681,8 +681,8 @@ fn test_update_synthetic_tendermint_client_duplicate_ok() { .unwrap() .into(), ), - proof_specs: ProofSpecs::default().into(), - upgrade_path: Default::default(), + proof_specs: ProofSpecs::cosmos().into(), + upgrade_path: Vec::new(), frozen_height: Some(RawHeight { revision_number: 0, revision_height: 0, @@ -782,7 +782,7 @@ fn test_update_client_events(fixture: Fixture) { mut router, } = fixture; - let client_id = ClientId::default(); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let signer = dummy_account_id(); let timestamp = Timestamp::now(); @@ -846,7 +846,7 @@ fn test_misbehaviour_client_ok(fixture: Fixture) { mut router, } = fixture; - let client_id = ClientId::default(); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let msg_envelope = msg_update_client(&client_id); let res = validate(&ctx, &router, msg_envelope.clone()); diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index 056936fd1..7ac747dc5 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -4,7 +4,8 @@ use ibc::core::channel::types::msgs::{MsgAcknowledgement, PacketMsg}; use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::commitment_types::commitment::CommitmentPrefix; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -33,6 +34,8 @@ struct Fixture { #[fixture] fn fixture() -> Fixture { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let client_height = Height::new(0, 2).unwrap(); let ctx = MockContext::default().with_client_config( MockClientConfig::builder() @@ -59,7 +62,7 @@ fn fixture() -> Fixture { State::Open, Order::Unordered, Counterparty::new(packet.port_id_on_b, Some(packet.chan_id_on_b)), - vec![ConnectionId::default()], + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); @@ -69,13 +72,13 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + default_client_id.clone(), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + default_client_id.clone(), + Some(ConnectionId::zero()), + CommitmentPrefix::empty(), ), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -128,10 +131,10 @@ fn ack_success_no_packet_commitment(fixture: Fixture) { ) .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a); + .with_connection(ConnectionId::zero(), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -145,6 +148,7 @@ fn ack_success_no_packet_commitment(fixture: Fixture) { #[rstest] fn ack_success_happy_path(fixture: Fixture) { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); let Fixture { ctx, router, @@ -163,10 +167,10 @@ fn ack_success_happy_path(fixture: Fixture) { ) .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -175,7 +179,7 @@ fn ack_success_happy_path(fixture: Fixture) { ); ctx.get_client_execution_context() .store_update_meta( - ClientId::default(), + default_client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 4).unwrap(), @@ -206,10 +210,10 @@ fn ack_unordered_chan_execute(fixture: Fixture) { let mut ctx = ctx .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -245,12 +249,8 @@ fn ack_ordered_chan_execute(fixture: Fixture) { .. } = fixture; let mut ctx = ctx - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a_ordered, - ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), 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 d337c7d4a..14b358702 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs @@ -1,7 +1,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State as ChannelState}; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelCloseConfirm}; use ibc::core::channel::types::Version; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -28,7 +28,7 @@ fn test_chan_close_confirm_validate() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -42,13 +42,13 @@ fn test_chan_close_confirm_validate() { let chan_end = ChannelEnd::new( ChannelState::Open, - Order::default(), + Order::Unordered, Counterparty::new( msg_chan_close_confirm.port_id_on_b.clone(), Some(msg_chan_close_confirm.chan_id_on_b.clone()), ), vec![conn_id.clone()], - Version::default(), + Version::empty(), ) .unwrap(); @@ -87,7 +87,7 @@ fn test_chan_close_confirm_execute() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -101,13 +101,13 @@ fn test_chan_close_confirm_execute() { let chan_end = ChannelEnd::new( ChannelState::Open, - Order::default(), + Order::Unordered, Counterparty::new( msg_chan_close_confirm.port_id_on_b.clone(), Some(msg_chan_close_confirm.chan_id_on_b.clone()), ), vec![conn_id.clone()], - Version::default(), + Version::empty(), ) .unwrap(); 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 ccf040f85..00ee8cdab 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs @@ -1,7 +1,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State as ChannelState}; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelCloseInit}; use ibc::core::channel::types::Version; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -26,7 +26,7 @@ fn test_chan_close_init_validate() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -38,13 +38,13 @@ fn test_chan_close_init_validate() { let chan_end = ChannelEnd::new( ChannelState::Open, - Order::default(), + Order::Unordered, Counterparty::new( msg_chan_close_init.port_id_on_a.clone(), Some(msg_chan_close_init.chan_id_on_a.clone()), ), vec![conn_id.clone()], - Version::default(), + Version::empty(), ) .unwrap(); @@ -86,7 +86,7 @@ fn test_chan_close_init_execute() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -98,13 +98,13 @@ fn test_chan_close_init_execute() { let chan_end = ChannelEnd::new( ChannelState::Open, - Order::default(), + Order::Unordered, Counterparty::new( msg_chan_close_init.port_id_on_a.clone(), Some(msg_chan_close_init.chan_id_on_a.clone()), ), vec![conn_id.clone()], - Version::default(), + Version::empty(), ) .unwrap(); 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 6a584e2ca..8c3140910 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs @@ -2,7 +2,7 @@ use ibc::apps::transfer::types::MODULE_ID_STR; use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State}; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenAck}; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -46,7 +46,7 @@ fn fixture() -> Fixture { ConnectionState::Open, client_id_on_a.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); 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 f01b4adfd..c97338f2e 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs @@ -2,7 +2,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State} use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenConfirm}; use ibc::core::channel::types::Version; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -43,7 +43,7 @@ fn fixture() -> Fixture { ConnectionState::Open, client_id_on_b.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -54,9 +54,9 @@ fn fixture() -> Fixture { let chan_end_on_b = ChannelEnd::new( State::TryOpen, Order::Unordered, - Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::default())), + Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::zero())), vec![conn_id_on_b.clone()], - Version::default(), + Version::empty(), ) .unwrap(); @@ -94,11 +94,7 @@ fn chan_open_confirm_validate_happy_path(fixture: Fixture) { .build(), ) .with_connection(conn_id_on_b, conn_end_on_b) - .with_channel( - msg.port_id_on_b.clone(), - ChannelId::default(), - chan_end_on_b, - ); + .with_channel(msg.port_id_on_b.clone(), ChannelId::zero(), chan_end_on_b); let msg_envelope = MsgEnvelope::from(ChannelMsg::from(msg)); @@ -129,11 +125,7 @@ fn chan_open_confirm_execute_happy_path(fixture: Fixture) { .build(), ) .with_connection(conn_id_on_b, conn_end_on_b) - .with_channel( - msg.port_id_on_b.clone(), - ChannelId::default(), - chan_end_on_b, - ); + .with_channel(msg.port_id_on_b.clone(), ChannelId::zero(), chan_end_on_b); let msg_envelope = MsgEnvelope::from(ChannelMsg::from(msg)); @@ -200,9 +192,9 @@ fn chan_open_confirm_fail_channel_wrong_state(fixture: Fixture) { let wrong_chan_end = ChannelEnd::new( State::Init, Order::Unordered, - Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::default())), + Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::zero())), vec![conn_id_on_b.clone()], - Version::default(), + Version::empty(), ) .unwrap(); let context = context @@ -213,11 +205,7 @@ fn chan_open_confirm_fail_channel_wrong_state(fixture: Fixture) { .build(), ) .with_connection(conn_id_on_b, conn_end_on_b) - .with_channel( - msg.port_id_on_b.clone(), - ChannelId::default(), - wrong_chan_end, - ); + .with_channel(msg.port_id_on_b.clone(), ChannelId::zero(), wrong_chan_end); let msg_envelope = MsgEnvelope::from(ChannelMsg::from(msg)); 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 d79f8989c..a76f34d03 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs @@ -1,7 +1,7 @@ use ibc::clients::tendermint::types::client_type as tm_client_type; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenInit}; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ConnectionEnd, State as ConnectionState}; use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; @@ -40,7 +40,7 @@ fn fixture() -> Fixture { ConnectionState::Init, msg_conn_init.client_id_on_a.clone(), msg_conn_init.counterparty.clone(), - get_compatible_versions(), + ConnectionVersion::compatibles(), msg_conn_init.delay_period, ) .unwrap(); @@ -52,7 +52,7 @@ fn fixture() -> Fixture { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a); + .with_connection(ConnectionId::zero(), conn_end_on_a); Fixture { ctx, router, msg } } 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 35d8a55a7..e9b121dba 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs @@ -1,6 +1,6 @@ use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenTry}; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -39,7 +39,7 @@ fn fixture() -> Fixture { ConnectionState::Open, client_id_on_b.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index 773390f17..a11a90837 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -4,7 +4,8 @@ use ibc::core::channel::types::packet::Packet; use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::commitment_types::commitment::CommitmentPrefix; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -30,10 +31,13 @@ pub struct Fixture { pub msg: MsgRecvPacket, pub conn_end_on_b: ConnectionEnd, pub chan_end_on_b: ChannelEnd, + pub client_id: ClientId, } #[fixture] fn fixture() -> Fixture { + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let context = MockContext::default(); let router = MockRouter::new_with_transfer(); @@ -49,22 +53,22 @@ fn fixture() -> Fixture { let chan_end_on_b = ChannelEnd::new( State::Open, - Order::default(), + Order::Unordered, Counterparty::new(packet.port_id_on_a, Some(packet.chan_id_on_a)), - vec![ConnectionId::default()], + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); let conn_end_on_b = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + client_id.clone(), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + client_id.clone(), + Some(ConnectionId::zero()), + CommitmentPrefix::empty(), ), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -77,6 +81,7 @@ fn fixture() -> Fixture { msg, conn_end_on_b, chan_end_on_b, + client_id, } } @@ -109,6 +114,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { chan_end_on_b, client_height, host_height, + client_id, .. } = fixture; @@ -119,7 +125,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_b) + .with_connection(ConnectionId::zero(), conn_end_on_b) .with_channel( packet.port_id_on_b.clone(), packet.chan_id_on_b.clone(), @@ -141,7 +147,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { context .get_client_execution_context() .store_update_meta( - ClientId::default(), + client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), @@ -174,9 +180,9 @@ fn recv_packet_timeout_expired(fixture: Fixture) { let packet_old = Packet { seq_on_a: 1.into(), port_id_on_a: PortId::transfer(), - chan_id_on_a: ChannelId::default(), + chan_id_on_a: ChannelId::zero(), port_id_on_b: PortId::transfer(), - chan_id_on_b: ChannelId::default(), + chan_id_on_b: ChannelId::zero(), data: Vec::new(), timeout_height_on_b: client_height.into(), timeout_timestamp_on_b: Timestamp::from_nanoseconds(1).unwrap(), @@ -197,9 +203,9 @@ fn recv_packet_timeout_expired(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_b) - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_b) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()) + .with_connection(ConnectionId::zero(), conn_end_on_b) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_b) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()) .with_height(host_height); let res = validate(&context, &router, msg_envelope); @@ -227,8 +233,8 @@ fn recv_packet_execute_happy_path(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_b) - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_b); + .with_connection(ConnectionId::zero(), conn_end_on_b) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_b); let msg_env = MsgEnvelope::from(PacketMsg::from(msg)); diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 333563ee0..acd58417a 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -6,7 +6,8 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State} use ibc::core::channel::types::packet::Packet; use ibc::core::channel::types::Version; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::commitment_types::commitment::CommitmentPrefix; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -19,6 +20,8 @@ use test_log::test; #[test] fn send_packet_processing() { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + struct Test { name: String, ctx: MockContext, @@ -30,22 +33,22 @@ fn send_packet_processing() { let chan_end_on_a = ChannelEnd::new( State::Open, - Order::default(), - Counterparty::new(PortId::transfer(), Some(ChannelId::default())), - vec![ConnectionId::default()], + Order::Unordered, + Counterparty::new(PortId::transfer(), Some(ChannelId::zero())), + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + default_client_id.clone(), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + default_client_id.clone(), + Some(ConnectionId::zero()), + CommitmentPrefix::empty(), ), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -97,13 +100,9 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a.clone()) - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a.clone(), - ) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()), + .with_connection(ConnectionId::zero(), conn_end_on_a.clone()) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet, want_pass: true, }, @@ -116,13 +115,9 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a.clone()) - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a.clone(), - ) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()), + .with_connection(ConnectionId::zero(), conn_end_on_a.clone()) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_timeout_equal_client_height, want_pass: true, }, @@ -135,13 +130,9 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a.clone()) - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a.clone(), - ) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()), + .with_connection(ConnectionId::zero(), conn_end_on_a.clone()) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_timeout_one_before_client_height, want_pass: false, }, @@ -153,9 +144,9 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a) - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_a) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()), + .with_connection(ConnectionId::zero(), conn_end_on_a) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_with_timestamp_old, want_pass: false, }, diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 55d964b68..05036636a 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -4,7 +4,8 @@ use ibc::core::channel::types::msgs::{MsgTimeout, PacketMsg}; use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::commitment_types::commitment::CommitmentPrefix; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -28,10 +29,13 @@ struct Fixture { conn_end_on_a: ConnectionEnd, chan_end_on_a_ordered: ChannelEnd, chan_end_on_a_unordered: ChannelEnd, + client_id: ClientId, } #[fixture] fn fixture() -> Fixture { + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let client_height = Height::new(0, 2).unwrap(); let ctx = MockContext::default().with_client_config( MockClientConfig::builder() @@ -66,7 +70,7 @@ fn fixture() -> Fixture { State::Open, Order::Unordered, Counterparty::new(packet.port_id_on_b.clone(), Some(packet.chan_id_on_b)), - vec![ConnectionId::default()], + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); @@ -76,13 +80,13 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + client_id.clone(), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + client_id.clone(), + Some(ConnectionId::zero()), + CommitmentPrefix::empty(), ), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -96,6 +100,7 @@ fn fixture() -> Fixture { conn_end_on_a, chan_end_on_a_ordered, chan_end_on_a_unordered, + client_id, } } @@ -139,10 +144,10 @@ fn timeout_fail_no_consensus_state_for_height(fixture: Fixture) { let ctx = ctx .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( packet.port_id_on_a, packet.chan_id_on_a, @@ -169,6 +174,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { chan_end_on_a_unordered, conn_end_on_a, client_height, + client_id, .. } = fixture; @@ -190,10 +196,10 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_packet_commitment( @@ -204,7 +210,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { ); ctx.store_update_meta( - ClientId::default(), + client_id, client_height, Timestamp::from_nanoseconds(5).unwrap(), Height::new(0, 4).unwrap(), @@ -235,10 +241,10 @@ fn timeout_success_no_packet_commitment(fixture: Fixture) { let ctx = ctx .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a); + .with_connection(ConnectionId::zero(), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -260,6 +266,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { conn_end_on_a, packet_commitment, client_height, + client_id, .. } = fixture; @@ -271,10 +278,10 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_packet_commitment( @@ -286,7 +293,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { ctx.get_client_execution_context() .store_update_meta( - ClientId::default(), + client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), @@ -310,6 +317,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { conn_end_on_a, packet_commitment, client_height, + client_id, .. } = fixture; @@ -321,12 +329,8 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a) - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a_ordered, - ) + .with_connection(ConnectionId::zero(), conn_end_on_a) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) .with_packet_commitment( packet.port_id_on_a, packet.chan_id_on_a, @@ -335,7 +339,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { ); ctx.store_update_meta( - ClientId::default(), + client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 4).unwrap(), @@ -363,10 +367,10 @@ fn timeout_unordered_chan_execute(fixture: Fixture) { let mut ctx = ctx .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -403,12 +407,8 @@ fn timeout_ordered_chan_execute(fixture: Fixture) { .. } = fixture; let mut ctx = ctx - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a_ordered, - ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), 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 c0321e8b1..39a4c306a 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -4,7 +4,8 @@ use ibc::core::channel::types::msgs::{MsgTimeoutOnClose, PacketMsg}; use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::commitment_types::commitment::CommitmentPrefix; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -29,6 +30,8 @@ pub struct Fixture { #[fixture] fn fixture() -> Fixture { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let client_height = Height::new(0, 2).unwrap(); let context = MockContext::default().with_client_config( MockClientConfig::builder() @@ -56,20 +59,20 @@ fn fixture() -> Fixture { State::Open, Order::Ordered, Counterparty::new(packet.port_id_on_b.clone(), Some(packet.chan_id_on_b)), - vec![ConnectionId::default()], + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + default_client_id.clone(), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + default_client_id.clone(), + Some(ConnectionId::zero()), + CommitmentPrefix::empty(), ), - get_compatible_versions(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -115,8 +118,8 @@ fn timeout_on_close_success_no_packet_commitment(fixture: Fixture) { .. } = fixture; let context = context - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_a) - .with_connection(ConnectionId::default(), conn_end_on_a); + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -130,6 +133,8 @@ fn timeout_on_close_success_no_packet_commitment(fixture: Fixture) { #[rstest] fn timeout_on_close_success_happy_path(fixture: Fixture) { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let Fixture { context, router, @@ -140,8 +145,8 @@ fn timeout_on_close_success_happy_path(fixture: Fixture) { .. } = fixture; let mut context = context - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_a) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -152,7 +157,7 @@ fn timeout_on_close_success_happy_path(fixture: Fixture) { context .get_client_execution_context() .store_update_meta( - ClientId::default(), + default_client_id, Height::new(0, 2).unwrap(), Timestamp::from_nanoseconds(5000).unwrap(), Height::new(0, 5).unwrap(),