From 54f9e2bfddb4b47ed666fa752d5dbe54771ddb69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Fri, 2 Aug 2024 12:20:59 +0100 Subject: [PATCH 01/10] add optional arbitrary impls --- Cargo.toml | 1 + ibc-apps/Cargo.toml | 1 + ibc-apps/ics20-transfer/Cargo.toml | 1 + ibc-apps/ics20-transfer/types/Cargo.toml | 2 ++ ibc-apps/ics20-transfer/types/src/amount.rs | 8 ++++++++ ibc-apps/ics20-transfer/types/src/coin.rs | 1 + ibc-apps/ics20-transfer/types/src/denom.rs | 4 ++++ ibc-apps/ics20-transfer/types/src/memo.rs | 1 + .../ics20-transfer/types/src/msgs/transfer.rs | 1 + ibc-apps/ics20-transfer/types/src/packet.rs | 1 + ibc-apps/ics721-nft-transfer/Cargo.toml | 1 + ibc-apps/ics721-nft-transfer/types/Cargo.toml | 2 ++ ibc-apps/ics721-nft-transfer/types/src/class.rs | 5 +++++ ibc-apps/ics721-nft-transfer/types/src/data.rs | 1 + ibc-apps/ics721-nft-transfer/types/src/lib.rs | 6 ++++++ ibc-apps/ics721-nft-transfer/types/src/memo.rs | 1 + .../types/src/msgs/transfer.rs | 1 + ibc-apps/ics721-nft-transfer/types/src/packet.rs | 1 + ibc-apps/ics721-nft-transfer/types/src/token.rs | 5 +++++ ibc-core/Cargo.toml | 8 ++++++++ ibc-core/ics02-client/Cargo.toml | 1 + ibc-core/ics02-client/types/Cargo.toml | 2 ++ ibc-core/ics02-client/types/src/height.rs | 1 + .../ics02-client/types/src/msgs/create_client.rs | 3 +++ .../ics02-client/types/src/msgs/misbehaviour.rs | 2 ++ ibc-core/ics02-client/types/src/msgs/mod.rs | 1 + .../types/src/msgs/recover_client.rs | 1 + .../ics02-client/types/src/msgs/update_client.rs | 2 ++ .../types/src/msgs/upgrade_client.rs | 3 +++ ibc-core/ics03-connection/Cargo.toml | 1 + ibc-core/ics03-connection/types/Cargo.toml | 7 +++++++ .../ics03-connection/types/src/connection.rs | 1 + .../types/src/msgs/conn_open_ack.rs | 2 ++ .../types/src/msgs/conn_open_confirm.rs | 1 + .../types/src/msgs/conn_open_init.rs | 1 + .../types/src/msgs/conn_open_try.rs | 2 ++ ibc-core/ics03-connection/types/src/msgs/mod.rs | 1 + ibc-core/ics03-connection/types/src/version.rs | 1 + ibc-core/ics04-channel/types/Cargo.toml | 2 ++ .../ics04-channel/types/src/acknowledgement.rs | 1 + ibc-core/ics04-channel/types/src/channel.rs | 1 + .../types/src/msgs/acknowledgement.rs | 1 + .../types/src/msgs/chan_close_confirm.rs | 1 + .../types/src/msgs/chan_close_init.rs | 1 + .../types/src/msgs/chan_open_ack.rs | 1 + .../types/src/msgs/chan_open_confirm.rs | 1 + .../types/src/msgs/chan_open_init.rs | 1 + .../types/src/msgs/chan_open_try.rs | 1 + ibc-core/ics04-channel/types/src/msgs/mod.rs | 2 ++ .../ics04-channel/types/src/msgs/recv_packet.rs | 1 + ibc-core/ics04-channel/types/src/msgs/timeout.rs | 1 + .../types/src/msgs/timeout_on_close.rs | 1 + ibc-core/ics04-channel/types/src/packet.rs | 1 + .../ics04-channel/types/src/timeout/height.rs | 1 + ibc-core/ics04-channel/types/src/version.rs | 1 + ibc-core/ics23-commitment/types/Cargo.toml | 6 ++++++ .../ics23-commitment/types/src/commitment.rs | 2 ++ ibc-core/ics24-host/Cargo.toml | 1 + ibc-core/ics24-host/types/Cargo.toml | 2 ++ .../types/src/identifiers/channel_id.rs | 1 + .../types/src/identifiers/client_id.rs | 1 + .../types/src/identifiers/connection_id.rs | 1 + .../ics24-host/types/src/identifiers/port_id.rs | 1 + .../ics24-host/types/src/identifiers/sequence.rs | 1 + ibc-core/ics25-handler/Cargo.toml | 1 + ibc-core/ics25-handler/types/Cargo.toml | 6 ++++++ ibc-core/ics25-handler/types/src/msgs.rs | 1 + ibc-primitives/Cargo.toml | 2 ++ ibc-primitives/src/lib.rs | 9 +++++++++ ibc-primitives/src/types/signer.rs | 1 + ibc-primitives/src/types/timestamp.rs | 16 ++++++++++++++++ ibc/Cargo.toml | 5 +++++ 72 files changed, 161 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 99e92f7ad7..1629891431 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,7 @@ authors = [ "Informal Systems " ] [workspace.dependencies] # external dependencies +arbitrary = { version = "1.4", features = [ "derive" ] } base64 = { version = "0.22", default-features = false } borsh = { version = "1", default-features = false, features = [ "derive" ] } displaydoc = { version = "0.2.5", default-features = false } diff --git a/ibc-apps/Cargo.toml b/ibc-apps/Cargo.toml index 6ef3c6ac63..1d49ce1d51 100644 --- a/ibc-apps/Cargo.toml +++ b/ibc-apps/Cargo.toml @@ -44,3 +44,4 @@ parity-scale-codec = [ nft-transfer = [ "ibc-app-nft-transfer", ] +arbitrary = [ "ibc-app-transfer/arbitrary", "ibc-app-nft-transfer/arbitrary" ] diff --git a/ibc-apps/ics20-transfer/Cargo.toml b/ibc-apps/ics20-transfer/Cargo.toml index 0f36a3700e..6e4d47e6f6 100644 --- a/ibc-apps/ics20-transfer/Cargo.toml +++ b/ibc-apps/ics20-transfer/Cargo.toml @@ -55,3 +55,4 @@ parity-scale-codec = [ "ibc-app-transfer-types/parity-scale-codec", "ibc-core/parity-scale-codec", ] +arbitrary = [ "ibc-app-transfer-types/arbitrary" ] diff --git a/ibc-apps/ics20-transfer/types/Cargo.toml b/ibc-apps/ics20-transfer/types/Cargo.toml index 30e477f28f..0a2b3a1513 100644 --- a/ibc-apps/ics20-transfer/types/Cargo.toml +++ b/ibc-apps/ics20-transfer/types/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +arbitrary = { workspace = true, optional = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } @@ -74,3 +75,4 @@ parity-scale-codec = [ "ibc-core/parity-scale-codec", "ibc-proto/parity-scale-codec", ] +arbitrary = [ "dep:arbitrary", "ibc-core/arbitrary" ] diff --git a/ibc-apps/ics20-transfer/types/src/amount.rs b/ibc-apps/ics20-transfer/types/src/amount.rs index 8f1b2c81f3..71f886d22d 100644 --- a/ibc-apps/ics20-transfer/types/src/amount.rs +++ b/ibc-apps/ics20-transfer/types/src/amount.rs @@ -10,10 +10,12 @@ use ibc_core::primitives::serializers; use primitive_types::U256; /// A type for representing token transfer amounts. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Display, From, Into)] pub struct Amount( + #[cfg_attr(feature = "arbitrary", arbitrary(with = arb_u256))] #[cfg_attr(feature = "schema", schemars(with = "String"))] #[cfg_attr(feature = "serde", serde(serialize_with = "serializers::serialize"))] #[cfg_attr(feature = "serde", serde(deserialize_with = "deserialize"))] @@ -158,3 +160,9 @@ mod tests { assert_eq!(value, value_deserialized); } } + +#[cfg(feature = "arbitrary")] +fn arb_u256(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let parts: [u8; 32] = arbitrary::Arbitrary::arbitrary(u)?; + Ok(U256::from_big_endian(&parts)) +} diff --git a/ibc-apps/ics20-transfer/types/src/coin.rs b/ibc-apps/ics20-transfer/types/src/coin.rs index db95bcc9fb..4ef61942cc 100644 --- a/ibc-apps/ics20-transfer/types/src/coin.rs +++ b/ibc-apps/ics20-transfer/types/src/coin.rs @@ -21,6 +21,7 @@ pub type RawCoin = Coin; const VALID_DENOM_CHARACTERS: &str = "/:._-"; /// Coin defines a token with a denomination and an amount. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr( diff --git a/ibc-apps/ics20-transfer/types/src/denom.rs b/ibc-apps/ics20-transfer/types/src/denom.rs index 44cd4e210e..630ef74791 100644 --- a/ibc-apps/ics20-transfer/types/src/denom.rs +++ b/ibc-apps/ics20-transfer/types/src/denom.rs @@ -14,6 +14,7 @@ use ibc_proto::ibc::applications::transfer::v1::DenomTrace as RawDenomTrace; /// /// For example, given the token `my_port-1/my_channel-1/my_port-2/my_channel-2/base_denom`, /// `base_denom` is the "base" of the denomination +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(transparent))] #[cfg_attr( @@ -55,6 +56,7 @@ impl FromStr for BaseDenom { /// For example, given the token `my_port-1/my_channel-1/my_port-2/my_channel-2/base_denom`, /// `my_port-1/my_channel-1` is a trace prefix, and `my_port-2/my_channel-2` is another one. /// See [TracePath] which stitches trace prefixes together. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( @@ -122,6 +124,7 @@ impl Display for TracePrefix { /// Internally, the `TracePath` is modelled as a `Vec` but with the order reversed, i.e. /// "transfer/channel-0/transfer/channel-1/uatom" => `["transfer/channel-1", "transfer/channel-0"]` /// This is done for ease of addition/removal of prefixes. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( @@ -236,6 +239,7 @@ impl Display for TracePath { } /// A type that contains the base denomination for ICS20 and the source tracing information path. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr( diff --git a/ibc-apps/ics20-transfer/types/src/memo.rs b/ibc-apps/ics20-transfer/types/src/memo.rs index a49c40beb9..dfe98ed6cd 100644 --- a/ibc-apps/ics20-transfer/types/src/memo.rs +++ b/ibc-apps/ics20-transfer/types/src/memo.rs @@ -10,6 +10,7 @@ use core::str::FromStr; use ibc_core::primitives::prelude::*; /// Represents the token transfer memo +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs index 4f822b5a65..5b3e412575 100644 --- a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs @@ -20,6 +20,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer"; /// have to specify the information related to the transfer of the token, and /// let the library figure out how to build the packet properly. #[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr( feature = "parity-scale-codec", diff --git a/ibc-apps/ics20-transfer/types/src/packet.rs b/ibc-apps/ics20-transfer/types/src/packet.rs index 8d4d5192cd..f757a25dfe 100644 --- a/ibc-apps/ics20-transfer/types/src/packet.rs +++ b/ibc-apps/ics20-transfer/types/src/packet.rs @@ -10,6 +10,7 @@ use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketData as RawPa use super::{Amount, Memo, PrefixedCoin, PrefixedDenom}; /// Defines the structure of token transfers' packet bytes +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr( feature = "serde", diff --git a/ibc-apps/ics721-nft-transfer/Cargo.toml b/ibc-apps/ics721-nft-transfer/Cargo.toml index 2b3149f999..4c3430310b 100644 --- a/ibc-apps/ics721-nft-transfer/Cargo.toml +++ b/ibc-apps/ics721-nft-transfer/Cargo.toml @@ -52,3 +52,4 @@ parity-scale-codec = [ "ibc-app-nft-transfer-types/parity-scale-codec", "ibc-core/parity-scale-codec", ] +arbitrary = [ "ibc-app-nft-transfer-types/arbitrary" ] diff --git a/ibc-apps/ics721-nft-transfer/types/Cargo.toml b/ibc-apps/ics721-nft-transfer/types/Cargo.toml index bf9c36e2cf..da9725acaf 100644 --- a/ibc-apps/ics721-nft-transfer/types/Cargo.toml +++ b/ibc-apps/ics721-nft-transfer/types/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +arbitrary = { workspace = true, optional = true } borsh = { workspace = true, optional = true } base64 = { workspace = true, features = [ "alloc" ] } derive_more = { workspace = true } @@ -81,3 +82,4 @@ parity-scale-codec = [ "ibc-proto/parity-scale-codec", "ibc-app-transfer-types/parity-scale-codec", ] +arbitrary = [ "dep:arbitrary", "ibc-core/arbitrary" ] diff --git a/ibc-apps/ics721-nft-transfer/types/src/class.rs b/ibc-apps/ics721-nft-transfer/types/src/class.rs index d554be89b5..f223243ca9 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/class.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/class.rs @@ -14,6 +14,7 @@ use ibc_proto::ibc::applications::nft_transfer::v1::ClassTrace as RawClassTrace; use crate::data::Data; /// Class ID for an NFT +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( @@ -56,6 +57,7 @@ impl FromStr for ClassId { } /// Prefixed class to trace sources like ICS-20 PrefixedDenom +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr( @@ -180,10 +182,12 @@ impl Display for PrefixedClassId { } /// Class URI for an NFT +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct ClassUri( + #[cfg_attr(feature = "arbitrary", arbitrary(with = crate::arb_uri))] #[cfg_attr(feature = "serde", serde(with = "serializers"))] #[cfg_attr(feature = "schema", schemars(with = "String"))] Uri, @@ -253,6 +257,7 @@ impl FromStr for ClassUri { } /// Class data for an NFT +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-apps/ics721-nft-transfer/types/src/data.rs b/ibc-apps/ics721-nft-transfer/types/src/data.rs index 5151203f35..a7f4858b78 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/data.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/data.rs @@ -10,6 +10,7 @@ use ibc_core::host::types::error::DecodingError; use ibc_core::primitives::prelude::*; use mime::Mime; +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-apps/ics721-nft-transfer/types/src/lib.rs b/ibc-apps/ics721-nft-transfer/types/src/lib.rs index 6992c98f0a..68818015ac 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/lib.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/lib.rs @@ -55,3 +55,9 @@ use ibc_core::channel::types::acknowledgement::StatusValue; pub fn ack_success_b64() -> StatusValue { StatusValue::new(ACK_SUCCESS_B64).expect("ack status value is never supposed to be empty") } + +#[cfg(feature = "arbitrary")] +fn arb_uri(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let raw: std::string::String = arbitrary::Arbitrary::arbitrary(u)?; + http::Uri::try_from(&raw).map_err(|_| arbitrary::Error::IncorrectFormat) +} diff --git a/ibc-apps/ics721-nft-transfer/types/src/memo.rs b/ibc-apps/ics721-nft-transfer/types/src/memo.rs index b18f2027d2..996373d958 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/memo.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/memo.rs @@ -10,6 +10,7 @@ use core::str::FromStr; use ibc_core::primitives::prelude::*; /// Represents the token transfer memo +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs index 0ced7dbacf..a3f8569a1c 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs @@ -20,6 +20,7 @@ pub(crate) const TYPE_URL: &str = "/ibc.applications.nft_transfer.v1.MsgTransfer /// have to specify the information related to the transfer of the token, and /// let the library figure out how to build the packet properly. #[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr( feature = "parity-scale-codec", diff --git a/ibc-apps/ics721-nft-transfer/types/src/packet.rs b/ibc-apps/ics721-nft-transfer/types/src/packet.rs index afa773bfc9..5ccf429f3d 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/packet.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/packet.rs @@ -15,6 +15,7 @@ use crate::memo::Memo; use crate::token::{TokenData, TokenIds, TokenUri}; /// Defines the structure of token transfers' packet bytes +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] diff --git a/ibc-apps/ics721-nft-transfer/types/src/token.rs b/ibc-apps/ics721-nft-transfer/types/src/token.rs index b865ed1265..910714d045 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/token.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/token.rs @@ -11,6 +11,7 @@ use ibc_core::primitives::serializers; use crate::data::Data; /// Token ID for an NFT +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( @@ -52,6 +53,7 @@ impl FromStr for TokenId { } } +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( @@ -116,10 +118,12 @@ impl TryFrom> for TokenIds { } /// Token URI for an NFT +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct TokenUri( + #[cfg_attr(feature = "arbitrary", arbitrary(with = crate::arb_uri))] #[cfg_attr(feature = "serde", serde(with = "serializers"))] #[cfg_attr(feature = "schema", schemars(with = "String"))] Uri, @@ -187,6 +191,7 @@ impl FromStr for TokenUri { } /// Token data for an NFT +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/Cargo.toml b/ibc-core/Cargo.toml index eebb123180..059536aad1 100644 --- a/ibc-core/Cargo.toml +++ b/ibc-core/Cargo.toml @@ -82,3 +82,11 @@ parity-scale-codec = [ "ibc-core-handler/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] +arbitrary = [ + "ibc-core-client/arbitrary", + "ibc-core-connection/arbitrary", + "ibc-core-commitment-types/arbitrary", + "ibc-core-host/arbitrary", + "ibc-core-handler/arbitrary", + "ibc-primitives/arbitrary", +] diff --git a/ibc-core/ics02-client/Cargo.toml b/ibc-core/ics02-client/Cargo.toml index 7502b6a259..314324d15c 100644 --- a/ibc-core/ics02-client/Cargo.toml +++ b/ibc-core/ics02-client/Cargo.toml @@ -69,3 +69,4 @@ parity-scale-codec = [ "ibc-core-handler-types/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] +arbitrary = [ "ibc-core-client-types/arbitrary" ] diff --git a/ibc-core/ics02-client/types/Cargo.toml b/ibc-core/ics02-client/types/Cargo.toml index abc812cd43..0abc2593c2 100644 --- a/ibc-core/ics02-client/types/Cargo.toml +++ b/ibc-core/ics02-client/types/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +arbitrary = { workspace = true, optional = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } @@ -86,3 +87,4 @@ parity-scale-codec = [ "ibc-primitives/parity-scale-codec", "ibc-proto/parity-scale-codec", ] +arbitrary = [ "dep:arbitrary", "ibc-primitives/arbitrary" ] diff --git a/ibc-core/ics02-client/types/src/height.rs b/ibc-core/ics02-client/types/src/height.rs index 612351863f..1ae788addc 100644 --- a/ibc-core/ics02-client/types/src/height.rs +++ b/ibc-core/ics02-client/types/src/height.rs @@ -13,6 +13,7 @@ use crate::error::ClientError; /// The core IBC height type, which represents the height of a chain, /// which typically is the number of blocks since genesis /// (or more generally, since the last revision/hard upgrade). +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( 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 1891a143e9..d898e44da3 100644 --- a/ibc-core/ics02-client/types/src/msgs/create_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/create_client.rs @@ -10,6 +10,7 @@ use ibc_proto::Protobuf; pub const CREATE_CLIENT_TYPE_URL: &str = "/ibc.core.client.v1.MsgCreateClient"; /// A type of message that triggers the creation of a new on-chain (IBC) client. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) @@ -17,7 +18,9 @@ pub const CREATE_CLIENT_TYPE_URL: &str = "/ibc.core.client.v1.MsgCreateClient"; #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgCreateClient { + #[cfg_attr(feature = "arbitrary", arbitrary(with = ibc_primitives::arb_protobuf_any))] pub client_state: Any, + #[cfg_attr(feature = "arbitrary", arbitrary(with = ibc_primitives::arb_protobuf_any))] pub consensus_state: Any, pub signer: Signer, } diff --git a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs index 1e495393bb..22737778ad 100644 --- a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs +++ b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs @@ -14,6 +14,7 @@ pub const SUBMIT_MISBEHAVIOUR_TYPE_URL: &str = "/ibc.core.client.v1.MsgSubmitMis /// /// Deprecated since v0.51.0. Misbehaviour reports should be submitted via the `MsgUpdateClient` /// type through its `client_message` field. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[deprecated( since = "0.51.0", note = "Misbehaviour reports should be submitted via `MsgUpdateClient` through its `client_message` field" @@ -28,6 +29,7 @@ pub struct MsgSubmitMisbehaviour { /// client unique identifier pub client_id: ClientId, /// misbehaviour, used for freezing the light client + #[cfg_attr(feature = "arbitrary", arbitrary(with = ibc_primitives::arb_protobuf_any))] pub misbehaviour: ProtoAny, /// signer address pub signer: Signer, diff --git a/ibc-core/ics02-client/types/src/msgs/mod.rs b/ibc-core/ics02-client/types/src/msgs/mod.rs index fbb76a8211..6e88878915 100644 --- a/ibc-core/ics02-client/types/src/msgs/mod.rs +++ b/ibc-core/ics02-client/types/src/msgs/mod.rs @@ -21,6 +21,7 @@ pub use upgrade_client::*; /// Encodes all the different client messages #[allow(dead_code)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) diff --git a/ibc-core/ics02-client/types/src/msgs/recover_client.rs b/ibc-core/ics02-client/types/src/msgs/recover_client.rs index 5ef857cbaf..91fcb10066 100644 --- a/ibc-core/ics02-client/types/src/msgs/recover_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/recover_client.rs @@ -17,6 +17,7 @@ pub const RECOVER_CLIENT_TYPE_URL: &str = "/ibc.core.client.v1.MsgRecoverClient" /// client recovery functionality is not part of ibc-rs's public API. The /// intended usage of this message type is to be integrated with hosts' /// governance modules, not to be called directly via `dispatch`. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 16a5d250d8..8e9e901c2d 100644 --- a/ibc-core/ics02-client/types/src/msgs/update_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/update_client.rs @@ -14,6 +14,7 @@ pub const UPDATE_CLIENT_TYPE_URL: &str = "/ibc.core.client.v1.MsgUpdateClient"; /// either with new headers, or evidence of misbehaviour. /// Note that some types of misbehaviour can be detected when the headers /// are updated (`UpdateKind::UpdateClient`). +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) @@ -22,6 +23,7 @@ pub const UPDATE_CLIENT_TYPE_URL: &str = "/ibc.core.client.v1.MsgUpdateClient"; #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgUpdateClient { pub client_id: ClientId, + #[cfg_attr(feature = "arbitrary", arbitrary(with = ibc_primitives::arb_protobuf_any))] pub client_message: Any, pub signer: Signer, } 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 d581f8e1bc..ba66c391d9 100644 --- a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs @@ -14,6 +14,7 @@ use ibc_proto::Protobuf; pub const UPGRADE_CLIENT_TYPE_URL: &str = "/ibc.core.client.v1.MsgUpgradeClient"; /// A type of message that triggers the upgrade of an on-chain (IBC) client. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) @@ -24,9 +25,11 @@ pub struct MsgUpgradeClient { // client unique identifier pub client_id: ClientId, // Upgraded client state + #[cfg_attr(feature = "arbitrary", arbitrary(with = ibc_primitives::arb_protobuf_any))] pub upgraded_client_state: Any, // Upgraded consensus state, only contains enough information // to serve as a basis of trust in update logic + #[cfg_attr(feature = "arbitrary", arbitrary(with = ibc_primitives::arb_protobuf_any))] pub upgraded_consensus_state: Any, // proof that old chain committed to new client pub proof_upgrade_client: CommitmentProofBytes, diff --git a/ibc-core/ics03-connection/Cargo.toml b/ibc-core/ics03-connection/Cargo.toml index a6b19b7ab0..1bd6889d81 100644 --- a/ibc-core/ics03-connection/Cargo.toml +++ b/ibc-core/ics03-connection/Cargo.toml @@ -71,3 +71,4 @@ wasm-client = [ "dep:ibc-client-wasm-types", "dep:prost", ] +arbitrary = [ "ibc-core-connection-types/arbitrary" ] diff --git a/ibc-core/ics03-connection/types/Cargo.toml b/ibc-core/ics03-connection/types/Cargo.toml index 39ecc8485a..65bfa0fc05 100644 --- a/ibc-core/ics03-connection/types/Cargo.toml +++ b/ibc-core/ics03-connection/types/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +arbitrary = { workspace = true, optional = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } @@ -89,3 +90,9 @@ parity-scale-codec = [ "ibc-primitives/parity-scale-codec", "ibc-proto/parity-scale-codec", ] +arbitrary = [ + "dep:arbitrary", + "ibc-core-commitment-types/arbitrary", + "ibc-core-host-types/arbitrary", + "ibc-primitives/arbitrary" +] diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index f518f86a50..4657d00fe8 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -339,6 +339,7 @@ impl ConnectionEnd { } } +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( 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 9379c25e36..73147c9e52 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 @@ -14,6 +14,7 @@ pub const CONN_OPEN_ACK_TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionO /// Per our convention, this message is sent to chain A. /// The handler will check proofs of chain B. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) @@ -26,6 +27,7 @@ pub struct MsgConnectionOpenAck { /// ConnectionId that chain B has chosen for its ConnectionEnd pub conn_id_on_b: ConnectionId, /// ClientState of client tracking chain A on chain B + #[cfg_attr(feature = "arbitrary", arbitrary(with = ibc_primitives::arb_protobuf_any))] pub client_state_of_a_on_b: Any, /// proof of ConnectionEnd stored on Chain B during ConnOpenTry pub proof_conn_end_on_b: CommitmentProofBytes, 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 24a58b87e1..d7791c1103 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 @@ -11,6 +11,7 @@ pub const CONN_OPEN_CONFIRM_TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnect /// Per our convention, this message is sent to chain B. /// The handler will check proofs of chain A. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 57790a3870..8f63d83ffe 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 @@ -14,6 +14,7 @@ pub const CONN_OPEN_INIT_TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnection /// Per our convention, this message is sent to chain A. /// The handler will check proofs of chain B. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct MsgConnectionOpenInit { 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 ea5f22f039..9db7574704 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 @@ -17,12 +17,14 @@ pub const CONN_OPEN_TRY_TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionO /// Per our convention, this message is sent to chain B. /// The handler will check proofs of chain A. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgConnectionOpenTry { /// ClientId on B that the connection is being opened for pub client_id_on_b: ClientId, /// ClientState of client tracking chain B on chain A + #[cfg_attr(feature = "arbitrary", arbitrary(with = ibc_primitives::arb_protobuf_any))] pub client_state_of_b_on_a: Any, /// ClientId, ConnectionId and prefix of chain A pub counterparty: Counterparty, diff --git a/ibc-core/ics03-connection/types/src/msgs/mod.rs b/ibc-core/ics03-connection/types/src/msgs/mod.rs index d3be3dcf61..3e374e0016 100644 --- a/ibc-core/ics03-connection/types/src/msgs/mod.rs +++ b/ibc-core/ics03-connection/types/src/msgs/mod.rs @@ -25,6 +25,7 @@ pub use conn_open_init::*; pub use conn_open_try::*; /// Enumeration of all possible messages that the ICS3 protocol processes. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) diff --git a/ibc-core/ics03-connection/types/src/version.rs b/ibc-core/ics03-connection/types/src/version.rs index 89f577cc0a..d51641d509 100644 --- a/ibc-core/ics03-connection/types/src/version.rs +++ b/ibc-core/ics03-connection/types/src/version.rs @@ -11,6 +11,7 @@ use ibc_proto::Protobuf; use crate::error::ConnectionError; /// Stores the identifier and the features supported by a version +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics04-channel/types/Cargo.toml b/ibc-core/ics04-channel/types/Cargo.toml index 5cff829cea..67e04e4fa5 100644 --- a/ibc-core/ics04-channel/types/Cargo.toml +++ b/ibc-core/ics04-channel/types/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +arbitrary = { workspace = true, optional = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } @@ -101,3 +102,4 @@ parity-scale-codec = [ "ibc-primitives/parity-scale-codec", "ibc-proto/parity-scale-codec", ] +arbitrary = [ "dep:arbitrary", "ibc-primitives/arbitrary" ] diff --git a/ibc-core/ics04-channel/types/src/acknowledgement.rs b/ibc-core/ics04-channel/types/src/acknowledgement.rs index efbbe28ce3..1ca8673870 100644 --- a/ibc-core/ics04-channel/types/src/acknowledgement.rs +++ b/ibc-core/ics04-channel/types/src/acknowledgement.rs @@ -11,6 +11,7 @@ use crate::error::ChannelError; /// A generic Acknowledgement type that modules may interpret as they like. /// /// NOTE: An acknowledgement cannot be empty. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics04-channel/types/src/channel.rs b/ibc-core/ics04-channel/types/src/channel.rs index 38140cb354..ba03f9da34 100644 --- a/ibc-core/ics04-channel/types/src/channel.rs +++ b/ibc-core/ics04-channel/types/src/channel.rs @@ -430,6 +430,7 @@ impl From for RawCounterparty { } /// Represents the channel ordering +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs b/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs index 10839e91d1..3f531279ba 100644 --- a/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs +++ b/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs @@ -14,6 +14,7 @@ pub const ACKNOWLEDGEMENT_TYPE_URL: &str = "/ibc.core.channel.v1.MsgAcknowledgem /// /// Message definition for packet acknowledgements. /// +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 f3cbf1171e..112aae1375 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 @@ -14,6 +14,7 @@ pub const CHAN_CLOSE_CONFIRM_TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCl /// datagram). /// Per our convention, this message is sent to chain B. /// +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 3d852e5fa1..9aa8a11bc8 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 @@ -11,6 +11,7 @@ pub const CHAN_CLOSE_INIT_TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelClose /// Message definition for the first step in the channel close handshake (`ChanCloseInit` datagram). /// Per our convention, this message is sent to chain A. /// +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 4d1151ff61..6a54373a87 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 @@ -14,6 +14,7 @@ pub const CHAN_OPEN_ACK_TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenAck /// Message definition for the third step in the channel open handshake (`ChanOpenAck` datagram). /// /// Per our convention, this message is sent to chain A. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 d28fe2a6e4..259c5a198f 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 @@ -14,6 +14,7 @@ pub const CHAN_OPEN_CONFIRM_TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpe /// datagram). /// Per our convention, this message is sent to chain B. /// +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 2299802d49..a86a22a165 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 @@ -15,6 +15,7 @@ pub const CHAN_OPEN_INIT_TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenIn /// Message definition for the first step in the channel open handshake (`ChanOpenInit` datagram). /// Per our convention, this message is sent to chain A. /// +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 042f2c07a6..6a25dcf609 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 @@ -17,6 +17,7 @@ pub const CHAN_OPEN_TRY_TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenTry /// Message definition for the second step in the channel open handshake (`ChanOpenTry` datagram). /// Per our convention, this message is sent to chain B. /// +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) diff --git a/ibc-core/ics04-channel/types/src/msgs/mod.rs b/ibc-core/ics04-channel/types/src/msgs/mod.rs index 8e518591cf..705d764e01 100644 --- a/ibc-core/ics04-channel/types/src/msgs/mod.rs +++ b/ibc-core/ics04-channel/types/src/msgs/mod.rs @@ -29,6 +29,7 @@ pub use timeout::*; pub use timeout_on_close::*; /// All channel messages +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) @@ -45,6 +46,7 @@ pub enum ChannelMsg { } /// All packet messages +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 c2b14ab418..bd596ae595 100644 --- a/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs +++ b/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs @@ -13,6 +13,7 @@ pub const RECV_PACKET_TYPE_URL: &str = "/ibc.core.channel.v1.MsgRecvPacket"; /// /// Message definition for the "packet receiving" datagram. /// +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) diff --git a/ibc-core/ics04-channel/types/src/msgs/timeout.rs b/ibc-core/ics04-channel/types/src/msgs/timeout.rs index 5fc2558966..9d3c7bbd9b 100644 --- a/ibc-core/ics04-channel/types/src/msgs/timeout.rs +++ b/ibc-core/ics04-channel/types/src/msgs/timeout.rs @@ -15,6 +15,7 @@ pub const TIMEOUT_TYPE_URL: &str = "/ibc.core.channel.v1.MsgTimeout"; /// Message definition for packet timeout domain type, /// which is sent on chain A and needs to prove that a previously sent packet was not received on chain B /// +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) 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 34394b8561..dfc3ad0621 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 @@ -14,6 +14,7 @@ pub const TIMEOUT_ON_CLOSE_TYPE_URL: &str = "/ibc.core.channel.v1.MsgTimeoutOnCl /// /// Message definition for packet timeout domain type. /// +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) diff --git a/ibc-core/ics04-channel/types/src/packet.rs b/ibc-core/ics04-channel/types/src/packet.rs index 82b28a1fd9..7dd73c0ba0 100644 --- a/ibc-core/ics04-channel/types/src/packet.rs +++ b/ibc-core/ics04-channel/types/src/packet.rs @@ -68,6 +68,7 @@ impl core::fmt::Display for PacketMsgType { /// The packet type; this is what applications send to one another. /// /// Each application defines the structure of the `data` field. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics04-channel/types/src/timeout/height.rs b/ibc-core/ics04-channel/types/src/timeout/height.rs index 46d6ab49a9..8ca9670371 100644 --- a/ibc-core/ics04-channel/types/src/timeout/height.rs +++ b/ibc-core/ics04-channel/types/src/timeout/height.rs @@ -17,6 +17,7 @@ use ibc_proto::ibc::core::client::v1::Height as RawHeight; /// is legal and meaningful, even though the Tendermint spec rejects this height /// as invalid. Thus, it must be parsed specially, where this special case means /// "no timeout". +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics04-channel/types/src/version.rs b/ibc-core/ics04-channel/types/src/version.rs index 1cf5c894af..a441a17b95 100644 --- a/ibc-core/ics04-channel/types/src/version.rs +++ b/ibc-core/ics04-channel/types/src/version.rs @@ -15,6 +15,7 @@ use super::error::ChannelError; /// This field is opaque to the core IBC protocol. /// No explicit validation is necessary, and the /// spec (v1) currently allows empty strings. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics23-commitment/types/Cargo.toml b/ibc-core/ics23-commitment/types/Cargo.toml index b627642fdb..40e67f5432 100644 --- a/ibc-core/ics23-commitment/types/Cargo.toml +++ b/ibc-core/ics23-commitment/types/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +arbitrary = { workspace = true, optional = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true, features = [ "as_ref" ] } displaydoc = { workspace = true } @@ -79,3 +80,8 @@ parity-scale-codec = [ "ibc-core-host-types/parity-scale-codec", "ibc-proto/parity-scale-codec", ] +arbitrary = [ + "dep:arbitrary", + "ibc-core-host-types/arbitrary", + "ibc-primitives/arbitrary" +] diff --git a/ibc-core/ics23-commitment/types/src/commitment.rs b/ibc-core/ics23-commitment/types/src/commitment.rs index af1f30153a..a15278a43d 100644 --- a/ibc-core/ics23-commitment/types/src/commitment.rs +++ b/ibc-core/ics23-commitment/types/src/commitment.rs @@ -63,6 +63,7 @@ impl From> for CommitmentRoot { /// /// For example, in the case of a proof of membership in a Merkle tree, /// this encodes a Merkle proof. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) @@ -128,6 +129,7 @@ impl<'a> TryFrom<&'a CommitmentProofBytes> for MerkleProof { /// Defines a store prefix of the commitment proof. /// /// See [spec](https://github.com/cosmos/ibc/blob/main/spec/core/ics-023-vector-commitments/README.md#prefix). +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics24-host/Cargo.toml b/ibc-core/ics24-host/Cargo.toml index c97fb73244..e10cabe054 100644 --- a/ibc-core/ics24-host/Cargo.toml +++ b/ibc-core/ics24-host/Cargo.toml @@ -92,3 +92,4 @@ parity-scale-codec = [ "ibc-core-handler-types/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] +arbitrary = [ "ibc-core-host-types/arbitrary" ] diff --git a/ibc-core/ics24-host/types/Cargo.toml b/ibc-core/ics24-host/types/Cargo.toml index e4953c7205..45fc4b1325 100644 --- a/ibc-core/ics24-host/types/Cargo.toml +++ b/ibc-core/ics24-host/types/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +arbitrary = { workspace = true, optional = true } base64 = { workspace = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true } @@ -64,3 +65,4 @@ parity-scale-codec = [ "dep:scale-info", "ibc-primitives/parity-scale-codec", ] +arbitrary = [ "dep:arbitrary", "ibc-primitives/arbitrary" ] 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 c8f9e30d77..2223778bd2 100644 --- a/ibc-core/ics24-host/types/src/identifiers/channel_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/channel_id.rs @@ -9,6 +9,7 @@ use crate::validate::validate_channel_identifier; const CHANNEL_ID_PREFIX: &str = "channel"; +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( 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 d0128336b4..76f157c19c 100644 --- a/ibc-core/ics24-host/types/src/identifiers/client_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/client_id.rs @@ -6,6 +6,7 @@ use ibc_primitives::prelude::*; use crate::error::IdentifierError; use crate::validate::{validate_client_identifier, validate_client_type}; +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( 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 9fe9657cc3..92fe20260f 100644 --- a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs @@ -9,6 +9,7 @@ use crate::validate::validate_connection_identifier; const CONNECTION_ID_PREFIX: &str = "connection"; +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics24-host/types/src/identifiers/port_id.rs b/ibc-core/ics24-host/types/src/identifiers/port_id.rs index e1a0e062da..2f28b4a41a 100644 --- a/ibc-core/ics24-host/types/src/identifiers/port_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/port_id.rs @@ -9,6 +9,7 @@ use crate::validate::validate_port_identifier; const TRANSFER_PORT_ID: &str = "transfer"; +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics24-host/types/src/identifiers/sequence.rs b/ibc-core/ics24-host/types/src/identifiers/sequence.rs index 0ab91f24cb..c150f2e8a1 100644 --- a/ibc-core/ics24-host/types/src/identifiers/sequence.rs +++ b/ibc-core/ics24-host/types/src/identifiers/sequence.rs @@ -2,6 +2,7 @@ use ibc_primitives::prelude::*; use crate::error::IdentifierError; +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-core/ics25-handler/Cargo.toml b/ibc-core/ics25-handler/Cargo.toml index 43dcf44ed1..29d70e10d8 100644 --- a/ibc-core/ics25-handler/Cargo.toml +++ b/ibc-core/ics25-handler/Cargo.toml @@ -81,3 +81,4 @@ parity-scale-codec = [ "ibc-core-handler-types/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] +arbitrary = [ "ibc-core-handler-types/arbitrary" ] diff --git a/ibc-core/ics25-handler/types/Cargo.toml b/ibc-core/ics25-handler/types/Cargo.toml index 8e51544933..eb36a60db0 100644 --- a/ibc-core/ics25-handler/types/Cargo.toml +++ b/ibc-core/ics25-handler/types/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +arbitrary = { workspace = true, optional = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } @@ -107,3 +108,8 @@ parity-scale-codec = [ "ibc-primitives/parity-scale-codec", "ibc-proto/parity-scale-codec", ] +arbitrary = [ + "dep:arbitrary", + "ibc-core-channel-types/arbitrary", + "ibc-primitives/arbitrary", +] diff --git a/ibc-core/ics25-handler/types/src/msgs.rs b/ibc-core/ics25-handler/types/src/msgs.rs index a47a9b7021..9156f88157 100644 --- a/ibc-core/ics25-handler/types/src/msgs.rs +++ b/ibc-core/ics25-handler/types/src/msgs.rs @@ -23,6 +23,7 @@ use ibc_proto::google::protobuf::Any; use ibc_proto::Protobuf; /// Enumeration of all messages that the local ICS26 module is capable of routing. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) diff --git a/ibc-primitives/Cargo.toml b/ibc-primitives/Cargo.toml index 7f8432e7d5..a62221db78 100644 --- a/ibc-primitives/Cargo.toml +++ b/ibc-primitives/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +arbitrary = { workspace = true, optional = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } @@ -67,3 +68,4 @@ parity-scale-codec = [ "dep:scale-info", "ibc-proto/parity-scale-codec", ] +arbitrary = [ "dep:arbitrary" ] diff --git a/ibc-primitives/src/lib.rs b/ibc-primitives/src/lib.rs index 277c794cd8..c2f7aa81a1 100644 --- a/ibc-primitives/src/lib.rs +++ b/ibc-primitives/src/lib.rs @@ -34,3 +34,12 @@ pub mod proto { pub use ibc_proto::google::protobuf::{Any, Duration, Timestamp}; pub use ibc_proto::{Error, Protobuf}; } + +#[cfg(feature = "arbitrary")] +pub fn arb_protobuf_any( + u: &mut arbitrary::Unstructured<'_>, +) -> arbitrary::Result { + let type_url: std::string::String = arbitrary::Arbitrary::arbitrary(u)?; + let value: std::vec::Vec = arbitrary::Arbitrary::arbitrary(u)?; + Ok(ibc_proto::google::protobuf::Any { type_url, value }) +} diff --git a/ibc-primitives/src/types/signer.rs b/ibc-primitives/src/types/signer.rs index a00cd498e0..0eeacef6f0 100644 --- a/ibc-primitives/src/types/signer.rs +++ b/ibc-primitives/src/types/signer.rs @@ -3,6 +3,7 @@ use derive_more::Display; use crate::prelude::*; /// Represents the address of the signer of the current transaction +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-primitives/src/types/timestamp.rs b/ibc-primitives/src/types/timestamp.rs index 33fca85d68..160ac36f07 100644 --- a/ibc-primitives/src/types/timestamp.rs +++ b/ibc-primitives/src/types/timestamp.rs @@ -26,10 +26,12 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0); /// It is also encoded as part of the /// `ibc::channel::types::timeout::TimeoutTimestamp` type for expressly keeping /// track of timeout timestamps. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[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 = "arbitrary", arbitrary(with = arb_tendermint_time))] #[cfg_attr(feature = "schema", schemars(with = "u64"))] time: PrimitiveDateTime, } @@ -435,3 +437,17 @@ mod tests { let _ = Timestamp::decode(&mut encode_timestamp.as_slice()).unwrap(); } } + +#[cfg(feature = "arbitrary")] +fn arb_tendermint_time(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result> { + Ok(if ::arbitrary(u)? { + let secs: i64 = u.int_in_range(0..=i64::MAX)?; + let nanos: u32 = u.int_in_range(0..=999_999_999)?; + Some( + Time::from_unix_timestamp(secs, nanos) + .map_err(|_| arbitrary::Error::IncorrectFormat)?, + ) + } else { + None + }) +} diff --git a/ibc/Cargo.toml b/ibc/Cargo.toml index 1005db2a0d..3d84005489 100644 --- a/ibc/Cargo.toml +++ b/ibc/Cargo.toml @@ -67,3 +67,8 @@ parity-scale-codec = [ "ibc-core-host-cosmos/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] +arbitrary = [ + "ibc-apps/arbitrary", + "ibc-core/arbitrary", + "ibc-primitives/arbitrary", +] From bfe33c32b46c0547997388afe610bf245576ac27 Mon Sep 17 00:00:00 2001 From: yito88 Date: Fri, 23 Aug 2024 15:45:31 +0200 Subject: [PATCH 02/10] arbitrary for timestamp --- ibc-apps/ics20-transfer/types/src/amount.rs | 12 ++++----- .../types/src/timeout/timestamp.rs | 1 + ibc-primitives/src/types/timestamp.rs | 26 +++++++++---------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/amount.rs b/ibc-apps/ics20-transfer/types/src/amount.rs index 71f886d22d..df81f5960a 100644 --- a/ibc-apps/ics20-transfer/types/src/amount.rs +++ b/ibc-apps/ics20-transfer/types/src/amount.rs @@ -131,6 +131,12 @@ where .map_err(serde::de::Error::custom) } +#[cfg(feature = "arbitrary")] +fn arb_u256(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { + let parts: [u8; 32] = arbitrary::Arbitrary::arbitrary(u)?; + Ok(U256::from_big_endian(&parts)) +} + #[cfg(test)] mod tests { use super::Amount; @@ -160,9 +166,3 @@ mod tests { assert_eq!(value, value_deserialized); } } - -#[cfg(feature = "arbitrary")] -fn arb_u256(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result { - let parts: [u8; 32] = arbitrary::Arbitrary::arbitrary(u)?; - Ok(U256::from_big_endian(&parts)) -} diff --git a/ibc-core/ics04-channel/types/src/timeout/timestamp.rs b/ibc-core/ics04-channel/types/src/timeout/timestamp.rs index 8cd45b712b..dd11089cdb 100644 --- a/ibc-core/ics04-channel/types/src/timeout/timestamp.rs +++ b/ibc-core/ics04-channel/types/src/timeout/timestamp.rs @@ -14,6 +14,7 @@ use crate::error::ChannelError; /// nanoseconds. A protocol value of 0 indicates that the timestamp is not set. /// In this case, we use the explicit `Never` variant to distinguish the absence /// of a timeout when converting from a zero protobuf value. +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( feature = "parity-scale-codec", derive( diff --git a/ibc-primitives/src/types/timestamp.rs b/ibc-primitives/src/types/timestamp.rs index 160ac36f07..ebf21f25a6 100644 --- a/ibc-primitives/src/types/timestamp.rs +++ b/ibc-primitives/src/types/timestamp.rs @@ -311,6 +311,18 @@ impl std::error::Error for TimestampError { } } +#[cfg(feature = "arbitrary")] +fn arb_tendermint_time( + u: &mut arbitrary::Unstructured<'_>, +) -> arbitrary::Result { + let secs: u64 = u.int_in_range(0..=u64::MAX)?; + let nanos: u32 = u.int_in_range(0..=999_999_999)?; + let total_nanos = secs as i128 * 1_000_000_000 + nanos as i128; + let odt = OffsetDateTime::from_unix_timestamp_nanos(total_nanos) + .map_err(|_| arbitrary::Error::IncorrectFormat)?; + Ok(PrimitiveDateTime::new(odt.date(), odt.time())) +} + #[cfg(test)] mod tests { use core::time::Duration; @@ -437,17 +449,3 @@ mod tests { let _ = Timestamp::decode(&mut encode_timestamp.as_slice()).unwrap(); } } - -#[cfg(feature = "arbitrary")] -fn arb_tendermint_time(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result> { - Ok(if ::arbitrary(u)? { - let secs: i64 = u.int_in_range(0..=i64::MAX)?; - let nanos: u32 = u.int_in_range(0..=999_999_999)?; - Some( - Time::from_unix_timestamp(secs, nanos) - .map_err(|_| arbitrary::Error::IncorrectFormat)?, - ) - } else { - None - }) -} From 902524329b0bcbc8e9640b15949b2ef385db4868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Mon, 13 Jan 2025 15:19:53 +0000 Subject: [PATCH 03/10] fix individual crates arbitrary feature deps --- ibc-apps/ics20-transfer/types/Cargo.toml | 2 +- ibc-apps/ics721-nft-transfer/types/Cargo.toml | 7 ++++++- ibc-core/Cargo.toml | 1 + ibc-core/ics02-client/types/Cargo.toml | 7 ++++++- ibc-core/ics03-connection/types/Cargo.toml | 4 +++- ibc-core/ics04-channel/types/Cargo.toml | 8 +++++++- ibc-core/ics23-commitment/types/Cargo.toml | 3 ++- ibc-core/ics24-host/types/Cargo.toml | 2 +- ibc-core/ics25-handler/types/Cargo.toml | 2 ++ ibc-primitives/Cargo.toml | 2 +- 10 files changed, 30 insertions(+), 8 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/Cargo.toml b/ibc-apps/ics20-transfer/types/Cargo.toml index 0a2b3a1513..9d6a9270c7 100644 --- a/ibc-apps/ics20-transfer/types/Cargo.toml +++ b/ibc-apps/ics20-transfer/types/Cargo.toml @@ -75,4 +75,4 @@ parity-scale-codec = [ "ibc-core/parity-scale-codec", "ibc-proto/parity-scale-codec", ] -arbitrary = [ "dep:arbitrary", "ibc-core/arbitrary" ] +arbitrary = [ "dep:arbitrary", "ibc-core/arbitrary", "std" ] diff --git a/ibc-apps/ics721-nft-transfer/types/Cargo.toml b/ibc-apps/ics721-nft-transfer/types/Cargo.toml index da9725acaf..9443492842 100644 --- a/ibc-apps/ics721-nft-transfer/types/Cargo.toml +++ b/ibc-apps/ics721-nft-transfer/types/Cargo.toml @@ -82,4 +82,9 @@ parity-scale-codec = [ "ibc-proto/parity-scale-codec", "ibc-app-transfer-types/parity-scale-codec", ] -arbitrary = [ "dep:arbitrary", "ibc-core/arbitrary" ] +arbitrary = [ + "dep:arbitrary", + "ibc-core/arbitrary", + "ibc-app-transfer-types/arbitrary", + "std", +] diff --git a/ibc-core/Cargo.toml b/ibc-core/Cargo.toml index 059536aad1..e63ee7f7a9 100644 --- a/ibc-core/Cargo.toml +++ b/ibc-core/Cargo.toml @@ -89,4 +89,5 @@ arbitrary = [ "ibc-core-host/arbitrary", "ibc-core-handler/arbitrary", "ibc-primitives/arbitrary", + "std", ] diff --git a/ibc-core/ics02-client/types/Cargo.toml b/ibc-core/ics02-client/types/Cargo.toml index 0abc2593c2..0852bdf074 100644 --- a/ibc-core/ics02-client/types/Cargo.toml +++ b/ibc-core/ics02-client/types/Cargo.toml @@ -87,4 +87,9 @@ parity-scale-codec = [ "ibc-primitives/parity-scale-codec", "ibc-proto/parity-scale-codec", ] -arbitrary = [ "dep:arbitrary", "ibc-primitives/arbitrary" ] +arbitrary = [ + "dep:arbitrary", + "ibc-primitives/arbitrary", + "ibc-core-commitment-types/arbitrary", + "std", +] diff --git a/ibc-core/ics03-connection/types/Cargo.toml b/ibc-core/ics03-connection/types/Cargo.toml index 65bfa0fc05..016c2bf76e 100644 --- a/ibc-core/ics03-connection/types/Cargo.toml +++ b/ibc-core/ics03-connection/types/Cargo.toml @@ -92,7 +92,9 @@ parity-scale-codec = [ ] arbitrary = [ "dep:arbitrary", + "ibc-core-client-types/arbitrary", "ibc-core-commitment-types/arbitrary", "ibc-core-host-types/arbitrary", - "ibc-primitives/arbitrary" + "ibc-primitives/arbitrary", + "std", ] diff --git a/ibc-core/ics04-channel/types/Cargo.toml b/ibc-core/ics04-channel/types/Cargo.toml index 67e04e4fa5..03eca219ed 100644 --- a/ibc-core/ics04-channel/types/Cargo.toml +++ b/ibc-core/ics04-channel/types/Cargo.toml @@ -102,4 +102,10 @@ parity-scale-codec = [ "ibc-primitives/parity-scale-codec", "ibc-proto/parity-scale-codec", ] -arbitrary = [ "dep:arbitrary", "ibc-primitives/arbitrary" ] +arbitrary = [ + "dep:arbitrary", + "ibc-core-client-types/arbitrary", + "ibc-core-host-types/arbitrary", + "ibc-primitives/arbitrary", + "std", +] diff --git a/ibc-core/ics23-commitment/types/Cargo.toml b/ibc-core/ics23-commitment/types/Cargo.toml index 40e67f5432..fc68f2d3db 100644 --- a/ibc-core/ics23-commitment/types/Cargo.toml +++ b/ibc-core/ics23-commitment/types/Cargo.toml @@ -83,5 +83,6 @@ parity-scale-codec = [ arbitrary = [ "dep:arbitrary", "ibc-core-host-types/arbitrary", - "ibc-primitives/arbitrary" + "ibc-primitives/arbitrary", + "std", ] diff --git a/ibc-core/ics24-host/types/Cargo.toml b/ibc-core/ics24-host/types/Cargo.toml index 45fc4b1325..4aadb3687e 100644 --- a/ibc-core/ics24-host/types/Cargo.toml +++ b/ibc-core/ics24-host/types/Cargo.toml @@ -65,4 +65,4 @@ parity-scale-codec = [ "dep:scale-info", "ibc-primitives/parity-scale-codec", ] -arbitrary = [ "dep:arbitrary", "ibc-primitives/arbitrary" ] +arbitrary = [ "dep:arbitrary", "ibc-primitives/arbitrary", "std" ] diff --git a/ibc-core/ics25-handler/types/Cargo.toml b/ibc-core/ics25-handler/types/Cargo.toml index eb36a60db0..2f59f45039 100644 --- a/ibc-core/ics25-handler/types/Cargo.toml +++ b/ibc-core/ics25-handler/types/Cargo.toml @@ -110,6 +110,8 @@ parity-scale-codec = [ ] arbitrary = [ "dep:arbitrary", + "ibc-core-connection-types/arbitrary", "ibc-core-channel-types/arbitrary", "ibc-primitives/arbitrary", + "std", ] diff --git a/ibc-primitives/Cargo.toml b/ibc-primitives/Cargo.toml index a62221db78..cdbe77b9aa 100644 --- a/ibc-primitives/Cargo.toml +++ b/ibc-primitives/Cargo.toml @@ -68,4 +68,4 @@ parity-scale-codec = [ "dep:scale-info", "ibc-proto/parity-scale-codec", ] -arbitrary = [ "dep:arbitrary" ] +arbitrary = [ "dep:arbitrary", "std" ] From 7dcca83e76394facb47861cff4c2f9ba65af8b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Mon, 13 Jan 2025 15:50:22 +0000 Subject: [PATCH 04/10] changelog: add #1390 --- .changelog/unreleased/features/1390-derive-arbitrary.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/features/1390-derive-arbitrary.md diff --git a/.changelog/unreleased/features/1390-derive-arbitrary.md b/.changelog/unreleased/features/1390-derive-arbitrary.md new file mode 100644 index 0000000000..21b269f313 --- /dev/null +++ b/.changelog/unreleased/features/1390-derive-arbitrary.md @@ -0,0 +1,2 @@ +- Added arbitrary trait implementation behind "arbitrary" feature flag. + ([\#1390](https://github.com/cosmos/ibc-rs/pull/1390)) \ No newline at end of file From 80f89a1caa998a9da88838b392e7cd38584472a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 14 Jan 2025 16:54:35 +0000 Subject: [PATCH 05/10] fix aribtrary feature not to rely on transitivity --- ibc-apps/ics20-transfer/Cargo.toml | 2 +- ibc-apps/ics721-nft-transfer/Cargo.toml | 2 +- ibc-core/ics02-client/types/Cargo.toml | 1 + ibc-core/ics03-connection/Cargo.toml | 8 +++++++- ibc-core/ics04-channel/types/Cargo.toml | 2 ++ ibc-core/ics25-handler/Cargo.toml | 9 ++++++++- ibc-core/ics25-handler/types/Cargo.toml | 3 +++ 7 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ibc-apps/ics20-transfer/Cargo.toml b/ibc-apps/ics20-transfer/Cargo.toml index 6e4d47e6f6..70e99d9512 100644 --- a/ibc-apps/ics20-transfer/Cargo.toml +++ b/ibc-apps/ics20-transfer/Cargo.toml @@ -55,4 +55,4 @@ parity-scale-codec = [ "ibc-app-transfer-types/parity-scale-codec", "ibc-core/parity-scale-codec", ] -arbitrary = [ "ibc-app-transfer-types/arbitrary" ] +arbitrary = [ "ibc-app-transfer-types/arbitrary", "ibc-core/arbitrary" ] diff --git a/ibc-apps/ics721-nft-transfer/Cargo.toml b/ibc-apps/ics721-nft-transfer/Cargo.toml index 4c3430310b..e7625cfd1f 100644 --- a/ibc-apps/ics721-nft-transfer/Cargo.toml +++ b/ibc-apps/ics721-nft-transfer/Cargo.toml @@ -52,4 +52,4 @@ parity-scale-codec = [ "ibc-app-nft-transfer-types/parity-scale-codec", "ibc-core/parity-scale-codec", ] -arbitrary = [ "ibc-app-nft-transfer-types/arbitrary" ] +arbitrary = [ "ibc-app-nft-transfer-types/arbitrary", "ibc-core/arbitrary" ] diff --git a/ibc-core/ics02-client/types/Cargo.toml b/ibc-core/ics02-client/types/Cargo.toml index 0852bdf074..8e84513710 100644 --- a/ibc-core/ics02-client/types/Cargo.toml +++ b/ibc-core/ics02-client/types/Cargo.toml @@ -91,5 +91,6 @@ arbitrary = [ "dep:arbitrary", "ibc-primitives/arbitrary", "ibc-core-commitment-types/arbitrary", + "ibc-core-host-types/arbitrary", "std", ] diff --git a/ibc-core/ics03-connection/Cargo.toml b/ibc-core/ics03-connection/Cargo.toml index 1bd6889d81..aad4efcdf4 100644 --- a/ibc-core/ics03-connection/Cargo.toml +++ b/ibc-core/ics03-connection/Cargo.toml @@ -71,4 +71,10 @@ wasm-client = [ "dep:ibc-client-wasm-types", "dep:prost", ] -arbitrary = [ "ibc-core-connection-types/arbitrary" ] +arbitrary = [ + "ibc-core-client/arbitrary", + "ibc-core-connection-types/arbitrary", + "ibc-core-host/arbitrary", + "ibc-core-handler-types/arbitrary", + "ibc-primitives/arbitrary", +] diff --git a/ibc-core/ics04-channel/types/Cargo.toml b/ibc-core/ics04-channel/types/Cargo.toml index 03eca219ed..89e2d4b29a 100644 --- a/ibc-core/ics04-channel/types/Cargo.toml +++ b/ibc-core/ics04-channel/types/Cargo.toml @@ -105,7 +105,9 @@ parity-scale-codec = [ arbitrary = [ "dep:arbitrary", "ibc-core-client-types/arbitrary", + "ibc-core-connection-types/arbitrary", "ibc-core-host-types/arbitrary", + "ibc-core-commitment-types/arbitrary", "ibc-primitives/arbitrary", "std", ] diff --git a/ibc-core/ics25-handler/Cargo.toml b/ibc-core/ics25-handler/Cargo.toml index 29d70e10d8..e064522cfb 100644 --- a/ibc-core/ics25-handler/Cargo.toml +++ b/ibc-core/ics25-handler/Cargo.toml @@ -81,4 +81,11 @@ parity-scale-codec = [ "ibc-core-handler-types/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] -arbitrary = [ "ibc-core-handler-types/arbitrary" ] +arbitrary = [ + "ibc-core-client/arbitrary", + "ibc-core-connection/arbitrary", + "ibc-core-commitment-types/arbitrary", + "ibc-core-host/arbitrary", + "ibc-core-handler-types/arbitrary", + "ibc-primitives/arbitrary", +] diff --git a/ibc-core/ics25-handler/types/Cargo.toml b/ibc-core/ics25-handler/types/Cargo.toml index 2f59f45039..714b17f32c 100644 --- a/ibc-core/ics25-handler/types/Cargo.toml +++ b/ibc-core/ics25-handler/types/Cargo.toml @@ -110,8 +110,11 @@ parity-scale-codec = [ ] arbitrary = [ "dep:arbitrary", + "ibc-core-client-types/arbitrary", "ibc-core-connection-types/arbitrary", "ibc-core-channel-types/arbitrary", + "ibc-core-commitment-types/arbitrary", + "ibc-core-host-types/arbitrary", "ibc-primitives/arbitrary", "std", ] From 80b2301c34b09e33fc0a92531d5345300ddcc77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 14 Jan 2025 16:55:11 +0000 Subject: [PATCH 06/10] simpler timestamp arbitrary impl --- ibc-primitives/src/types/timestamp.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/ibc-primitives/src/types/timestamp.rs b/ibc-primitives/src/types/timestamp.rs index ebf21f25a6..eafa8608c4 100644 --- a/ibc-primitives/src/types/timestamp.rs +++ b/ibc-primitives/src/types/timestamp.rs @@ -26,16 +26,22 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0); /// It is also encoded as part of the /// `ibc::channel::types::timeout::TimeoutTimestamp` type for expressly keeping /// track of timeout timestamps. -#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[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 = "arbitrary", arbitrary(with = arb_tendermint_time))] #[cfg_attr(feature = "schema", schemars(with = "u64"))] time: PrimitiveDateTime, } +#[cfg(feature = "arbitrary")] +impl<'a> arbitrary::Arbitrary<'a> for Timestamp { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let nanos: u64 = arbitrary::Arbitrary::arbitrary(u)?; + Ok(Timestamp::from_nanoseconds(nanos)) + } +} + impl Timestamp { pub fn from_nanoseconds(nanoseconds: u64) -> Self { // As the `u64` can only represent times up to about year 2554, there is @@ -311,18 +317,6 @@ impl std::error::Error for TimestampError { } } -#[cfg(feature = "arbitrary")] -fn arb_tendermint_time( - u: &mut arbitrary::Unstructured<'_>, -) -> arbitrary::Result { - let secs: u64 = u.int_in_range(0..=u64::MAX)?; - let nanos: u32 = u.int_in_range(0..=999_999_999)?; - let total_nanos = secs as i128 * 1_000_000_000 + nanos as i128; - let odt = OffsetDateTime::from_unix_timestamp_nanos(total_nanos) - .map_err(|_| arbitrary::Error::IncorrectFormat)?; - Ok(PrimitiveDateTime::new(odt.date(), odt.time())) -} - #[cfg(test)] mod tests { use core::time::Duration; From 8d111312db2aa7512a0271c4d5776f4109732dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 14 Jan 2025 16:56:05 +0000 Subject: [PATCH 07/10] fix lint --- ibc-apps/ics20-transfer/types/src/coin.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/coin.rs b/ibc-apps/ics20-transfer/types/src/coin.rs index 4ef61942cc..0447c4b5c1 100644 --- a/ibc-apps/ics20-transfer/types/src/coin.rs +++ b/ibc-apps/ics20-transfer/types/src/coin.rs @@ -166,12 +166,12 @@ mod tests { "115792089237316195423570985008687907853269984665640564039457584007913129639936stake" )] #[case::invalid_char_in_denom("0x!")] - #[case::blackslash_in_denom("0x1/:.\\_-")] + #[case::backslash_in_denom("0x1/:.\\_-")] #[should_panic] fn test_failed_parse_raw_coin(#[case] _raw: RawCoin) {} #[rstest] - #[case::nomal("123stake,1a1,999den0m", &[(123, "stake"), (1, "a1"), (999, "den0m")])] + #[case::normal("123stake,1a1,999den0m", &[(123, "stake"), (1, "a1"), (999, "den0m")])] #[case::tricky("123stake,1a1-999den0m", &[(123, "stake"), (1, "a1-999den0m")])] #[case::colon_delimiter("123stake:1a1:999den0m", &[(123, "stake:1a1:999den0m")])] #[case::dash_delimiter("123stake-1a1-999den0m", &[(123, "stake-1a1-999den0m")])] From 0651ff889333035183a38ce72f65f20b20b31b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 16 Jan 2025 11:03:59 +0000 Subject: [PATCH 08/10] add more missing arbitrary transitive features --- ibc-core/Cargo.toml | 1 + ibc-core/ics02-client/Cargo.toml | 8 +++++++- ibc-core/ics04-channel/Cargo.toml | 9 +++++++++ ibc-core/ics24-host/Cargo.toml | 10 +++++++++- ibc-core/ics24-host/cosmos/Cargo.toml | 8 ++++++++ ibc-core/ics25-handler/Cargo.toml | 1 + 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/ibc-core/Cargo.toml b/ibc-core/Cargo.toml index e63ee7f7a9..73785201d2 100644 --- a/ibc-core/Cargo.toml +++ b/ibc-core/Cargo.toml @@ -85,6 +85,7 @@ parity-scale-codec = [ arbitrary = [ "ibc-core-client/arbitrary", "ibc-core-connection/arbitrary", + "ibc-core-channel/arbitrary", "ibc-core-commitment-types/arbitrary", "ibc-core-host/arbitrary", "ibc-core-handler/arbitrary", diff --git a/ibc-core/ics02-client/Cargo.toml b/ibc-core/ics02-client/Cargo.toml index 314324d15c..aec647ccbb 100644 --- a/ibc-core/ics02-client/Cargo.toml +++ b/ibc-core/ics02-client/Cargo.toml @@ -69,4 +69,10 @@ parity-scale-codec = [ "ibc-core-handler-types/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] -arbitrary = [ "ibc-core-client-types/arbitrary" ] +arbitrary = [ + "ibc-core-client-types/arbitrary", + "ibc-core-commitment-types/arbitrary", + "ibc-core-host/arbitrary", + "ibc-core-handler-types/arbitrary", + "ibc-primitives/arbitrary", +] diff --git a/ibc-core/ics04-channel/Cargo.toml b/ibc-core/ics04-channel/Cargo.toml index 1ad973cc18..9ad505d41c 100644 --- a/ibc-core/ics04-channel/Cargo.toml +++ b/ibc-core/ics04-channel/Cargo.toml @@ -81,3 +81,12 @@ parity-scale-codec = [ "ibc-core-router/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] +arbitrary = [ + "ibc-core-client/arbitrary", + "ibc-core-connection/arbitrary", + "ibc-core-channel-types/arbitrary", + "ibc-core-commitment-types/arbitrary", + "ibc-core-host/arbitrary", + "ibc-core-handler-types/arbitrary", + "ibc-primitives/arbitrary", +] diff --git a/ibc-core/ics24-host/Cargo.toml b/ibc-core/ics24-host/Cargo.toml index e10cabe054..55af891aff 100644 --- a/ibc-core/ics24-host/Cargo.toml +++ b/ibc-core/ics24-host/Cargo.toml @@ -92,4 +92,12 @@ parity-scale-codec = [ "ibc-core-handler-types/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] -arbitrary = [ "ibc-core-host-types/arbitrary" ] +arbitrary = [ + "ibc-core-client-types/arbitrary", + "ibc-core-connection-types/arbitrary", + "ibc-core-channel-types/arbitrary", + "ibc-core-commitment-types/arbitrary", + "ibc-core-host-types/arbitrary", + "ibc-core-handler-types/arbitrary", + "ibc-primitives/arbitrary", +] diff --git a/ibc-core/ics24-host/cosmos/Cargo.toml b/ibc-core/ics24-host/cosmos/Cargo.toml index 50e06f273b..c8d4fed295 100644 --- a/ibc-core/ics24-host/cosmos/Cargo.toml +++ b/ibc-core/ics24-host/cosmos/Cargo.toml @@ -110,3 +110,11 @@ parity-scale-codec = [ "ibc-primitives/parity-scale-codec", "ibc-proto/parity-scale-codec", ] +arbitrary = [ + "ibc-core-client-types/arbitrary", + "ibc-core-connection-types/arbitrary", + "ibc-core-commitment-types/arbitrary", + "ibc-core-host-types/arbitrary", + "ibc-core-handler-types/arbitrary", + "ibc-primitives/arbitrary", +] diff --git a/ibc-core/ics25-handler/Cargo.toml b/ibc-core/ics25-handler/Cargo.toml index e064522cfb..f296f1c4dc 100644 --- a/ibc-core/ics25-handler/Cargo.toml +++ b/ibc-core/ics25-handler/Cargo.toml @@ -84,6 +84,7 @@ parity-scale-codec = [ arbitrary = [ "ibc-core-client/arbitrary", "ibc-core-connection/arbitrary", + "ibc-core-channel/arbitrary", "ibc-core-commitment-types/arbitrary", "ibc-core-host/arbitrary", "ibc-core-handler-types/arbitrary", From bffa6c081074ebf2b22491359dd81733414e5638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 16 Jan 2025 11:10:36 +0000 Subject: [PATCH 09/10] add one more missing transitive arbitrary feature --- ibc/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/ibc/Cargo.toml b/ibc/Cargo.toml index 3d84005489..1a1eb6f567 100644 --- a/ibc/Cargo.toml +++ b/ibc/Cargo.toml @@ -70,5 +70,6 @@ parity-scale-codec = [ arbitrary = [ "ibc-apps/arbitrary", "ibc-core/arbitrary", + "ibc-core-host-cosmos/arbitrary", "ibc-primitives/arbitrary", ] From 7f330300e1424b1a7ac21df91744062e864f1667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 16 Jan 2025 11:51:38 +0000 Subject: [PATCH 10/10] ci: try to force install cargo-msrv --- .github/workflows/rust.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index a7cf8c9e27..71293dbedc 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -125,7 +125,7 @@ jobs: - name: Install cargo-msrv env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: cargo binstall --no-confirm cargo-msrv + run: cargo binstall --no-confirm cargo-msrv --force - name: Verify and Test Rust version run: |