From dc8e4161dd5e00a2031cf3feb58dad1ed7e26bdb Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 5 Sep 2023 07:24:07 -0700 Subject: [PATCH] imp: organize imports using `rustfmt.toml` (#849) * imp: organize imports using rustfmt.toml * fix: use nightly toolchain for fmt * fix: add fmt component * nix: add reorder_imports --- .../improvements/848-configure-cargo-fmt.md | 2 + .github/workflows/rust.yml | 3 +- crates/ibc-derive/src/client_state.rs | 8 +-- .../traits/client_state_common.rs | 8 +-- .../traits/client_state_execution.rs | 14 ++--- .../traits/client_state_validation.rs | 14 ++--- crates/ibc-derive/src/consensus_state.rs | 3 +- .../ibc/src/applications/transfer/amount.rs | 13 +++-- crates/ibc/src/applications/transfer/coin.rs | 1 + .../ibc/src/applications/transfer/context.rs | 12 ++-- crates/ibc/src/applications/transfer/denom.rs | 1 - crates/ibc/src/applications/transfer/error.rs | 1 + .../ibc/src/applications/transfer/events.rs | 3 +- crates/ibc/src/applications/transfer/memo.rs | 4 +- .../applications/transfer/msgs/transfer.rs | 7 +-- .../ibc/src/applications/transfer/packet.rs | 8 +-- crates/ibc/src/applications/transfer/relay.rs | 3 +- .../clients/ics07_tendermint/client_state.rs | 38 ++++++------ .../client_state/misbehaviour.rs | 6 +- .../client_state/update_client.rs | 6 +- .../ics07_tendermint/consensus_state.rs | 10 ++-- .../src/clients/ics07_tendermint/context.rs | 16 ++--- .../ibc/src/clients/ics07_tendermint/error.rs | 11 ++-- .../src/clients/ics07_tendermint/header.rs | 8 +-- .../clients/ics07_tendermint/misbehaviour.rs | 3 +- .../ibc/src/clients/ics07_tendermint/mod.rs | 3 +- .../ics07_tendermint/trust_threshold.rs | 6 +- crates/ibc/src/core/context.rs | 21 +++---- crates/ibc/src/core/events.rs | 28 ++++----- crates/ibc/src/core/handler.rs | 58 ++++++++++--------- .../ibc/src/core/ics02_client/client_type.rs | 13 ++--- .../src/core/ics02_client/consensus_state.rs | 9 ++- crates/ibc/src/core/ics02_client/context.rs | 3 +- crates/ibc/src/core/ics02_client/error.rs | 6 +- crates/ibc/src/core/ics02_client/events.rs | 13 +++-- .../ics02_client/handler/create_client.rs | 15 ++--- .../ics02_client/handler/update_client.rs | 21 +++---- .../ics02_client/handler/upgrade_client.rs | 14 ++--- crates/ibc/src/core/ics02_client/height.rs | 6 +- .../core/ics02_client/msgs/create_client.rs | 6 +- .../core/ics02_client/msgs/misbehaviour.rs | 3 +- .../core/ics02_client/msgs/update_client.rs | 11 ++-- .../core/ics02_client/msgs/upgrade_client.rs | 14 ++--- .../src/core/ics03_connection/connection.rs | 11 ++-- crates/ibc/src/core/ics03_connection/delay.rs | 7 ++- crates/ibc/src/core/ics03_connection/error.rs | 9 +-- .../ibc/src/core/ics03_connection/events.rs | 8 ++- .../ibc/src/core/ics03_connection/handler.rs | 6 +- .../ics03_connection/handler/conn_open_ack.rs | 15 +++-- .../handler/conn_open_confirm.rs | 10 ++-- .../handler/conn_open_init.rs | 11 ++-- .../ics03_connection/handler/conn_open_try.rs | 12 ++-- crates/ibc/src/core/ics03_connection/msgs.rs | 5 +- .../ics03_connection/msgs/conn_open_ack.rs | 20 +++---- .../msgs/conn_open_confirm.rs | 19 +++--- .../ics03_connection/msgs/conn_open_init.rs | 22 +++---- .../ics03_connection/msgs/conn_open_try.rs | 34 +++++------ .../ibc/src/core/ics03_connection/version.rs | 11 ++-- .../src/core/ics04_channel/acknowledgement.rs | 4 +- crates/ibc/src/core/ics04_channel/channel.rs | 22 +++---- .../ibc/src/core/ics04_channel/commitment.rs | 3 +- crates/ibc/src/core/ics04_channel/context.rs | 20 +++---- crates/ibc/src/core/ics04_channel/error.rs | 4 +- crates/ibc/src/core/ics04_channel/events.rs | 15 +++-- .../events/channel_attributes.rs | 6 +- .../ics04_channel/events/packet_attributes.rs | 4 +- .../ics04_channel/handler/acknowledgement.rs | 37 +++++------- .../handler/chan_close_confirm.rs | 24 +++----- .../ics04_channel/handler/chan_close_init.rs | 18 +++--- .../ics04_channel/handler/chan_open_ack.rs | 28 ++++----- .../handler/chan_open_confirm.rs | 30 +++++----- .../ics04_channel/handler/chan_open_init.rs | 21 +++---- .../ics04_channel/handler/chan_open_try.rs | 27 ++++----- .../core/ics04_channel/handler/recv_packet.rs | 33 +++++------ .../core/ics04_channel/handler/send_packet.rs | 36 +++++------- .../src/core/ics04_channel/handler/timeout.rs | 40 +++++-------- .../ics04_channel/handler/timeout_on_close.rs | 32 +++++----- crates/ibc/src/core/ics04_channel/msgs.rs | 12 ++-- .../ics04_channel/msgs/acknowledgement.rs | 14 ++--- .../ics04_channel/msgs/chan_close_confirm.rs | 14 ++--- .../ics04_channel/msgs/chan_close_init.rs | 14 ++--- .../core/ics04_channel/msgs/chan_open_ack.rs | 18 +++--- .../ics04_channel/msgs/chan_open_confirm.rs | 18 +++--- .../core/ics04_channel/msgs/chan_open_init.rs | 21 ++++--- .../core/ics04_channel/msgs/chan_open_try.rs | 28 ++++----- .../core/ics04_channel/msgs/recv_packet.rs | 17 +++--- .../src/core/ics04_channel/msgs/timeout.rs | 12 ++-- .../ics04_channel/msgs/timeout_on_close.rs | 5 +- crates/ibc/src/core/ics04_channel/packet.rs | 14 ++--- crates/ibc/src/core/ics04_channel/timeout.rs | 6 +- crates/ibc/src/core/ics04_channel/version.rs | 3 +- .../src/core/ics23_commitment/commitment.rs | 12 ++-- crates/ibc/src/core/ics23_commitment/error.rs | 1 + .../ibc/src/core/ics23_commitment/merkle.rs | 7 +-- crates/ibc/src/core/ics23_commitment/specs.rs | 3 +- crates/ibc/src/core/ics24_host/identifier.rs | 4 +- .../core/ics24_host/identifier/validate.rs | 7 +-- crates/ibc/src/core/ics24_host/path.rs | 11 ++-- crates/ibc/src/core/mod.rs | 10 +--- crates/ibc/src/core/msgs.rs | 5 +- crates/ibc/src/core/router.rs | 5 +- crates/ibc/src/core/timestamp.rs | 8 +-- .../tendermint/upgrade_proposal/events.rs | 1 + .../tendermint/upgrade_proposal/handler.rs | 7 ++- .../hosts/tendermint/upgrade_proposal/plan.rs | 1 + .../tendermint/upgrade_proposal/proposal.rs | 1 + .../hosts/tendermint/validate_self_client.rs | 7 +-- crates/ibc/src/lib.rs | 3 +- crates/ibc/src/mock/client_state.rs | 22 +++---- crates/ibc/src/mock/consensus_state.rs | 6 +- crates/ibc/src/mock/context.rs | 42 ++++++-------- crates/ibc/src/mock/context/clients.rs | 16 +++-- crates/ibc/src/mock/header.rs | 3 +- crates/ibc/src/mock/host.rs | 4 +- crates/ibc/src/mock/ics18_relayer/context.rs | 9 ++- crates/ibc/src/mock/ics18_relayer/error.rs | 3 +- crates/ibc/src/mock/misbehaviour.rs | 3 +- crates/ibc/src/mock/router.rs | 6 +- crates/ibc/src/prelude.rs | 7 +-- crates/ibc/src/signer.rs | 4 +- crates/ibc/src/test.rs | 4 +- crates/ibc/src/test_utils.rs | 3 +- crates/ibc/src/utils/pretty.rs | 3 +- rustfmt.toml | 5 ++ 124 files changed, 658 insertions(+), 828 deletions(-) create mode 100644 .changelog/unreleased/improvements/848-configure-cargo-fmt.md create mode 100644 rustfmt.toml diff --git a/.changelog/unreleased/improvements/848-configure-cargo-fmt.md b/.changelog/unreleased/improvements/848-configure-cargo-fmt.md new file mode 100644 index 000000000..51ad15851 --- /dev/null +++ b/.changelog/unreleased/improvements/848-configure-cargo-fmt.md @@ -0,0 +1,2 @@ +- Organize imports grouping and granularity using `rustfmt.toml` + ([#848](https://github.com/cosmos/ibc-rs/issues/848)) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 740d384c1..4671367c2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -37,7 +37,8 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: nightly # Since fmt uses unstable features for organizing imports + components: rustfmt override: true - uses: actions-rs/cargo@v1 with: diff --git a/crates/ibc-derive/src/client_state.rs b/crates/ibc-derive/src/client_state.rs index a6bb0e83c..46917ce2e 100644 --- a/crates/ibc-derive/src/client_state.rs +++ b/crates/ibc-derive/src/client_state.rs @@ -4,11 +4,9 @@ use darling::FromDeriveInput; use proc_macro2::TokenStream; use quote::quote; use syn::DeriveInput; - -use traits::{ - client_state_common::impl_ClientStateCommon, client_state_execution::impl_ClientStateExecution, - client_state_validation::impl_ClientStateValidation, -}; +use traits::client_state_common::impl_ClientStateCommon; +use traits::client_state_execution::impl_ClientStateExecution; +use traits::client_state_validation::impl_ClientStateValidation; #[derive(FromDeriveInput)] #[darling(attributes(generics))] diff --git a/crates/ibc-derive/src/client_state/traits/client_state_common.rs b/crates/ibc-derive/src/client_state/traits/client_state_common.rs index b1dc37731..8176743e3 100644 --- a/crates/ibc-derive/src/client_state/traits/client_state_common.rs +++ b/crates/ibc-derive/src/client_state/traits/client_state_common.rs @@ -1,10 +1,8 @@ use proc_macro2::{Ident, TokenStream}; use quote::quote; -use syn::{ - punctuated::{Iter, Punctuated}, - token::Comma, - Variant, -}; +use syn::punctuated::{Iter, Punctuated}; +use syn::token::Comma; +use syn::Variant; use crate::utils::{get_enum_variant_type_path, Imports}; diff --git a/crates/ibc-derive/src/client_state/traits/client_state_execution.rs b/crates/ibc-derive/src/client_state/traits/client_state_execution.rs index 7b6903122..1a92c8f79 100644 --- a/crates/ibc-derive/src/client_state/traits/client_state_execution.rs +++ b/crates/ibc-derive/src/client_state/traits/client_state_execution.rs @@ -1,15 +1,11 @@ use proc_macro2::{Ident, TokenStream}; use quote::quote; -use syn::{ - punctuated::{Iter, Punctuated}, - token::Comma, - Variant, -}; +use syn::punctuated::{Iter, Punctuated}; +use syn::token::Comma; +use syn::Variant; -use crate::{ - client_state::Opts, - utils::{get_enum_variant_type_path, Imports}, -}; +use crate::client_state::Opts; +use crate::utils::{get_enum_variant_type_path, Imports}; pub(crate) fn impl_ClientStateExecution( client_state_enum_name: &Ident, diff --git a/crates/ibc-derive/src/client_state/traits/client_state_validation.rs b/crates/ibc-derive/src/client_state/traits/client_state_validation.rs index 38c8ba397..a0c920bd3 100644 --- a/crates/ibc-derive/src/client_state/traits/client_state_validation.rs +++ b/crates/ibc-derive/src/client_state/traits/client_state_validation.rs @@ -1,15 +1,11 @@ use proc_macro2::{Ident, TokenStream}; use quote::quote; -use syn::{ - punctuated::{Iter, Punctuated}, - token::Comma, - Variant, -}; +use syn::punctuated::{Iter, Punctuated}; +use syn::token::Comma; +use syn::Variant; -use crate::{ - client_state::Opts, - utils::{get_enum_variant_type_path, Imports}, -}; +use crate::client_state::Opts; +use crate::utils::{get_enum_variant_type_path, Imports}; pub(crate) fn impl_ClientStateValidation( client_state_enum_name: &Ident, diff --git a/crates/ibc-derive/src/consensus_state.rs b/crates/ibc-derive/src/consensus_state.rs index 3a00ea2de..99feb69ce 100644 --- a/crates/ibc-derive/src/consensus_state.rs +++ b/crates/ibc-derive/src/consensus_state.rs @@ -1,6 +1,7 @@ use proc_macro2::TokenStream; use quote::quote; -use syn::{punctuated::Iter, DeriveInput, Ident, Variant}; +use syn::punctuated::Iter; +use syn::{DeriveInput, Ident, Variant}; use crate::utils::{get_enum_variant_type_path, Imports}; diff --git a/crates/ibc/src/applications/transfer/amount.rs b/crates/ibc/src/applications/transfer/amount.rs index 9cee50d29..fe21574fa 100644 --- a/crates/ibc/src/applications/transfer/amount.rs +++ b/crates/ibc/src/applications/transfer/amount.rs @@ -1,14 +1,17 @@ //! Contains the `Amount` type, which represents amounts of tokens transferred. -use crate::prelude::*; -use core::{ops::Deref, str::FromStr}; -use derive_more::{Display, From, Into}; +use core::ops::Deref; +use core::str::FromStr; -use super::error::TokenTransferError; +use derive_more::{Display, From, Into}; use primitive_types::U256; +use super::error::TokenTransferError; +#[cfg(feature = "schema")] +use crate::alloc::borrow::ToOwned; #[cfg(feature = "schema")] -use crate::alloc::{borrow::ToOwned, string::String}; +use crate::alloc::string::String; +use crate::prelude::*; /// A type for representing token transfer amounts. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/ibc/src/applications/transfer/coin.rs b/crates/ibc/src/applications/transfer/coin.rs index 7fd429640..406e01b43 100644 --- a/crates/ibc/src/applications/transfer/coin.rs +++ b/crates/ibc/src/applications/transfer/coin.rs @@ -2,6 +2,7 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::{from_utf8, FromStr}; + use ibc_proto::cosmos::base::v1beta1::Coin as ProtoCoin; use safe_regex::regex; diff --git a/crates/ibc/src/applications/transfer/context.rs b/crates/ibc/src/applications/transfer/context.rs index 6b3b25880..81b4030af 100644 --- a/crates/ibc/src/applications/transfer/context.rs +++ b/crates/ibc/src/applications/transfer/context.rs @@ -1,25 +1,23 @@ //! Defines the main context traits and IBC module callbacks -use crate::prelude::*; - use sha2::{Digest, Sha256}; use super::ack_success_b64; use super::error::TokenTransferError; use crate::applications::transfer::events::{AckEvent, AckStatusEvent, RecvEvent, TimeoutEvent}; use crate::applications::transfer::packet::PacketData; -use crate::applications::transfer::relay::refund_packet_token_execute; +use crate::applications::transfer::relay::on_recv_packet::process_recv_packet_execute; use crate::applications::transfer::relay::{ - on_recv_packet::process_recv_packet_execute, refund_packet_token_validate, + refund_packet_token_execute, refund_packet_token_validate, }; use crate::applications::transfer::{PrefixedCoin, PrefixedDenom, VERSION}; -use crate::core::ics04_channel::acknowledgement::Acknowledgement; -use crate::core::ics04_channel::acknowledgement::AcknowledgementStatus; +use crate::core::ics04_channel::acknowledgement::{Acknowledgement, AcknowledgementStatus}; use crate::core::ics04_channel::channel::{Counterparty, Order}; use crate::core::ics04_channel::packet::Packet; use crate::core::ics04_channel::Version; use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; use crate::core::router::ModuleExtras; use crate::core::ContextError; +use crate::prelude::*; use crate::signer::Signer; /// Methods required in token transfer validation, to be implemented by the host @@ -414,9 +412,9 @@ pub fn on_timeout_packet_execute( #[cfg(test)] pub(crate) mod test { - use super::*; use subtle_encoding::bech32; + use super::*; use crate::applications::transfer::context::cosmos_adr028_escrow_address; use crate::core::ics04_channel::channel::{Counterparty, Order}; use crate::core::ics04_channel::Version; diff --git a/crates/ibc/src/applications/transfer/denom.rs b/crates/ibc/src/applications/transfer/denom.rs index 77ab685ee..73d46745d 100644 --- a/crates/ibc/src/applications/transfer/denom.rs +++ b/crates/ibc/src/applications/transfer/denom.rs @@ -9,7 +9,6 @@ use ibc_proto::ibc::applications::transfer::v1::DenomTrace as RawDenomTrace; use super::error::TokenTransferError; use crate::core::ics24_host::identifier::{ChannelId, PortId}; use crate::prelude::*; - #[cfg(feature = "serde")] use crate::serializers::serde_string; diff --git a/crates/ibc/src/applications/transfer/error.rs b/crates/ibc/src/applications/transfer/error.rs index 479820bc7..0c25654ce 100644 --- a/crates/ibc/src/applications/transfer/error.rs +++ b/crates/ibc/src/applications/transfer/error.rs @@ -2,6 +2,7 @@ use core::convert::Infallible; use core::str::Utf8Error; + use displaydoc::Display; use ibc_proto::protobuf::Error as TendermintProtoError; use uint::FromDecStrErr; diff --git a/crates/ibc/src/applications/transfer/events.rs b/crates/ibc/src/applications/transfer/events.rs index 23476f3d2..45eff108a 100644 --- a/crates/ibc/src/applications/transfer/events.rs +++ b/crates/ibc/src/applications/transfer/events.rs @@ -1,13 +1,12 @@ //! Defines all token transfer event types +use super::Memo; use crate::applications::transfer::{Amount, PrefixedDenom, MODULE_ID_STR}; use crate::core::events::ModuleEvent; use crate::core::ics04_channel::acknowledgement::AcknowledgementStatus; use crate::prelude::*; use crate::signer::Signer; -use super::Memo; - const EVENT_TYPE_PACKET: &str = "fungible_token_packet"; const EVENT_TYPE_TIMEOUT: &str = "timeout"; const EVENT_TYPE_DENOM_TRACE: &str = "denomination_trace"; diff --git a/crates/ibc/src/applications/transfer/memo.rs b/crates/ibc/src/applications/transfer/memo.rs index 04bc75584..3d31f206e 100644 --- a/crates/ibc/src/applications/transfer/memo.rs +++ b/crates/ibc/src/applications/transfer/memo.rs @@ -2,7 +2,9 @@ //! with a token transfer use core::convert::Infallible; -use core::fmt::{self, Display}; +use core::fmt::{ + Display, {self}, +}; use core::str::FromStr; use crate::prelude::*; diff --git a/crates/ibc/src/applications/transfer/msgs/transfer.rs b/crates/ibc/src/applications/transfer/msgs/transfer.rs index a5d9024c5..f3ef9172e 100644 --- a/crates/ibc/src/applications/transfer/msgs/transfer.rs +++ b/crates/ibc/src/applications/transfer/msgs/transfer.rs @@ -1,7 +1,5 @@ //! Defines the token transfer message type -use crate::prelude::*; - use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::applications::transfer::v1::MsgTransfer as RawMsgTransfer; use ibc_proto::protobuf::Protobuf; @@ -13,6 +11,7 @@ use crate::core::ics04_channel::timeout::TimeoutHeight; use crate::core::ics24_host::identifier::{ChannelId, PortId}; use crate::core::timestamp::Timestamp; use crate::core::{ContextError, Msg}; +use crate::prelude::*; pub(crate) const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer"; @@ -127,12 +126,10 @@ impl TryFrom for MsgTransfer { #[cfg(test)] pub mod test_util { - use super::*; - use core::ops::Add; use core::time::Duration; - use super::MsgTransfer; + use super::{MsgTransfer, *}; use crate::applications::transfer::packet::PacketData; use crate::core::ics04_channel::packet::{Packet, Sequence}; use crate::core::ics04_channel::timeout::TimeoutHeight; diff --git a/crates/ibc/src/applications/transfer/packet.rs b/crates/ibc/src/applications/transfer/packet.rs index fdcede335..758af8439 100644 --- a/crates/ibc/src/applications/transfer/packet.rs +++ b/crates/ibc/src/applications/transfer/packet.rs @@ -4,13 +4,12 @@ use alloc::string::ToString; use core::convert::TryFrom; use core::str::FromStr; -#[cfg(feature = "schema")] -use crate::alloc::borrow::ToOwned; - use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketData as RawPacketData; use super::error::TokenTransferError; use super::{Amount, Memo, PrefixedCoin, PrefixedDenom}; +#[cfg(feature = "schema")] +use crate::alloc::borrow::ToOwned; use crate::signer::Signer; /// Defines the structure of token transfers' packet bytes @@ -67,10 +66,11 @@ impl From for RawPacketData { #[cfg(test)] mod tests { + use primitive_types::U256; + use super::*; use crate::applications::transfer::BaseCoin; use crate::test_utils::get_dummy_bech32_account; - use primitive_types::U256; impl PacketData { pub fn new_dummy() -> Self { diff --git a/crates/ibc/src/applications/transfer/relay.rs b/crates/ibc/src/applications/transfer/relay.rs index 2d2fce7d1..227ac8243 100644 --- a/crates/ibc/src/applications/transfer/relay.rs +++ b/crates/ibc/src/applications/transfer/relay.rs @@ -1,13 +1,12 @@ //! Implements the processing logic for ICS20 (token transfer) message. +use super::context::{TokenTransferExecutionContext, TokenTransferValidationContext}; use crate::applications::transfer::error::TokenTransferError; use crate::applications::transfer::is_sender_chain_source; use crate::applications::transfer::packet::PacketData; use crate::core::ics04_channel::packet::Packet; use crate::prelude::*; -use super::context::{TokenTransferExecutionContext, TokenTransferValidationContext}; - pub mod on_recv_packet; pub mod send_transfer; diff --git a/crates/ibc/src/clients/ics07_tendermint/client_state.rs b/crates/ibc/src/clients/ics07_tendermint/client_state.rs index 3e60b86b8..f9709e38d 100644 --- a/crates/ibc/src/clients/ics07_tendermint/client_state.rs +++ b/crates/ibc/src/clients/ics07_tendermint/client_state.rs @@ -4,8 +4,6 @@ mod misbehaviour; mod update_client; -use crate::prelude::*; - use core::cmp::max; use core::convert::{TryFrom, TryInto}; use core::str::FromStr; @@ -17,12 +15,16 @@ use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof; use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState; use ibc_proto::protobuf::Protobuf; use prost::Message; - use tendermint::chain::id::MAX_LENGTH as MaxChainIdLen; use tendermint::trust_threshold::TrustThresholdFraction as TendermintTrustThresholdFraction; use tendermint_light_client_verifier::options::Options; use tendermint_light_client_verifier::ProdVerifier; +use super::trust_threshold::TrustThreshold; +use super::{ + client_type as tm_client_type, ExecutionContext as TmExecutionContext, + ValidationContext as TmValidationContext, +}; use crate::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; use crate::clients::ics07_tendermint::error::Error; use crate::clients::ics07_tendermint::header::Header as TmHeader; @@ -40,17 +42,13 @@ use crate::core::ics23_commitment::commitment::{ use crate::core::ics23_commitment::merkle::{apply_prefix, MerkleProof}; use crate::core::ics23_commitment::specs::ProofSpecs; use crate::core::ics24_host::identifier::{ChainId, ClientId}; -use crate::core::ics24_host::path::Path; -use crate::core::ics24_host::path::{ClientConsensusStatePath, ClientStatePath, UpgradeClientPath}; +use crate::core::ics24_host::path::{ + ClientConsensusStatePath, ClientStatePath, Path, UpgradeClientPath, +}; use crate::core::timestamp::ZERO_DURATION; +use crate::prelude::*; use crate::Height; -use super::trust_threshold::TrustThreshold; -use super::{ - client_type as tm_client_type, ExecutionContext as TmExecutionContext, - ValidationContext as TmValidationContext, -}; - pub const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState"; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -735,9 +733,10 @@ impl TryFrom for ClientState { type Error = ClientError; fn try_from(raw: Any) -> Result { - use bytes::Buf; use core::ops::Deref; + use bytes::Buf; + fn decode_client_state(buf: B) -> Result { RawTmClientState::decode(buf) .map_err(Error::Decode)? @@ -783,22 +782,21 @@ fn check_header_trusted_next_validator_set( #[cfg(test)] mod tests { - use super::*; - - use crate::clients::ics07_tendermint::header::test_util::get_dummy_tendermint_header; - use crate::Height; use core::time::Duration; - use test_log::test; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::Height as RawHeight; use ibc_proto::ics23::ProofSpec as Ics23ProofSpec; + use test_log::test; + use super::*; use crate::clients::ics07_tendermint::client_state::AllowUpdate; use crate::clients::ics07_tendermint::error::Error; + use crate::clients::ics07_tendermint::header::test_util::get_dummy_tendermint_header; use crate::core::ics23_commitment::specs::ProofSpecs; use crate::core::ics24_host::identifier::ChainId; use crate::core::timestamp::ZERO_DURATION; + use crate::Height; #[derive(Clone, Debug, PartialEq)] struct ClientStateParams { @@ -1120,10 +1118,11 @@ mod serde_tests { #[cfg(any(test, feature = "mocks"))] pub mod test_util { - use crate::prelude::*; use core::str::FromStr; use core::time::Duration; + use ibc_proto::ibc::core::client::v1::Height as RawHeight; + use ibc_proto::ibc::lightclients::tendermint::v1::{ClientState as RawTmClientState, Fraction}; use tendermint::block::Header; use crate::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState}; @@ -1131,8 +1130,7 @@ pub mod test_util { use crate::core::ics02_client::height::Height; use crate::core::ics23_commitment::specs::ProofSpecs; use crate::core::ics24_host::identifier::ChainId; - use ibc_proto::ibc::core::client::v1::Height as RawHeight; - use ibc_proto::ibc::lightclients::tendermint::v1::{ClientState as RawTmClientState, Fraction}; + use crate::prelude::*; impl ClientState { pub fn new_dummy_from_raw(frozen_height: RawHeight) -> Result { diff --git a/crates/ibc/src/clients/ics07_tendermint/client_state/misbehaviour.rs b/crates/ibc/src/clients/ics07_tendermint/client_state/misbehaviour.rs index 5dc2aa02e..9e3c3141a 100644 --- a/crates/ibc/src/clients/ics07_tendermint/client_state/misbehaviour.rs +++ b/crates/ibc/src/clients/ics07_tendermint/client_state/misbehaviour.rs @@ -1,7 +1,6 @@ use tendermint_light_client_verifier::Verifier; -use crate::prelude::*; - +use super::{check_header_trusted_next_validator_set, ClientState}; use crate::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; use crate::clients::ics07_tendermint::error::{Error, IntoResult}; use crate::clients::ics07_tendermint::header::Header as TmHeader; @@ -12,8 +11,7 @@ use crate::core::ics02_client::error::ClientError; use crate::core::ics24_host::identifier::ClientId; use crate::core::ics24_host::path::ClientConsensusStatePath; use crate::core::timestamp::Timestamp; - -use super::{check_header_trusted_next_validator_set, ClientState}; +use crate::prelude::*; impl ClientState { // verify_misbehaviour determines whether or not two conflicting headers at diff --git a/crates/ibc/src/clients/ics07_tendermint/client_state/update_client.rs b/crates/ibc/src/clients/ics07_tendermint/client_state/update_client.rs index 86050de97..34c10e464 100644 --- a/crates/ibc/src/clients/ics07_tendermint/client_state/update_client.rs +++ b/crates/ibc/src/clients/ics07_tendermint/client_state/update_client.rs @@ -1,8 +1,7 @@ -use crate::prelude::*; - use tendermint_light_client_verifier::types::{TrustedBlockState, UntrustedBlockState}; use tendermint_light_client_verifier::Verifier; +use super::{check_header_trusted_next_validator_set, ClientState}; use crate::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; use crate::clients::ics07_tendermint::error::{Error, IntoResult}; use crate::clients::ics07_tendermint::header::Header as TmHeader; @@ -10,8 +9,7 @@ use crate::clients::ics07_tendermint::ValidationContext as TmValidationContext; use crate::core::ics02_client::error::ClientError; use crate::core::ics24_host::identifier::ClientId; use crate::core::ics24_host::path::ClientConsensusStatePath; - -use super::{check_header_trusted_next_validator_set, ClientState}; +use crate::prelude::*; impl ClientState { pub fn verify_header( diff --git a/crates/ibc/src/clients/ics07_tendermint/consensus_state.rs b/crates/ibc/src/clients/ics07_tendermint/consensus_state.rs index b5b7f476e..39c654364 100644 --- a/crates/ibc/src/clients/ics07_tendermint/consensus_state.rs +++ b/crates/ibc/src/clients/ics07_tendermint/consensus_state.rs @@ -1,11 +1,11 @@ //! Defines Tendermint's `ConsensusState` type -use crate::prelude::*; - use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState; use ibc_proto::protobuf::Protobuf; -use tendermint::{hash::Algorithm, time::Time, Hash}; +use tendermint::hash::Algorithm; +use tendermint::time::Time; +use tendermint::Hash; use tendermint_proto::google::protobuf as tpb; use crate::clients::ics07_tendermint::error::Error; @@ -14,6 +14,7 @@ use crate::core::ics02_client::consensus_state::ConsensusState as ConsensusState use crate::core::ics02_client::error::ClientError; use crate::core::ics23_commitment::commitment::CommitmentRoot; use crate::core::timestamp::Timestamp; +use crate::prelude::*; pub const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ConsensusState"; @@ -99,8 +100,9 @@ impl TryFrom for ConsensusState { type Error = ClientError; fn try_from(raw: Any) -> Result { - use bytes::Buf; use core::ops::Deref; + + use bytes::Buf; use prost::Message; fn decode_consensus_state(buf: B) -> Result { diff --git a/crates/ibc/src/clients/ics07_tendermint/context.rs b/crates/ibc/src/clients/ics07_tendermint/context.rs index 3c3674389..b62cc1680 100644 --- a/crates/ibc/src/clients/ics07_tendermint/context.rs +++ b/crates/ibc/src/clients/ics07_tendermint/context.rs @@ -1,16 +1,12 @@ use alloc::string::ToString; -use crate::{ - core::{ - ics02_client::ClientExecutionContext, - ics24_host::{identifier::ClientId, path::ClientConsensusStatePath}, - timestamp::Timestamp, - ContextError, - }, - Height, -}; - use super::consensus_state::ConsensusState as TmConsensusState; +use crate::core::ics02_client::ClientExecutionContext; +use crate::core::ics24_host::identifier::ClientId; +use crate::core::ics24_host::path::ClientConsensusStatePath; +use crate::core::timestamp::Timestamp; +use crate::core::ContextError; +use crate::Height; /// Client's context required during both validation and execution pub trait CommonContext { diff --git a/crates/ibc/src/clients/ics07_tendermint/error.rs b/crates/ibc/src/clients/ics07_tendermint/error.rs index f89878f91..135cb1948 100644 --- a/crates/ibc/src/clients/ics07_tendermint/error.rs +++ b/crates/ibc/src/clients/ics07_tendermint/error.rs @@ -1,11 +1,5 @@ //! Defines the Tendermint light client's error type -use crate::prelude::*; - -use crate::core::ics02_client::error::ClientError; -use crate::core::ics24_host::identifier::{ClientId, IdentifierError}; -use crate::Height; - use core::time::Duration; use displaydoc::Display; @@ -14,6 +8,11 @@ use tendermint_light_client_verifier::errors::VerificationErrorDetail as LightCl use tendermint_light_client_verifier::operations::VotingPowerTally; use tendermint_light_client_verifier::Verdict; +use crate::core::ics02_client::error::ClientError; +use crate::core::ics24_host::identifier::{ClientId, IdentifierError}; +use crate::prelude::*; +use crate::Height; + /// The main error type #[derive(Debug, Display)] pub enum Error { diff --git a/crates/ibc/src/clients/ics07_tendermint/header.rs b/crates/ibc/src/clients/ics07_tendermint/header.rs index d24cf409c..614f4dd5a 100644 --- a/crates/ibc/src/clients/ics07_tendermint/header.rs +++ b/crates/ibc/src/clients/ics07_tendermint/header.rs @@ -1,6 +1,5 @@ //! Defines the domain type for tendermint headers -use crate::prelude::*; use alloc::string::ToString; use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; @@ -9,6 +8,7 @@ use bytes::Buf; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader; use ibc_proto::protobuf::Protobuf; +use pretty::{PrettySignedHeader, PrettyValidatorSet}; use prost::Message; use tendermint::block::signed_header::SignedHeader; use tendermint::chain::Id as TmChainId; @@ -20,10 +20,9 @@ use crate::clients::ics07_tendermint::error::Error; use crate::core::ics02_client::error::ClientError; use crate::core::ics24_host::identifier::ChainId; use crate::core::timestamp::Timestamp; +use crate::prelude::*; use crate::Height; -use pretty::{PrettySignedHeader, PrettyValidatorSet}; - pub(crate) const TENDERMINT_HEADER_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.Header"; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -263,8 +262,7 @@ pub mod test_util { use subtle_encoding::hex; use tendermint::block::signed_header::SignedHeader; - use tendermint::validator::Info as ValidatorInfo; - use tendermint::validator::Set as ValidatorSet; + use tendermint::validator::{Info as ValidatorInfo, Set as ValidatorSet}; use tendermint::PublicKey; use crate::clients::ics07_tendermint::header::Header; diff --git a/crates/ibc/src/clients/ics07_tendermint/misbehaviour.rs b/crates/ibc/src/clients/ics07_tendermint/misbehaviour.rs index d81a47621..646eb6781 100644 --- a/crates/ibc/src/clients/ics07_tendermint/misbehaviour.rs +++ b/crates/ibc/src/clients/ics07_tendermint/misbehaviour.rs @@ -1,7 +1,5 @@ //! Defines the misbehaviour type for the tendermint light client -use crate::prelude::*; - use bytes::Buf; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour; @@ -12,6 +10,7 @@ use crate::clients::ics07_tendermint::error::Error; use crate::clients::ics07_tendermint::header::Header; use crate::core::ics02_client::error::ClientError; use crate::core::ics24_host::identifier::ClientId; +use crate::prelude::*; const TENDERMINT_MISBEHAVIOUR_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.Misbehaviour"; diff --git a/crates/ibc/src/clients/ics07_tendermint/mod.rs b/crates/ibc/src/clients/ics07_tendermint/mod.rs index 2bb58ec4b..803e7814e 100644 --- a/crates/ibc/src/clients/ics07_tendermint/mod.rs +++ b/crates/ibc/src/clients/ics07_tendermint/mod.rs @@ -1,9 +1,10 @@ //! ICS 07: Tendermint Client implements a client verification algorithm for blockchains which use //! the Tendermint consensus algorithm. -use crate::core::ics02_client::client_type::ClientType; use core::str::FromStr; +use crate::core::ics02_client::client_type::ClientType; + pub mod client_state; pub mod consensus_state; pub mod error; diff --git a/crates/ibc/src/clients/ics07_tendermint/trust_threshold.rs b/crates/ibc/src/clients/ics07_tendermint/trust_threshold.rs index 2ae58f3d6..d4e4e9c86 100644 --- a/crates/ibc/src/clients/ics07_tendermint/trust_threshold.rs +++ b/crates/ibc/src/clients/ics07_tendermint/trust_threshold.rs @@ -2,10 +2,8 @@ //! represented as a fraction with valid values in the //! range `[0, 1)`. -use core::{ - convert::TryFrom, - fmt::{Display, Error as FmtError, Formatter}, -}; +use core::convert::TryFrom; +use core::fmt::{Display, Error as FmtError, Formatter}; use ibc_proto::ibc::lightclients::tendermint::v1::Fraction; use ibc_proto::protobuf::Protobuf; diff --git a/crates/ibc/src/core/context.rs b/crates/ibc/src/core/context.rs index b74437af1..9d9ae5e77 100644 --- a/crates/ibc/src/core/context.rs +++ b/crates/ibc/src/core/context.rs @@ -1,12 +1,14 @@ -use crate::prelude::*; - -use crate::signer::Signer; use alloc::string::String; use core::time::Duration; + use derive_more::From; use displaydoc::Display; use ibc_proto::google::protobuf::Any; +use super::ics02_client::client_state::ClientState; +use super::ics02_client::consensus_state::ConsensusState; +use super::ics02_client::ClientExecutionContext; +use super::ics24_host::identifier::PortId; use crate::core::events::IbcEvent; use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::connection::ConnectionEnd; @@ -17,24 +19,19 @@ use crate::core::ics03_connection::version::{ use crate::core::ics04_channel::channel::ChannelEnd; use crate::core::ics04_channel::commitment::{AcknowledgementCommitment, PacketCommitment}; use crate::core::ics04_channel::context::calculate_block_delay; -use crate::core::ics04_channel::error::ChannelError; -use crate::core::ics04_channel::error::PacketError; +use crate::core::ics04_channel::error::{ChannelError, PacketError}; use crate::core::ics04_channel::packet::{Receipt, Sequence}; use crate::core::ics23_commitment::commitment::CommitmentPrefix; -use crate::core::ics24_host::identifier::ClientId; -use crate::core::ics24_host::identifier::ConnectionId; +use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; use crate::core::ics24_host::path::{ AckPath, ChannelEndPath, ClientConnectionPath, ClientConsensusStatePath, CommitmentPath, ConnectionPath, ReceiptPath, SeqAckPath, SeqRecvPath, SeqSendPath, }; use crate::core::timestamp::Timestamp; +use crate::prelude::*; +use crate::signer::Signer; use crate::Height; -use super::ics02_client::client_state::ClientState; -use super::ics02_client::consensus_state::ConsensusState; -use super::ics02_client::ClientExecutionContext; -use super::ics24_host::identifier::PortId; - /// Top-level error #[derive(Debug, Display, From)] pub enum ContextError { diff --git a/crates/ibc/src/core/events.rs b/crates/ibc/src/core/events.rs index 0d8d654a9..6b451c960 100644 --- a/crates/ibc/src/core/events.rs +++ b/crates/ibc/src/core/events.rs @@ -1,20 +1,17 @@ //! Events emitted during message handling -use crate::prelude::*; - use core::convert::{TryFrom, TryInto}; + use displaydoc::Display; use tendermint::abci; +use super::ics24_host::identifier::IdentifierError; use crate::core::ics02_client::error as client_error; use crate::core::ics02_client::events::{self as ClientEvents}; -use crate::core::ics03_connection::error as connection_error; -use crate::core::ics03_connection::events as ConnectionEvents; -use crate::core::ics04_channel::error as channel_error; -use crate::core::ics04_channel::events as ChannelEvents; +use crate::core::ics03_connection::{error as connection_error, events as ConnectionEvents}; +use crate::core::ics04_channel::{error as channel_error, events as ChannelEvents}; use crate::core::timestamp::ParseTimestampError; - -use super::ics24_host::identifier::IdentifierError; +use crate::prelude::*; /// All error variants related to IBC events #[derive(Debug, Display)] @@ -284,17 +281,14 @@ impl From for IbcEvent { #[cfg(test)] pub mod tests { - use super::*; use alloc::vec; - use crate::core::{ - ics04_channel::{ - channel::Order, - events::SendPacket, - packet::{test_utils::get_dummy_raw_packet, Packet}, - }, - ics24_host::identifier::ConnectionId, - }; + use super::*; + use crate::core::ics04_channel::channel::Order; + use crate::core::ics04_channel::events::SendPacket; + use crate::core::ics04_channel::packet::test_utils::get_dummy_raw_packet; + use crate::core::ics04_channel::packet::Packet; + use crate::core::ics24_host::identifier::ConnectionId; #[test] /// Ensures that we don't panic when packet data is not valid UTF-8. diff --git a/crates/ibc/src/core/handler.rs b/crates/ibc/src/core/handler.rs index faa3216a6..5ddebcf97 100644 --- a/crates/ibc/src/core/handler.rs +++ b/crates/ibc/src/core/handler.rs @@ -202,51 +202,53 @@ where #[cfg(test)] mod tests { - use super::*; - use core::default::Default; use core::time::Duration; use test_log::test; + use super::*; use crate::applications::transfer::error::TokenTransferError; - use crate::applications::transfer::send_transfer; - use crate::applications::transfer::{msgs::transfer::MsgTransfer, MODULE_ID_STR}; + use crate::applications::transfer::msgs::transfer::MsgTransfer; + use crate::applications::transfer::{send_transfer, MODULE_ID_STR}; use crate::core::dispatch; use crate::core::events::{IbcEvent, MessageEvent}; - use crate::core::ics02_client::msgs::{ - create_client::MsgCreateClient, update_client::MsgUpdateClient, - upgrade_client::MsgUpgradeClient, ClientMsg, - }; + use crate::core::ics02_client::msgs::create_client::MsgCreateClient; + use crate::core::ics02_client::msgs::update_client::MsgUpdateClient; + use crate::core::ics02_client::msgs::upgrade_client::MsgUpgradeClient; + use crate::core::ics02_client::msgs::ClientMsg; use crate::core::ics03_connection::connection::{ ConnectionEnd, Counterparty as ConnCounterparty, State as ConnState, }; - use crate::core::ics03_connection::msgs::{ - conn_open_ack::MsgConnectionOpenAck, conn_open_init::MsgConnectionOpenInit, - conn_open_try::MsgConnectionOpenTry, ConnectionMsg, - }; + use crate::core::ics03_connection::msgs::conn_open_ack::MsgConnectionOpenAck; + use crate::core::ics03_connection::msgs::conn_open_init::MsgConnectionOpenInit; + use crate::core::ics03_connection::msgs::conn_open_try::MsgConnectionOpenTry; + use crate::core::ics03_connection::msgs::ConnectionMsg; use crate::core::ics03_connection::version::Version as ConnVersion; - use crate::core::ics04_channel::channel::ChannelEnd; - use crate::core::ics04_channel::channel::Counterparty as ChannelCounterparty; - use crate::core::ics04_channel::channel::Order as ChannelOrder; - use crate::core::ics04_channel::channel::State as ChannelState; + use crate::core::ics04_channel::channel::{ + ChannelEnd, Counterparty as ChannelCounterparty, Order as ChannelOrder, + State as ChannelState, + }; use crate::core::ics04_channel::error::ChannelError; use crate::core::ics04_channel::msgs::acknowledgement::test_util::get_dummy_raw_msg_ack_with_packet; use crate::core::ics04_channel::msgs::acknowledgement::MsgAcknowledgement; + use crate::core::ics04_channel::msgs::chan_close_confirm::test_util::get_dummy_raw_msg_chan_close_confirm; + use crate::core::ics04_channel::msgs::chan_close_confirm::MsgChannelCloseConfirm; + use crate::core::ics04_channel::msgs::chan_close_init::test_util::get_dummy_raw_msg_chan_close_init; + use crate::core::ics04_channel::msgs::chan_close_init::MsgChannelCloseInit; + use crate::core::ics04_channel::msgs::chan_open_ack::test_util::get_dummy_raw_msg_chan_open_ack; + use crate::core::ics04_channel::msgs::chan_open_ack::MsgChannelOpenAck; use crate::core::ics04_channel::msgs::chan_open_confirm::test_util::get_dummy_raw_msg_chan_open_confirm; use crate::core::ics04_channel::msgs::chan_open_confirm::MsgChannelOpenConfirm; - use crate::core::ics04_channel::msgs::{ - chan_close_confirm::{ - test_util::get_dummy_raw_msg_chan_close_confirm, MsgChannelCloseConfirm, - }, - chan_close_init::{test_util::get_dummy_raw_msg_chan_close_init, MsgChannelCloseInit}, - chan_open_ack::{test_util::get_dummy_raw_msg_chan_open_ack, MsgChannelOpenAck}, - chan_open_init::{test_util::get_dummy_raw_msg_chan_open_init, MsgChannelOpenInit}, - chan_open_try::{test_util::get_dummy_raw_msg_chan_open_try, MsgChannelOpenTry}, - recv_packet::{test_util::get_dummy_raw_msg_recv_packet, MsgRecvPacket}, - timeout_on_close::{test_util::get_dummy_raw_msg_timeout_on_close, MsgTimeoutOnClose}, - ChannelMsg, PacketMsg, - }; + use crate::core::ics04_channel::msgs::chan_open_init::test_util::get_dummy_raw_msg_chan_open_init; + use crate::core::ics04_channel::msgs::chan_open_init::MsgChannelOpenInit; + use crate::core::ics04_channel::msgs::chan_open_try::test_util::get_dummy_raw_msg_chan_open_try; + use crate::core::ics04_channel::msgs::chan_open_try::MsgChannelOpenTry; + use crate::core::ics04_channel::msgs::recv_packet::test_util::get_dummy_raw_msg_recv_packet; + use crate::core::ics04_channel::msgs::recv_packet::MsgRecvPacket; + use crate::core::ics04_channel::msgs::timeout_on_close::test_util::get_dummy_raw_msg_timeout_on_close; + use crate::core::ics04_channel::msgs::timeout_on_close::MsgTimeoutOnClose; + use crate::core::ics04_channel::msgs::{ChannelMsg, PacketMsg}; use crate::core::ics04_channel::timeout::TimeoutHeight; use crate::core::ics04_channel::Version as ChannelVersion; use crate::core::ics23_commitment::commitment::CommitmentPrefix; diff --git a/crates/ibc/src/core/ics02_client/client_type.rs b/crates/ibc/src/core/ics02_client/client_type.rs index d842e84b3..b223fbdae 100644 --- a/crates/ibc/src/core/ics02_client/client_type.rs +++ b/crates/ibc/src/core/ics02_client/client_type.rs @@ -1,14 +1,11 @@ //! Defines the `ClientType` format, typically used in chain IDs. +use core::fmt::{Display, Error as FmtError, Formatter}; +use core::str::FromStr; + +use crate::core::ics24_host::identifier::validate::validate_client_type; +use crate::core::ics24_host::identifier::IdentifierError; use crate::prelude::*; -use core::{ - fmt::{Display, Error as FmtError, Formatter}, - str::FromStr, -}; - -use crate::core::ics24_host::{ - identifier::validate::validate_client_type, identifier::IdentifierError, -}; #[cfg_attr( feature = "parity-scale-codec", diff --git a/crates/ibc/src/core/ics02_client/consensus_state.rs b/crates/ibc/src/core/ics02_client/consensus_state.rs index 377272b0d..17a4ebbec 100644 --- a/crates/ibc/src/core/ics02_client/consensus_state.rs +++ b/crates/ibc/src/core/ics02_client/consensus_state.rs @@ -1,16 +1,15 @@ //! Defines the trait to be implemented by all concrete consensus state types -use crate::prelude::*; - use core::marker::{Send, Sync}; -use crate::core::ics23_commitment::commitment::CommitmentRoot; -use crate::core::timestamp::Timestamp; - /// Derive macro that implements [`ConsensusState`] for enums containing /// variants that implement [`ConsensusState`] pub use ibc_derive::ConsensusState; +use crate::core::ics23_commitment::commitment::CommitmentRoot; +use crate::core::timestamp::Timestamp; +use crate::prelude::*; + /// Defines methods that all `ConsensusState`s should provide. /// /// One can think of a "consensus state" as a pruned header, to be stored on chain. In other words, diff --git a/crates/ibc/src/core/ics02_client/context.rs b/crates/ibc/src/core/ics02_client/context.rs index 4423d4690..f07c51e9e 100644 --- a/crates/ibc/src/core/ics02_client/context.rs +++ b/crates/ibc/src/core/ics02_client/context.rs @@ -1,7 +1,6 @@ use super::client_state::ClientState; use super::consensus_state::ConsensusState; -use crate::core::ics24_host::path::ClientConsensusStatePath; -use crate::core::ics24_host::path::ClientStatePath; +use crate::core::ics24_host::path::{ClientConsensusStatePath, ClientStatePath}; use crate::core::ContextError; /// Defines the methods that all client `ExecutionContext`s (precisely the diff --git a/crates/ibc/src/core/ics02_client/error.rs b/crates/ibc/src/core/ics02_client/error.rs index 826341c34..c055863cf 100644 --- a/crates/ibc/src/core/ics02_client/error.rs +++ b/crates/ibc/src/core/ics02_client/error.rs @@ -1,19 +1,17 @@ //! Defines the client error type -use crate::prelude::*; - use displaydoc::Display; use ibc_proto::protobuf::Error as TendermintProtoError; +use super::client_state::Status; use crate::core::ics02_client::client_type::ClientType; use crate::core::ics23_commitment::error::CommitmentError; use crate::core::ics24_host::identifier::{ClientId, IdentifierError}; use crate::core::timestamp::Timestamp; use crate::core::ContextError; +use crate::prelude::*; use crate::Height; -use super::client_state::Status; - /// Encodes all the possible client errors #[derive(Debug, Display)] pub enum ClientError { diff --git a/crates/ibc/src/core/ics02_client/events.rs b/crates/ibc/src/core/ics02_client/events.rs index 01e4c586a..8b9f027cb 100644 --- a/crates/ibc/src/core/ics02_client/events.rs +++ b/crates/ibc/src/core/ics02_client/events.rs @@ -1,6 +1,4 @@ //! Types for the IBC events emitted from Tendermint Websocket by the client module. -use crate::prelude::*; - use derive_more::From; use subtle_encoding::hex; use tendermint::abci; @@ -8,6 +6,7 @@ use tendermint::abci; use crate::core::ics02_client::client_type::ClientType; use crate::core::ics02_client::height::Height; use crate::core::ics24_host::identifier::ClientId; +use crate::prelude::*; /// Client event types const CREATE_CLIENT_EVENT: &str = "create_client"; @@ -421,14 +420,16 @@ impl From for abci::Event { #[cfg(test)] mod tests { - use super::*; - use crate::core::timestamp::Timestamp; - use crate::mock::header::MockHeader; + use std::str::FromStr; + use ibc_proto::google::protobuf::Any; use prost::Message; - use std::str::FromStr; use tendermint::abci::Event as AbciEvent; + use super::*; + use crate::core::timestamp::Timestamp; + use crate::mock::header::MockHeader; + #[test] fn ibc_to_abci_client_events() { struct Test { diff --git a/crates/ibc/src/core/ics02_client/handler/create_client.rs b/crates/ibc/src/core/ics02_client/handler/create_client.rs index e3ee280ab..ff770a22b 100644 --- a/crates/ibc/src/core/ics02_client/handler/create_client.rs +++ b/crates/ibc/src/core/ics02_client/handler/create_client.rs @@ -1,18 +1,14 @@ //! Protocol logic specific to processing ICS2 messages of type `MsgCreateClient`. -use crate::prelude::*; - use crate::core::context::ContextError; -use crate::core::events::IbcEvent; -use crate::core::events::MessageEvent; -use crate::core::ics02_client::client_state::ClientStateCommon; -use crate::core::ics02_client::client_state::ClientStateExecution; +use crate::core::events::{IbcEvent, MessageEvent}; +use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateExecution}; use crate::core::ics02_client::error::ClientError; use crate::core::ics02_client::events::CreateClient; use crate::core::ics02_client::msgs::create_client::MsgCreateClient; use crate::core::ics24_host::identifier::ClientId; -use crate::core::ExecutionContext; -use crate::core::ValidationContext; +use crate::core::{ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn validate(ctx: &Ctx, msg: MsgCreateClient) -> Result<(), ContextError> where @@ -104,10 +100,9 @@ where #[cfg(test)] mod tests { - use super::*; - use test_log::test; + use super::*; use crate::clients::ics07_tendermint::client_state::ClientState as TmClientState; use crate::clients::ics07_tendermint::client_type as tm_client_type; use crate::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; diff --git a/crates/ibc/src/core/ics02_client/handler/update_client.rs b/crates/ibc/src/core/ics02_client/handler/update_client.rs index d0e2e0712..1aa200b1e 100644 --- a/crates/ibc/src/core/ics02_client/handler/update_client.rs +++ b/crates/ibc/src/core/ics02_client/handler/update_client.rs @@ -1,18 +1,17 @@ //! Protocol logic specific to processing ICS2 messages of type `MsgUpdateAnyClient`. -use crate::prelude::*; use prost::Message; use crate::core::context::ContextError; use crate::core::events::{IbcEvent, MessageEvent}; -use crate::core::ics02_client::client_state::ClientStateCommon; -use crate::core::ics02_client::client_state::ClientStateExecution; -use crate::core::ics02_client::client_state::ClientStateValidation; -use crate::core::ics02_client::client_state::UpdateKind; +use crate::core::ics02_client::client_state::{ + ClientStateCommon, ClientStateExecution, ClientStateValidation, UpdateKind, +}; use crate::core::ics02_client::error::ClientError; use crate::core::ics02_client::events::{ClientMisbehaviour, UpdateClient}; use crate::core::ics02_client::msgs::MsgUpdateOrMisbehaviour; use crate::core::{ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn validate(ctx: &Ctx, msg: MsgUpdateOrMisbehaviour) -> Result<(), ContextError> where @@ -133,13 +132,14 @@ where #[cfg(test)] mod tests { - use super::*; - use core::str::FromStr; use core::time::Duration; + use ibc_proto::google::protobuf::Any; + use ibc_proto::ibc::lightclients::tendermint::v1::{ClientState as RawTmClientState, Fraction}; use test_log::test; + use super::*; use crate::clients::ics07_tendermint::client_state::ClientState as TmClientState; use crate::clients::ics07_tendermint::client_type as tm_client_type; use crate::clients::ics07_tendermint::header::Header as TmHeader; @@ -152,16 +152,13 @@ mod tests { use crate::core::ics23_commitment::specs::ProofSpecs; use crate::core::ics24_host::identifier::{ChainId, ClientId}; use crate::core::timestamp::Timestamp; - use crate::downcast; - use crate::mock::client_state::client_type as mock_client_type; - use crate::mock::client_state::MockClientState; + use crate::mock::client_state::{client_type as mock_client_type, MockClientState}; use crate::mock::context::{AnyConsensusState, MockContext}; use crate::mock::header::MockHeader; use crate::mock::host::{HostBlock, HostType}; use crate::mock::misbehaviour::Misbehaviour as MockMisbehaviour; use crate::test_utils::get_dummy_account_id; - use crate::Height; - use ibc_proto::ibc::lightclients::tendermint::v1::{ClientState as RawTmClientState, Fraction}; + use crate::{downcast, Height}; #[test] fn test_update_client_ok() { diff --git a/crates/ibc/src/core/ics02_client/handler/upgrade_client.rs b/crates/ibc/src/core/ics02_client/handler/upgrade_client.rs index 3980d5b77..5e43dc008 100644 --- a/crates/ibc/src/core/ics02_client/handler/upgrade_client.rs +++ b/crates/ibc/src/core/ics02_client/handler/upgrade_client.rs @@ -1,17 +1,17 @@ //! Protocol logic specific to processing ICS2 messages of type `MsgUpgradeAnyClient`. //! -use crate::prelude::*; - use crate::core::context::ContextError; use crate::core::events::{IbcEvent, MessageEvent}; -use crate::core::ics02_client::client_state::ClientStateExecution; -use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; +use crate::core::ics02_client::client_state::{ + ClientStateCommon, ClientStateExecution, ClientStateValidation, +}; use crate::core::ics02_client::consensus_state::ConsensusState; use crate::core::ics02_client::error::ClientError; use crate::core::ics02_client::events::UpgradeClient; use crate::core::ics02_client::msgs::upgrade_client::MsgUpgradeClient; use crate::core::ics24_host::path::ClientConsensusStatePath; use crate::core::{ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn validate(ctx: &Ctx, msg: MsgUpgradeClient) -> Result<(), ContextError> where @@ -85,19 +85,15 @@ where #[cfg(test)] mod tests { use super::*; - use crate::clients::ics07_tendermint::client_state::ClientState as TmClientState; use crate::clients::ics07_tendermint::client_type; use crate::clients::ics07_tendermint::header::test_util::get_dummy_tendermint_header; - use crate::core::ics02_client::error::UpgradeClientError; use crate::core::ics03_connection::handler::test_util::{Expect, Fixture}; use crate::core::ics24_host::identifier::ClientId; - use crate::downcast; - use crate::Height; - use crate::mock::client_state::client_type as mock_client_type; use crate::mock::context::{AnyClientState, AnyConsensusState, MockContext}; + use crate::{downcast, Height}; enum Ctx { Default, diff --git a/crates/ibc/src/core/ics02_client/height.rs b/crates/ibc/src/core/ics02_client/height.rs index 21297a49d..469337917 100644 --- a/crates/ibc/src/core/ics02_client/height.rs +++ b/crates/ibc/src/core/ics02_client/height.rs @@ -1,17 +1,15 @@ //! Defines the core `Height` type used throughout the library -use crate::prelude::*; use core::cmp::Ordering; - use core::num::ParseIntError; use core::str::FromStr; use displaydoc::Display; -use ibc_proto::protobuf::Protobuf; - use ibc_proto::ibc::core::client::v1::Height as RawHeight; +use ibc_proto::protobuf::Protobuf; use crate::core::ics02_client::error::ClientError; +use crate::prelude::*; /// The core IBC height type, which represents the height of a chain, /// which typically is the number of blocks since genesis diff --git a/crates/ibc/src/core/ics02_client/msgs/create_client.rs b/crates/ibc/src/core/ics02_client/msgs/create_client.rs index c55e8668c..93cbc126f 100644 --- a/crates/ibc/src/core/ics02_client/msgs/create_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/create_client.rs @@ -1,13 +1,12 @@ //! Definition of domain type message `MsgCreateClient`. -use crate::prelude::*; - use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::MsgCreateClient as RawMsgCreateClient; use ibc_proto::protobuf::Protobuf; use crate::core::ics02_client::error::ClientError; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgCreateClient"; @@ -75,9 +74,8 @@ impl From for RawMsgCreateClient { #[cfg(test)] mod tests { - use test_log::test; - use ibc_proto::ibc::core::client::v1::MsgCreateClient as RawMsgCreateClient; + use test_log::test; use crate::clients::ics07_tendermint::client_state::ClientState as TmClientState; use crate::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; diff --git a/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs b/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs index 6ab10266b..02fe61905 100644 --- a/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs +++ b/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs @@ -1,7 +1,5 @@ //! Definition of domain type message `MsgSubmitMisbehaviour`. -use crate::prelude::*; - use ibc_proto::google::protobuf::Any as ProtoAny; use ibc_proto::ibc::core::client::v1::MsgSubmitMisbehaviour as RawMsgSubmitMisbehaviour; use ibc_proto::protobuf::Protobuf; @@ -9,6 +7,7 @@ use ibc_proto::protobuf::Protobuf; use crate::core::ics02_client::error::ClientError; use crate::core::ics24_host::identifier::ClientId; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgSubmitMisbehaviour"; diff --git a/crates/ibc/src/core/ics02_client/msgs/update_client.rs b/crates/ibc/src/core/ics02_client/msgs/update_client.rs index 74e365a44..36ef02b36 100644 --- a/crates/ibc/src/core/ics02_client/msgs/update_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/update_client.rs @@ -1,14 +1,13 @@ //! Definition of domain type message `MsgUpdateClient`. -use crate::core::Msg; -use crate::prelude::*; - use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::MsgUpdateClient as RawMsgUpdateClient; use ibc_proto::protobuf::Protobuf; use crate::core::ics02_client::error::ClientError; use crate::core::ics24_host::identifier::ClientId; +use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgUpdateClient"; @@ -67,13 +66,11 @@ impl From for RawMsgUpdateClient { #[cfg(test)] mod tests { - use super::*; - - use test_log::test; - use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::MsgUpdateClient as RawMsgUpdateClient; + use test_log::test; + use super::*; use crate::clients::ics07_tendermint::header::test_util::get_dummy_ics07_header; use crate::core::ics02_client::msgs::MsgUpdateClient; use crate::core::ics24_host::identifier::ClientId; diff --git a/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs b/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs index f18160f89..55da7a238 100644 --- a/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs @@ -1,7 +1,5 @@ //! Definition of domain type msg `MsgUpgradeClient`. -use crate::prelude::*; - use core::str::FromStr; use ibc_proto::google::protobuf::Any; @@ -13,6 +11,7 @@ use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::ics23_commitment::error::CommitmentError; use crate::core::ics24_host::identifier::ClientId; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgUpgradeClient"; @@ -100,13 +99,12 @@ impl TryFrom for MsgUpgradeClient { #[cfg(test)] pub mod test_util { use super::*; - + use crate::core::ics02_client::height::Height; use crate::core::ics23_commitment::commitment::test_util::get_dummy_commitment_proof_bytes; - use crate::core::{ics02_client::height::Height, ics24_host::identifier::ClientId}; - use crate::mock::client_state::client_type as mock_client_type; - use crate::mock::{ - client_state::MockClientState, consensus_state::MockConsensusState, header::MockHeader, - }; + use crate::core::ics24_host::identifier::ClientId; + use crate::mock::client_state::{client_type as mock_client_type, MockClientState}; + use crate::mock::consensus_state::MockConsensusState; + use crate::mock::header::MockHeader; use crate::test_utils::{get_dummy_account_id, get_dummy_bech32_account, get_dummy_proof}; /// Extends the implementation with additional helper methods. diff --git a/crates/ibc/src/core/ics03_connection/connection.rs b/crates/ibc/src/core/ics03_connection/connection.rs index 6ab1513ec..bfb73b645 100644 --- a/crates/ibc/src/core/ics03_connection/connection.rs +++ b/crates/ibc/src/core/ics03_connection/connection.rs @@ -1,18 +1,14 @@ //! Defines the types that define a connection -use crate::prelude::*; -use ibc_proto::protobuf::Protobuf; - +use core::fmt::{Display, Error as FmtError, Formatter}; use core::time::Duration; -use core::{ - fmt::{Display, Error as FmtError, Formatter}, - u64, -}; +use core::u64; use ibc_proto::ibc::core::connection::v1::{ ConnectionEnd as RawConnectionEnd, Counterparty as RawCounterparty, IdentifiedConnection as RawIdentifiedConnection, }; +use ibc_proto::protobuf::Protobuf; use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::error::ConnectionError; @@ -20,6 +16,7 @@ use crate::core::ics03_connection::version::Version; use crate::core::ics23_commitment::commitment::CommitmentPrefix; use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; use crate::core::timestamp::ZERO_DURATION; +use crate::prelude::*; #[cfg_attr( feature = "parity-scale-codec", diff --git a/crates/ibc/src/core/ics03_connection/delay.rs b/crates/ibc/src/core/ics03_connection/delay.rs index 4536a6d2b..067a84282 100644 --- a/crates/ibc/src/core/ics03_connection/delay.rs +++ b/crates/ibc/src/core/ics03_connection/delay.rs @@ -1,6 +1,7 @@ -use crate::core::{ics02_client::height::Height, ContextError, ValidationContext}; - -use super::{connection::ConnectionEnd, error::ConnectionError}; +use super::connection::ConnectionEnd; +use super::error::ConnectionError; +use crate::core::ics02_client::height::Height; +use crate::core::{ContextError, ValidationContext}; pub fn verify_conn_delay_passed( ctx: &Ctx, diff --git a/crates/ibc/src/core/ics03_connection/error.rs b/crates/ibc/src/core/ics03_connection/error.rs index 28512f9dd..3364a274c 100644 --- a/crates/ibc/src/core/ics03_connection/error.rs +++ b/crates/ibc/src/core/ics03_connection/error.rs @@ -1,15 +1,16 @@ //! Defines the connection error type +use alloc::string::String; + +use displaydoc::Display; +use ibc_proto::protobuf::Error as ProtoError; + use crate::core::ics02_client::error as client_error; use crate::core::ics03_connection::version::Version; use crate::core::ics24_host::identifier::{ClientId, ConnectionId, IdentifierError}; use crate::core::timestamp::{Timestamp, TimestampOverflowError}; use crate::Height; -use alloc::string::String; -use displaydoc::Display; -use ibc_proto::protobuf::Error as ProtoError; - #[derive(Debug, Display)] pub enum ConnectionError { /// client error: `{0}` diff --git a/crates/ibc/src/core/ics03_connection/events.rs b/crates/ibc/src/core/ics03_connection/events.rs index ed8dcd2c9..dcc0f38f9 100644 --- a/crates/ibc/src/core/ics03_connection/events.rs +++ b/crates/ibc/src/core/ics03_connection/events.rs @@ -1,9 +1,9 @@ //! Types for the IBC events emitted from Tendermint Websocket by the connection module. -use crate::prelude::*; use tendermint::abci; use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; +use crate::prelude::*; /// Connection event types const CONNECTION_OPEN_INIT_EVENT: &str = "connection_open_init"; @@ -306,11 +306,13 @@ impl From for abci::Event { #[cfg(test)] mod tests { - use super::*; - use crate::core::ics02_client::client_type::ClientType; use std::str::FromStr; + use tendermint::abci::Event as AbciEvent; + use super::*; + use crate::core::ics02_client::client_type::ClientType; + #[test] fn ibc_to_abci_connection_events() { struct Test { diff --git a/crates/ibc/src/core/ics03_connection/handler.rs b/crates/ibc/src/core/ics03_connection/handler.rs index 8946943c6..a79a2d87b 100644 --- a/crates/ibc/src/core/ics03_connection/handler.rs +++ b/crates/ibc/src/core/ics03_connection/handler.rs @@ -8,10 +8,12 @@ pub mod conn_open_try; #[cfg(test)] pub mod test_util { + use alloc::format; use core::fmt::Debug; - use crate::{core::ContextError, mock::context::MockContext, prelude::String}; - use alloc::format; + use crate::core::ContextError; + use crate::mock::context::MockContext; + use crate::prelude::String; pub enum Expect { Success, diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs index 8ca94b4a1..1aee37d96 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs @@ -4,6 +4,7 @@ use ibc_proto::protobuf::Protobuf; use prost::Message; use crate::core::context::ContextError; +use crate::core::events::{IbcEvent, MessageEvent}; use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; use crate::core::ics02_client::error::ClientError; @@ -12,13 +13,12 @@ use crate::core::ics03_connection::error::ConnectionError; use crate::core::ics03_connection::events::OpenAck; use crate::core::ics03_connection::msgs::conn_open_ack::MsgConnectionOpenAck; use crate::core::ics24_host::identifier::ClientId; -use crate::core::ics24_host::path::Path; -use crate::core::ics24_host::path::{ClientConsensusStatePath, ClientStatePath, ConnectionPath}; +use crate::core::ics24_host::path::{ + ClientConsensusStatePath, ClientStatePath, ConnectionPath, Path, +}; use crate::core::{ExecutionContext, ValidationContext}; use crate::prelude::*; -use crate::core::events::{IbcEvent, MessageEvent}; - pub(crate) fn validate(ctx_a: &Ctx, msg: MsgConnectionOpenAck) -> Result<(), ContextError> where Ctx: ValidationContext, @@ -205,19 +205,18 @@ impl LocalVars { #[cfg(test)] mod tests { - use super::*; - use core::str::FromStr; + use test_log::test; + use super::*; + use crate::core::events::IbcEvent; use crate::core::ics02_client::height::Height; use crate::core::ics03_connection::connection::{ConnectionEnd, Counterparty, State}; use crate::core::ics03_connection::handler::test_util::{Expect, Fixture}; use crate::core::ics03_connection::msgs::conn_open_ack::MsgConnectionOpenAck; use crate::core::ics23_commitment::commitment::CommitmentPrefix; use crate::core::ics24_host::identifier::{ChainId, ClientId}; - - use crate::core::events::IbcEvent; use crate::core::timestamp::ZERO_DURATION; use crate::mock::context::MockContext; use crate::mock::host::HostType; diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_confirm.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_confirm.rs index 56a96b45b..e5c1251c6 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_confirm.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_confirm.rs @@ -3,6 +3,7 @@ use ibc_proto::protobuf::Protobuf; use crate::core::context::ContextError; +use crate::core::events::{IbcEvent, MessageEvent}; use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; use crate::core::ics02_client::error::ClientError; @@ -11,13 +12,10 @@ use crate::core::ics03_connection::error::ConnectionError; use crate::core::ics03_connection::events::OpenConfirm; use crate::core::ics03_connection::msgs::conn_open_confirm::MsgConnectionOpenConfirm; use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; -use crate::core::ics24_host::path::Path; -use crate::core::ics24_host::path::{ClientConsensusStatePath, ConnectionPath}; +use crate::core::ics24_host::path::{ClientConsensusStatePath, ConnectionPath, Path}; use crate::core::{ExecutionContext, ValidationContext}; use crate::prelude::*; -use crate::core::events::{IbcEvent, MessageEvent}; - pub(crate) fn validate(ctx_b: &Ctx, msg: &MsgConnectionOpenConfirm) -> Result<(), ContextError> where Ctx: ValidationContext, @@ -173,11 +171,11 @@ impl LocalVars { #[cfg(test)] mod tests { - use super::*; - use core::str::FromStr; + use test_log::test; + use super::*; use crate::core::events::IbcEvent; use crate::core::ics03_connection::connection::{ConnectionEnd, Counterparty, State}; use crate::core::ics03_connection::handler::test_util::{Expect, Fixture}; diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_init.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_init.rs index 1d7e11a5c..6ee7daedc 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_init.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_init.rs @@ -1,16 +1,15 @@ //! Protocol logic specific to ICS3 messages of type `MsgConnectionOpenInit`. -use crate::core::ics02_client::client_state::ClientStateValidation; -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; - use crate::core::context::ContextError; use crate::core::events::{IbcEvent, MessageEvent}; +use crate::core::ics02_client::client_state::ClientStateValidation; +use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::connection::{ConnectionEnd, Counterparty, State}; use crate::core::ics03_connection::events::OpenInit; use crate::core::ics03_connection::msgs::conn_open_init::MsgConnectionOpenInit; use crate::core::ics24_host::identifier::ConnectionId; use crate::core::ics24_host::path::{ClientConnectionPath, ConnectionPath}; use crate::core::{ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn validate(ctx_a: &Ctx, msg: MsgConnectionOpenInit) -> Result<(), ContextError> where @@ -90,8 +89,9 @@ where #[cfg(test)] mod tests { - use super::*; + use test_log::test; + use super::*; use crate::core::events::IbcEvent; use crate::core::ics03_connection::connection::State; use crate::core::ics03_connection::handler::test_util::{Expect, Fixture}; @@ -99,7 +99,6 @@ mod tests { use crate::core::ics03_connection::version::Version; use crate::mock::context::MockContext; use crate::Height; - use test_log::test; enum Ctx { Default, diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs index 090f3ede5..2cdd5da8c 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs @@ -4,6 +4,7 @@ use ibc_proto::protobuf::Protobuf; use prost::Message; use crate::core::context::ContextError; +use crate::core::events::{IbcEvent, MessageEvent}; use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; use crate::core::ics02_client::error::ClientError; @@ -11,17 +12,13 @@ use crate::core::ics03_connection::connection::{ConnectionEnd, Counterparty, Sta use crate::core::ics03_connection::error::ConnectionError; use crate::core::ics03_connection::events::OpenTry; use crate::core::ics03_connection::msgs::conn_open_try::MsgConnectionOpenTry; -use crate::core::ics24_host::identifier::ClientId; -use crate::core::ics24_host::identifier::ConnectionId; -use crate::core::ics24_host::path::Path; +use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; use crate::core::ics24_host::path::{ - ClientConnectionPath, ClientConsensusStatePath, ClientStatePath, ConnectionPath, + ClientConnectionPath, ClientConsensusStatePath, ClientStatePath, ConnectionPath, Path, }; use crate::core::{ExecutionContext, ValidationContext}; use crate::prelude::*; -use crate::core::events::{IbcEvent, MessageEvent}; - pub(crate) fn validate(ctx_b: &Ctx, msg: MsgConnectionOpenTry) -> Result<(), ContextError> where Ctx: ValidationContext, @@ -208,10 +205,9 @@ impl LocalVars { #[cfg(test)] mod tests { - use super::*; - use test_log::test; + use super::*; use crate::core::events::IbcEvent; use crate::core::ics03_connection::connection::State; use crate::core::ics03_connection::handler::test_util::{Expect, Fixture}; diff --git a/crates/ibc/src/core/ics03_connection/msgs.rs b/crates/ibc/src/core/ics03_connection/msgs.rs index 486ce3956..4adae4c9b 100644 --- a/crates/ibc/src/core/ics03_connection/msgs.rs +++ b/crates/ibc/src/core/ics03_connection/msgs.rs @@ -38,11 +38,12 @@ pub enum ConnectionMsg { #[cfg(test)] pub mod test_util { - use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; - use crate::prelude::*; use ibc_proto::ibc::core::commitment::v1::MerklePrefix; use ibc_proto::ibc::core::connection::v1::Counterparty as RawCounterparty; + use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; + use crate::prelude::*; + pub fn get_dummy_raw_counterparty(conn_id: Option) -> RawCounterparty { let connection_id = match conn_id { Some(id) => ConnectionId::new(id).to_string(), diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs index 5b57756f7..415cd3983 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs @@ -1,5 +1,3 @@ -use crate::prelude::*; - use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; use ibc_proto::protobuf::Protobuf; @@ -9,6 +7,7 @@ use crate::core::ics03_connection::version::Version; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::ics24_host::identifier::ConnectionId; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; use crate::Height; @@ -132,19 +131,18 @@ impl From for RawMsgConnectionOpenAck { #[cfg(test)] pub mod test_util { - use crate::core::ics02_client::height::Height; - use crate::mock::client_state::MockClientState; - use crate::mock::header::MockHeader; - use crate::prelude::*; use ibc_proto::ibc::core::client::v1::Height as RawHeight; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; + use super::MsgConnectionOpenAck; + use crate::core::ics02_client::height::Height; use crate::core::ics03_connection::version::Version; use crate::core::ics24_host::identifier::ConnectionId; + use crate::mock::client_state::MockClientState; + use crate::mock::header::MockHeader; + use crate::prelude::*; use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof}; - use super::MsgConnectionOpenAck; - /// Testing-specific helper methods. impl MsgConnectionOpenAck { /// Returns a new `MsgConnectionOpenAck` with dummy values. @@ -186,15 +184,13 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::prelude::*; - - use test_log::test; - use ibc_proto::ibc::core::client::v1::Height; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; + use test_log::test; use crate::core::ics03_connection::msgs::conn_open_ack::test_util::get_dummy_raw_msg_conn_open_ack; use crate::core::ics03_connection::msgs::conn_open_ack::MsgConnectionOpenAck; + use crate::prelude::*; #[test] fn parse_connection_open_ack_msg() { diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs index 4f0337a69..cb1528dc3 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs @@ -1,14 +1,13 @@ -use crate::core::ics23_commitment::commitment::CommitmentProofBytes; -use crate::{prelude::*, Height}; - -use ibc_proto::protobuf::Protobuf; - use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenConfirm as RawMsgConnectionOpenConfirm; +use ibc_proto::protobuf::Protobuf; use crate::core::ics03_connection::error::ConnectionError; +use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::ics24_host::identifier::ConnectionId; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; +use crate::Height; pub(crate) const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenConfirm"; @@ -74,11 +73,11 @@ impl From for RawMsgConnectionOpenConfirm { #[cfg(test)] pub mod test_util { - use super::MsgConnectionOpenConfirm; - use crate::prelude::*; use ibc_proto::ibc::core::client::v1::Height; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenConfirm as RawMsgConnectionOpenConfirm; + use super::MsgConnectionOpenConfirm; + use crate::prelude::*; use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof}; /// Testing-specific helper methods. @@ -104,15 +103,13 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::prelude::*; - - use test_log::test; - use ibc_proto::ibc::core::client::v1::Height; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenConfirm as RawMsgConnectionOpenConfirm; + use test_log::test; use crate::core::ics03_connection::msgs::conn_open_confirm::test_util::get_dummy_raw_msg_conn_open_confirm; use crate::core::ics03_connection::msgs::conn_open_confirm::MsgConnectionOpenConfirm; + use crate::prelude::*; #[test] fn parse_connection_open_confirm_msg() { diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs index d6732f258..322f28cc2 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs @@ -1,5 +1,3 @@ -use crate::prelude::*; - use core::time::Duration; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenInit as RawMsgConnectionOpenInit; @@ -10,6 +8,7 @@ use crate::core::ics03_connection::error::ConnectionError; use crate::core::ics03_connection::version::Version; use crate::core::ics24_host::identifier::ClientId; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; pub(crate) const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenInit"; @@ -38,10 +37,8 @@ impl Msg for MsgConnectionOpenInit { /// `BorshSerialize` and `BorshDeserialize` on `MsgConnectionOpenInit` #[cfg(feature = "borsh")] mod borsh_impls { - use borsh::{ - maybestd::io::{self, Read}, - BorshDeserialize, BorshSerialize, - }; + use borsh::maybestd::io::{self, Read}; + use borsh::{BorshDeserialize, BorshSerialize}; use super::*; @@ -132,16 +129,16 @@ impl From for RawMsgConnectionOpenInit { #[cfg(test)] pub mod test_util { - use crate::core::ics03_connection::connection::Counterparty; - use crate::prelude::*; use ibc_proto::ibc::core::connection::v1::{ MsgConnectionOpenInit as RawMsgConnectionOpenInit, Version as RawVersion, }; + use crate::core::ics03_connection::connection::Counterparty; use crate::core::ics03_connection::msgs::conn_open_init::MsgConnectionOpenInit; use crate::core::ics03_connection::msgs::test_util::get_dummy_raw_counterparty; use crate::core::ics03_connection::version::Version; use crate::core::ics24_host::identifier::ClientId; + use crate::prelude::*; use crate::test_utils::get_dummy_bech32_account; /// Extends the implementation with additional helper methods. @@ -199,16 +196,15 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::prelude::*; - + use ibc_proto::ibc::core::connection::v1::{ + Counterparty as RawCounterparty, MsgConnectionOpenInit as RawMsgConnectionOpenInit, + }; use test_log::test; - use ibc_proto::ibc::core::connection::v1::Counterparty as RawCounterparty; - use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenInit as RawMsgConnectionOpenInit; - use super::MsgConnectionOpenInit; use crate::core::ics03_connection::msgs::conn_open_init::test_util::get_dummy_raw_msg_conn_open_init; use crate::core::ics03_connection::msgs::test_util::get_dummy_raw_counterparty; + use crate::prelude::*; #[test] fn parse_connection_open_init_msg() { diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs index 11f7fb884..64269f075 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs @@ -1,9 +1,5 @@ -use crate::prelude::*; - -use core::{ - convert::{TryFrom, TryInto}, - time::Duration, -}; +use core::convert::{TryFrom, TryInto}; +use core::time::Duration; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenTry as RawMsgConnectionOpenTry; @@ -15,6 +11,7 @@ use crate::core::ics03_connection::version::Version; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::ics24_host::identifier::ClientId; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; use crate::Height; @@ -63,10 +60,8 @@ impl Msg for MsgConnectionOpenTry { #[allow(deprecated)] #[cfg(feature = "borsh")] mod borsh_impls { - use borsh::{ - maybestd::io::{self, Read}, - BorshDeserialize, BorshSerialize, - }; + use borsh::maybestd::io::{self, Read}; + use borsh::{BorshDeserialize, BorshSerialize}; use super::*; @@ -248,17 +243,17 @@ impl From for RawMsgConnectionOpenTry { #[cfg(test)] pub mod test_util { - use crate::core::ics02_client::height::Height; - use crate::mock::client_state::MockClientState; - use crate::mock::header::MockHeader; - use crate::prelude::*; use ibc_proto::ibc::core::client::v1::Height as RawHeight; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenTry as RawMsgConnectionOpenTry; + use crate::core::ics02_client::height::Height; use crate::core::ics03_connection::msgs::conn_open_try::MsgConnectionOpenTry; use crate::core::ics03_connection::msgs::test_util::get_dummy_raw_counterparty; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; + use crate::mock::client_state::MockClientState; + use crate::mock::header::MockHeader; + use crate::prelude::*; use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof}; /// Testing-specific helper methods. @@ -320,17 +315,16 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::prelude::*; - - use test_log::test; - use ibc_proto::ibc::core::client::v1::Height; - use ibc_proto::ibc::core::connection::v1::Counterparty as RawCounterparty; - use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenTry as RawMsgConnectionOpenTry; + use ibc_proto::ibc::core::connection::v1::{ + Counterparty as RawCounterparty, MsgConnectionOpenTry as RawMsgConnectionOpenTry, + }; + use test_log::test; use crate::core::ics03_connection::msgs::conn_open_try::test_util::get_dummy_raw_msg_conn_open_try; use crate::core::ics03_connection::msgs::conn_open_try::MsgConnectionOpenTry; use crate::core::ics03_connection::msgs::test_util::get_dummy_raw_counterparty; + use crate::prelude::*; #[test] fn parse_connection_open_try_msg() { diff --git a/crates/ibc/src/core/ics03_connection/version.rs b/crates/ibc/src/core/ics03_connection/version.rs index ba6fdb9a6..dcdb2b9f8 100644 --- a/crates/ibc/src/core/ics03_connection/version.rs +++ b/crates/ibc/src/core/ics03_connection/version.rs @@ -2,14 +2,13 @@ use core::fmt::Display; -use crate::prelude::*; -use crate::utils::pretty::PrettySlice; - use ibc_proto::ibc::core::connection::v1::Version as RawVersion; use ibc_proto::protobuf::Protobuf; use crate::core::ics03_connection::error::ConnectionError; use crate::core::ics04_channel::channel::Order; +use crate::prelude::*; +use crate::utils::pretty::PrettySlice; /// Stores the identifier and the features supported by a version #[cfg_attr( @@ -189,14 +188,12 @@ fn get_feature_set_intersection( #[cfg(test)] mod tests { - use crate::prelude::*; - - use test_log::test; - use ibc_proto::ibc::core::connection::v1::Version as RawVersion; + use test_log::test; use crate::core::ics03_connection::error::ConnectionError; use crate::core::ics03_connection::version::{get_compatible_versions, pick_version, Version}; + use crate::prelude::*; fn get_dummy_features() -> Vec { vec!["ORDER_RANDOM".to_string(), "ORDER_UNORDERED".to_string()] diff --git a/crates/ibc/src/core/ics04_channel/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/acknowledgement.rs index 3b3ebb844..4c5d08cd7 100644 --- a/crates/ibc/src/core/ics04_channel/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/acknowledgement.rs @@ -1,6 +1,7 @@ //! Defines acknowledgment types used by various IBC messages and applications. use core::fmt::{Display, Error as FmtError, Formatter}; + use derive_more::Into; use super::error::PacketError; @@ -142,7 +143,8 @@ impl From for Acknowledgement { #[cfg(test)] mod test { use super::*; - use crate::applications::transfer::{ack_success_b64, error::TokenTransferError}; + use crate::applications::transfer::ack_success_b64; + use crate::applications::transfer::error::TokenTransferError; #[test] fn test_ack_ser() { diff --git a/crates/ibc/src/core/ics04_channel/channel.rs b/crates/ibc/src/core/ics04_channel/channel.rs index 0c77c99be..7cfac5265 100644 --- a/crates/ibc/src/core/ics04_channel/channel.rs +++ b/crates/ibc/src/core/ics04_channel/channel.rs @@ -1,20 +1,19 @@ //! Implementation of IBC channels, as described in ICS 4. -use crate::prelude::*; -use crate::utils::pretty::PrettySlice; - use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; -use ibc_proto::protobuf::Protobuf; - use ibc_proto::ibc::core::channel::v1::{ Channel as RawChannel, Counterparty as RawCounterparty, IdentifiedChannel as RawIdentifiedChannel, }; +use ibc_proto::protobuf::Protobuf; -use crate::core::ics04_channel::{error::ChannelError, Version}; +use crate::core::ics04_channel::error::ChannelError; +use crate::core::ics04_channel::Version; use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; +use crate::prelude::*; +use crate::utils::pretty::PrettySlice; /// A [`ChannelEnd`] along with its ID and the port it is bound to #[cfg_attr( @@ -573,10 +572,12 @@ impl Display for State { #[cfg(test)] pub mod test_util { + use ibc_proto::ibc::core::channel::v1::{ + Channel as RawChannel, Counterparty as RawCounterparty, + }; + use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; use crate::prelude::*; - use ibc_proto::ibc::core::channel::v1::Channel as RawChannel; - use ibc_proto::ibc::core::channel::v1::Counterparty as RawCounterparty; /// Returns a dummy `RawCounterparty`, for testing only! /// Can be optionally parametrized with a specific channel identifier. @@ -605,15 +606,14 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::prelude::*; - use core::str::FromStr; - use test_log::test; use ibc_proto::ibc::core::channel::v1::Channel as RawChannel; + use test_log::test; use crate::core::ics04_channel::channel::test_util::get_dummy_raw_channel_end; use crate::core::ics04_channel::channel::ChannelEnd; + use crate::prelude::*; #[test] fn channel_end_try_from_raw() { diff --git a/crates/ibc/src/core/ics04_channel/commitment.rs b/crates/ibc/src/core/ics04_channel/commitment.rs index f389673e6..c2979e910 100644 --- a/crates/ibc/src/core/ics04_channel/commitment.rs +++ b/crates/ibc/src/core/ics04_channel/commitment.rs @@ -1,11 +1,10 @@ //! Types and utilities related to packet commitments. +use super::acknowledgement::Acknowledgement; use crate::core::ics04_channel::timeout::TimeoutHeight; use crate::core::timestamp::Timestamp; use crate::prelude::*; -use super::acknowledgement::Acknowledgement; - /// Packet commitment #[cfg_attr( feature = "parity-scale-codec", diff --git a/crates/ibc/src/core/ics04_channel/context.rs b/crates/ibc/src/core/ics04_channel/context.rs index 3e24e1729..aa7794a2e 100644 --- a/crates/ibc/src/core/ics04_channel/context.rs +++ b/crates/ibc/src/core/ics04_channel/context.rs @@ -1,23 +1,23 @@ //! ICS4 (channel) context. -use crate::core::events::IbcEvent; -use crate::core::ics02_client::client_state::ClientState; -use crate::core::ics02_client::ClientExecutionContext; -use crate::core::ics24_host::path::{ - ChannelEndPath, ClientConsensusStatePath, CommitmentPath, SeqSendPath, -}; -use crate::core::{ContextError, ExecutionContext, ValidationContext}; -use crate::prelude::*; use core::time::Duration; + use num_traits::float::FloatCore; +use super::packet::Sequence; +use crate::core::events::IbcEvent; +use crate::core::ics02_client::client_state::ClientState; use crate::core::ics02_client::consensus_state::ConsensusState; +use crate::core::ics02_client::ClientExecutionContext; use crate::core::ics03_connection::connection::ConnectionEnd; use crate::core::ics04_channel::channel::ChannelEnd; use crate::core::ics04_channel::commitment::PacketCommitment; use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; - -use super::packet::Sequence; +use crate::core::ics24_host::path::{ + ChannelEndPath, ClientConsensusStatePath, CommitmentPath, SeqSendPath, +}; +use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; /// Methods required in send packet validation, to be implemented by the host pub trait SendPacketValidationContext { diff --git a/crates/ibc/src/core/ics04_channel/error.rs b/crates/ibc/src/core/ics04_channel/error.rs index d8a98a2a7..669a54e2f 100644 --- a/crates/ibc/src/core/ics04_channel/error.rs +++ b/crates/ibc/src/core/ics04_channel/error.rs @@ -1,5 +1,7 @@ //! Defines the main channel, port and packet error types +use displaydoc::Display; + use super::channel::Counterparty; use super::packet::Sequence; use super::timeout::TimeoutHeight; @@ -14,8 +16,6 @@ use crate::core::timestamp::{ParseTimestampError, Timestamp}; use crate::prelude::*; use crate::Height; -use displaydoc::Display; - #[derive(Debug, Display)] pub enum ChannelError { /// invalid channel end: `{channel_end}` diff --git a/crates/ibc/src/core/ics04_channel/events.rs b/crates/ibc/src/core/ics04_channel/events.rs index 86b360734..58baab970 100644 --- a/crates/ibc/src/core/ics04_channel/events.rs +++ b/crates/ibc/src/core/ics04_channel/events.rs @@ -5,12 +5,6 @@ mod packet_attributes; use tendermint::abci; -use crate::core::ics04_channel::error::ChannelError; -use crate::core::ics04_channel::packet::Packet; -use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; -use crate::core::timestamp::Timestamp; -use crate::prelude::*; - use self::channel_attributes::{ ChannelIdAttribute, ConnectionIdAttribute, CounterpartyChannelIdAttribute, CounterpartyPortIdAttribute, PortIdAttribute, VersionAttribute, @@ -21,12 +15,16 @@ use self::packet_attributes::{ PacketConnectionIdAttribute, PacketDataAttribute, SequenceAttribute, SrcChannelIdAttribute, SrcPortIdAttribute, TimeoutHeightAttribute, TimeoutTimestampAttribute, }; - use super::acknowledgement::Acknowledgement; use super::channel::Order; use super::packet::Sequence; use super::timeout::TimeoutHeight; use super::Version; +use crate::core::ics04_channel::error::ChannelError; +use crate::core::ics04_channel::packet::Packet; +use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; +use crate::core::timestamp::Timestamp; +use crate::prelude::*; /// Channel event types const CHANNEL_OPEN_INIT_EVENT: &str = "channel_open_init"; @@ -1121,9 +1119,10 @@ impl TryFrom for abci::Event { #[cfg(test)] mod tests { - use super::*; use tendermint::abci::Event as AbciEvent; + use super::*; + #[test] fn ibc_to_abci_channel_events() { struct Test { diff --git a/crates/ibc/src/core/ics04_channel/events/channel_attributes.rs b/crates/ibc/src/core/ics04_channel/events/channel_attributes.rs index dad056755..d802a50b0 100644 --- a/crates/ibc/src/core/ics04_channel/events/channel_attributes.rs +++ b/crates/ibc/src/core/ics04_channel/events/channel_attributes.rs @@ -3,10 +3,8 @@ use derive_more::From; use tendermint::abci; -use crate::core::{ - ics04_channel::Version, - ics24_host::identifier::{ChannelId, ConnectionId, PortId}, -}; +use crate::core::ics04_channel::Version; +use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; const CONNECTION_ID_ATTRIBUTE_KEY: &str = "connection_id"; const CHANNEL_ID_ATTRIBUTE_KEY: &str = "channel_id"; diff --git a/crates/ibc/src/core/ics04_channel/events/packet_attributes.rs b/crates/ibc/src/core/ics04_channel/events/packet_attributes.rs index 8e53ebfdc..58d820635 100644 --- a/crates/ibc/src/core/ics04_channel/events/packet_attributes.rs +++ b/crates/ibc/src/core/ics04_channel/events/packet_attributes.rs @@ -2,12 +2,11 @@ //! during packet-related datagrams. //! use core::str; + use derive_more::From; use subtle_encoding::hex; use tendermint::abci; -use crate::prelude::*; - use crate::core::ics04_channel::acknowledgement::Acknowledgement; use crate::core::ics04_channel::channel::Order; use crate::core::ics04_channel::error::ChannelError; @@ -15,6 +14,7 @@ use crate::core::ics04_channel::packet::Sequence; use crate::core::ics04_channel::timeout::TimeoutHeight; use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; use crate::core::timestamp::Timestamp; +use crate::prelude::*; const PKT_SEQ_ATTRIBUTE_KEY: &str = "packet_sequence"; const PKT_DATA_ATTRIBUTE_KEY: &str = "packet_data"; diff --git a/crates/ibc/src/core/ics04_channel/handler/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/handler/acknowledgement.rs index 64d7b31f4..65c14fd40 100644 --- a/crates/ibc/src/core/ics04_channel/handler/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/handler/acknowledgement.rs @@ -1,23 +1,20 @@ -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; - -use crate::core::events::MessageEvent; +use crate::core::events::{IbcEvent, MessageEvent}; use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; +use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::connection::State as ConnectionState; use crate::core::ics03_connection::delay::verify_conn_delay_passed; use crate::core::ics04_channel::channel::{Counterparty, Order, State as ChannelState}; use crate::core::ics04_channel::commitment::{compute_ack_commitment, compute_packet_commitment}; -use crate::core::ics04_channel::error::ChannelError; -use crate::core::ics04_channel::error::PacketError; +use crate::core::ics04_channel::error::{ChannelError, PacketError}; +use crate::core::ics04_channel::events::AcknowledgePacket; use crate::core::ics04_channel::msgs::acknowledgement::MsgAcknowledgement; -use crate::core::ics24_host::path::Path; use crate::core::ics24_host::path::{ - AckPath, ChannelEndPath, ClientConsensusStatePath, CommitmentPath, SeqAckPath, + AckPath, ChannelEndPath, ClientConsensusStatePath, CommitmentPath, Path, SeqAckPath, }; use crate::core::router::Module; -use crate::core::{events::IbcEvent, ics04_channel::events::AcknowledgePacket}; use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn acknowledgement_packet_validate( ctx_a: &ValCtx, @@ -219,31 +216,27 @@ where #[cfg(test)] mod tests { - use super::*; use rstest::*; use test_log::test; + use super::*; + use crate::applications::transfer::MODULE_ID_STR; use crate::core::ics02_client::height::Height; - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order, State}; use crate::core::ics04_channel::commitment::PacketCommitment; use crate::core::ics04_channel::msgs::acknowledgement::test_util::get_dummy_raw_msg_acknowledgement; use crate::core::ics04_channel::msgs::acknowledgement::MsgAcknowledgement; use crate::core::ics04_channel::Version; - use crate::core::ics24_host::identifier::ChannelId; - use crate::core::ics24_host::identifier::PortId; - use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; - use crate::core::router::ModuleId; - use crate::core::router::Router; - use crate::core::timestamp::Timestamp; - use crate::core::timestamp::ZERO_DURATION; - + use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; + use crate::core::router::{ModuleId, Router}; + use crate::core::timestamp::{Timestamp, ZERO_DURATION}; use crate::mock::context::MockContext; use crate::mock::router::MockRouter; - use crate::{applications::transfer::MODULE_ID_STR, test_utils::DummyTransferModule}; + use crate::test_utils::DummyTransferModule; struct Fixture { ctx: MockContext, diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs b/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs index 11974a118..57ca51e55 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs @@ -1,22 +1,20 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelCloseConfirm`. -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; use ibc_proto::protobuf::Protobuf; use crate::core::events::{IbcEvent, MessageEvent}; use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; +use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::connection::State as ConnectionState; -use crate::core::ics04_channel::channel::State; -use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State as ChannelState}; +use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State, State as ChannelState}; use crate::core::ics04_channel::error::ChannelError; use crate::core::ics04_channel::events::CloseConfirm; use crate::core::ics04_channel::msgs::chan_close_confirm::MsgChannelCloseConfirm; -use crate::core::ics24_host::path::Path; -use crate::core::ics24_host::path::{ChannelEndPath, ClientConsensusStatePath}; +use crate::core::ics24_host::path::{ChannelEndPath, ClientConsensusStatePath, Path}; use crate::core::router::Module; use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn chan_close_confirm_validate( ctx_b: &ValCtx, @@ -169,10 +167,10 @@ where #[cfg(test)] mod tests { use super::*; - - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use crate::applications::transfer::MODULE_ID_STR; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::msgs::test_util::get_dummy_raw_counterparty; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::channel::{ @@ -181,14 +179,10 @@ mod tests { use crate::core::ics04_channel::msgs::chan_close_confirm::test_util::get_dummy_raw_msg_chan_close_confirm; use crate::core::ics04_channel::Version; use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; - use crate::core::router::ModuleId; - use crate::core::router::Router; + use crate::core::router::{ModuleId, Router}; use crate::core::timestamp::ZERO_DURATION; - use crate::mock::client_state::client_type as mock_client_type; use crate::mock::context::MockContext; - - use crate::applications::transfer::MODULE_ID_STR; use crate::mock::router::MockRouter; use crate::test_utils::DummyTransferModule; diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs b/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs index 976456696..01aaac7e1 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs @@ -1,9 +1,7 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelCloseInit`. -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; - use crate::core::events::{IbcEvent, MessageEvent}; use crate::core::ics02_client::client_state::ClientStateValidation; +use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::connection::State as ConnectionState; use crate::core::ics04_channel::channel::State; use crate::core::ics04_channel::error::ChannelError; @@ -12,6 +10,7 @@ use crate::core::ics04_channel::msgs::chan_close_init::MsgChannelCloseInit; use crate::core::ics24_host::path::ChannelEndPath; use crate::core::router::Module; use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn chan_close_init_validate( ctx_a: &ValCtx, @@ -126,10 +125,10 @@ where #[cfg(test)] mod tests { use super::*; - - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use crate::applications::transfer::MODULE_ID_STR; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::msgs::test_util::get_dummy_raw_counterparty; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::channel::{ @@ -138,11 +137,8 @@ mod tests { use crate::core::ics04_channel::msgs::chan_close_init::test_util::get_dummy_raw_msg_chan_close_init; use crate::core::ics04_channel::Version; use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; - use crate::core::router::ModuleId; - use crate::core::router::Router; + use crate::core::router::{ModuleId, Router}; use crate::core::timestamp::ZERO_DURATION; - - use crate::applications::transfer::MODULE_ID_STR; use crate::mock::client_state::client_type as mock_client_type; use crate::mock::context::MockContext; use crate::mock::router::MockRouter; diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_ack.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_ack.rs index 8e522ebe0..910441015 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_ack.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_ack.rs @@ -1,6 +1,5 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelOpenAck`. -use crate::prelude::*; use ibc_proto::protobuf::Protobuf; use crate::core::events::{IbcEvent, MessageEvent}; @@ -8,15 +7,14 @@ use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateVali use crate::core::ics02_client::consensus_state::ConsensusState; use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::connection::State as ConnectionState; -use crate::core::ics04_channel::channel::State; -use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State as ChannelState}; +use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State, State as ChannelState}; use crate::core::ics04_channel::error::ChannelError; use crate::core::ics04_channel::events::OpenAck; use crate::core::ics04_channel::msgs::chan_open_ack::MsgChannelOpenAck; -use crate::core::ics24_host::path::Path; -use crate::core::ics24_host::path::{ChannelEndPath, ClientConsensusStatePath}; +use crate::core::ics24_host::path::{ChannelEndPath, ClientConsensusStatePath, Path}; use crate::core::router::Module; use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn chan_open_ack_validate( ctx_a: &ValCtx, @@ -165,31 +163,27 @@ where #[cfg(test)] mod tests { - use super::*; use rstest::*; use test_log::test; + use super::*; use crate::applications::transfer::MODULE_ID_STR; - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::msgs::test_util::get_dummy_raw_counterparty; use crate::core::ics03_connection::version::get_compatible_versions; - use crate::core::ics04_channel::channel::Order; - use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State}; + use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order, State}; use crate::core::ics04_channel::msgs::chan_open_ack::test_util::get_dummy_raw_msg_chan_open_ack; use crate::core::ics04_channel::msgs::chan_open_ack::MsgChannelOpenAck; - use crate::core::ics24_host::identifier::ClientId; - use crate::core::ics24_host::identifier::ConnectionId; - use crate::core::router::ModuleId; - use crate::core::router::Router; + use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; + use crate::core::router::{ModuleId, Router}; use crate::core::timestamp::ZERO_DURATION; - use crate::Height; - use crate::mock::client_state::client_type as mock_client_type; use crate::mock::context::MockContext; use crate::mock::router::MockRouter; use crate::test_utils::DummyTransferModule; + use crate::Height; pub struct Fixture { pub context: MockContext, diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs index b38a937c7..9461f55aa 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs @@ -1,22 +1,20 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelOpenConfirm`. -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; use ibc_proto::protobuf::Protobuf; use crate::core::events::{IbcEvent, MessageEvent}; use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; +use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::connection::State as ConnectionState; -use crate::core::ics04_channel::channel::State; -use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State as ChannelState}; +use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State, State as ChannelState}; use crate::core::ics04_channel::error::ChannelError; use crate::core::ics04_channel::events::OpenConfirm; use crate::core::ics04_channel::msgs::chan_open_confirm::MsgChannelOpenConfirm; -use crate::core::ics24_host::path::Path; -use crate::core::ics24_host::path::{ChannelEndPath, ClientConsensusStatePath}; +use crate::core::ics24_host::path::{ChannelEndPath, ClientConsensusStatePath, Path}; use crate::core::router::Module; use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn chan_open_confirm_validate( ctx_b: &ValCtx, @@ -170,30 +168,28 @@ where #[cfg(test)] mod tests { - use super::*; use rstest::*; use test_log::test; - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use super::*; + use crate::applications::transfer::MODULE_ID_STR; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::msgs::test_util::get_dummy_raw_counterparty; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order, State}; use crate::core::ics04_channel::msgs::chan_open_confirm::test_util::get_dummy_raw_msg_chan_open_confirm; use crate::core::ics04_channel::msgs::chan_open_confirm::MsgChannelOpenConfirm; use crate::core::ics04_channel::Version; - use crate::core::ics24_host::identifier::ChannelId; - use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; - use crate::core::router::ModuleId; - use crate::core::router::Router; + use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId}; + use crate::core::router::{ModuleId, Router}; use crate::core::timestamp::ZERO_DURATION; - use crate::Height; - use crate::mock::client_state::client_type as mock_client_type; use crate::mock::context::MockContext; use crate::mock::router::MockRouter; - use crate::{applications::transfer::MODULE_ID_STR, test_utils::DummyTransferModule}; + use crate::test_utils::DummyTransferModule; + use crate::Height; pub struct Fixture { pub context: MockContext, diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_init.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_init.rs index 1cd8583e8..15d5792ac 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_init.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_init.rs @@ -1,10 +1,8 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelOpenInit`. -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; - use crate::core::events::{IbcEvent, MessageEvent}; use crate::core::ics02_client::client_state::ClientStateValidation; +use crate::core::ics02_client::error::ClientError; use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State}; use crate::core::ics04_channel::events::OpenInit; use crate::core::ics04_channel::msgs::chan_open_init::MsgChannelOpenInit; @@ -12,6 +10,7 @@ use crate::core::ics24_host::identifier::ChannelId; use crate::core::ics24_host::path::{ChannelEndPath, SeqAckPath, SeqRecvPath, SeqSendPath}; use crate::core::router::Module; use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn chan_open_init_validate( ctx_a: &ValCtx, @@ -140,28 +139,24 @@ where #[cfg(test)] mod tests { - use super::*; use rstest::*; + use test_log::test; + use super::*; + use crate::applications::transfer::MODULE_ID_STR; use crate::clients::ics07_tendermint::client_type as tm_client_type; use crate::core::ics02_client::height::Height; - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::State as ConnectionState; + use crate::core::ics03_connection::connection::{ConnectionEnd, State as ConnectionState}; use crate::core::ics03_connection::msgs::conn_open_init::MsgConnectionOpenInit; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::handler::chan_open_init::validate; use crate::core::ics04_channel::msgs::chan_open_init::test_util::get_dummy_raw_msg_chan_open_init; use crate::core::ics04_channel::msgs::chan_open_init::MsgChannelOpenInit; - use crate::core::ics24_host::identifier::ClientId; - use crate::core::ics24_host::identifier::ConnectionId; - - use crate::applications::transfer::MODULE_ID_STR; - use crate::core::router::ModuleId; - use crate::core::router::Router; + use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; + use crate::core::router::{ModuleId, Router}; use crate::mock::context::MockContext; use crate::mock::router::MockRouter; use crate::test_utils::DummyTransferModule; - use test_log::test; pub struct Fixture { pub ctx: MockContext, diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_try.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_try.rs index 3cda49710..4cf78dce7 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_try.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_try.rs @@ -1,6 +1,5 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelOpenTry`. -use crate::prelude::*; use ibc_proto::protobuf::Protobuf; use crate::core::events::{IbcEvent, MessageEvent}; @@ -8,17 +7,17 @@ use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateVali use crate::core::ics02_client::consensus_state::ConsensusState; use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::connection::State as ConnectionState; -use crate::core::ics04_channel::channel::State; -use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State as ChannelState}; +use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, State, State as ChannelState}; use crate::core::ics04_channel::error::ChannelError; use crate::core::ics04_channel::events::OpenTry; use crate::core::ics04_channel::msgs::chan_open_try::MsgChannelOpenTry; use crate::core::ics24_host::identifier::ChannelId; -use crate::core::ics24_host::path::Path; -use crate::core::ics24_host::path::{ChannelEndPath, ClientConsensusStatePath}; -use crate::core::ics24_host::path::{SeqAckPath, SeqRecvPath, SeqSendPath}; +use crate::core::ics24_host::path::{ + ChannelEndPath, ClientConsensusStatePath, Path, SeqAckPath, SeqRecvPath, SeqSendPath, +}; use crate::core::router::Module; use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn chan_open_try_validate( ctx_b: &ValCtx, @@ -187,28 +186,26 @@ where #[cfg(test)] mod tests { - use super::*; use rstest::*; use test_log::test; - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use super::*; + use crate::applications::transfer::MODULE_ID_STR; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::msgs::test_util::get_dummy_raw_counterparty; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::msgs::chan_open_try::test_util::get_dummy_raw_msg_chan_open_try; use crate::core::ics04_channel::msgs::chan_open_try::MsgChannelOpenTry; use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; - use crate::core::router::ModuleId; - use crate::core::router::Router; + use crate::core::router::{ModuleId, Router}; use crate::core::timestamp::ZERO_DURATION; - use crate::Height; - - use crate::applications::transfer::MODULE_ID_STR; use crate::mock::client_state::client_type as mock_client_type; use crate::mock::context::MockContext; use crate::mock::router::MockRouter; use crate::test_utils::DummyTransferModule; + use crate::Height; pub struct Fixture { pub ctx: MockContext, diff --git a/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs b/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs index d2f024612..81009c800 100644 --- a/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs +++ b/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs @@ -1,25 +1,23 @@ -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; - use crate::core::events::{IbcEvent, MessageEvent}; use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; +use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::connection::State as ConnectionState; use crate::core::ics03_connection::delay::verify_conn_delay_passed; use crate::core::ics04_channel::channel::{Counterparty, Order, State as ChannelState}; use crate::core::ics04_channel::commitment::{compute_ack_commitment, compute_packet_commitment}; -use crate::core::ics04_channel::error::ChannelError; -use crate::core::ics04_channel::error::PacketError; +use crate::core::ics04_channel::error::{ChannelError, PacketError}; use crate::core::ics04_channel::events::{ReceivePacket, WriteAcknowledgement}; use crate::core::ics04_channel::msgs::recv_packet::MsgRecvPacket; use crate::core::ics04_channel::packet::Receipt; -use crate::core::ics24_host::path::Path; use crate::core::ics24_host::path::{ - AckPath, ChannelEndPath, ClientConsensusStatePath, CommitmentPath, ReceiptPath, SeqRecvPath, + AckPath, ChannelEndPath, ClientConsensusStatePath, CommitmentPath, Path, ReceiptPath, + SeqRecvPath, }; use crate::core::router::Module; use crate::core::timestamp::Expiry; use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) fn recv_packet_validate( ctx_b: &ValCtx, @@ -284,13 +282,14 @@ where #[cfg(test)] mod tests { - use super::*; use rstest::*; use test_log::test; - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use super::*; + use crate::applications::transfer::MODULE_ID_STR; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order, State}; use crate::core::ics04_channel::msgs::recv_packet::test_util::get_dummy_raw_msg_recv_packet; @@ -298,17 +297,13 @@ mod tests { use crate::core::ics04_channel::packet::Packet; use crate::core::ics04_channel::Version; use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; - use crate::core::router::ModuleId; - use crate::core::router::Router; - use crate::core::timestamp::Timestamp; - use crate::core::timestamp::ZERO_DURATION; - use crate::Height; - + use crate::core::router::{ModuleId, Router}; + use crate::core::timestamp::{Timestamp, ZERO_DURATION}; use crate::mock::context::MockContext; use crate::mock::ics18_relayer::context::RelayerContext; use crate::mock::router::MockRouter; - use crate::test_utils::get_dummy_account_id; - use crate::{applications::transfer::MODULE_ID_STR, test_utils::DummyTransferModule}; + use crate::test_utils::{get_dummy_account_id, DummyTransferModule}; + use crate::Height; pub struct Fixture { pub context: MockContext, diff --git a/crates/ibc/src/core/ics04_channel/handler/send_packet.rs b/crates/ibc/src/core/ics04_channel/handler/send_packet.rs index 59cb14c6d..c978935d8 100644 --- a/crates/ibc/src/core/ics04_channel/handler/send_packet.rs +++ b/crates/ibc/src/core/ics04_channel/handler/send_packet.rs @@ -1,24 +1,21 @@ -use crate::core::ics02_client::client_state::ClientStateValidation; -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; - -use crate::core::events::IbcEvent; -use crate::core::events::MessageEvent; -use crate::core::ics02_client::client_state::ClientStateCommon; +use crate::core::events::{IbcEvent, MessageEvent}; +use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; +use crate::core::ics02_client::error::ClientError; use crate::core::ics04_channel::channel::Counterparty; use crate::core::ics04_channel::commitment::compute_packet_commitment; -use crate::core::ics04_channel::context::SendPacketExecutionContext; +use crate::core::ics04_channel::context::{ + SendPacketExecutionContext, SendPacketValidationContext, +}; +use crate::core::ics04_channel::error::PacketError; use crate::core::ics04_channel::events::SendPacket; -use crate::core::ics04_channel::{ - context::SendPacketValidationContext, error::PacketError, packet::Packet, +use crate::core::ics04_channel::packet::Packet; +use crate::core::ics24_host::path::{ + ChannelEndPath, ClientConsensusStatePath, CommitmentPath, SeqSendPath, }; -use crate::core::ics24_host::path::ChannelEndPath; -use crate::core::ics24_host::path::ClientConsensusStatePath; -use crate::core::ics24_host::path::CommitmentPath; -use crate::core::ics24_host::path::SeqSendPath; use crate::core::timestamp::Expiry; use crate::core::ContextError; +use crate::prelude::*; /// Send the given packet, including all necessary validation. /// @@ -143,17 +140,17 @@ pub fn send_packet_execute( #[cfg(test)] mod tests { - use super::*; use core::ops::Add; use core::time::Duration; use test_log::test; + use super::*; use crate::core::events::IbcEvent; use crate::core::ics02_client::height::Height; - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order, State}; use crate::core::ics04_channel::handler::send_packet::send_packet; @@ -161,8 +158,7 @@ mod tests { use crate::core::ics04_channel::packet::Packet; use crate::core::ics04_channel::Version; use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; - use crate::core::timestamp::Timestamp; - use crate::core::timestamp::ZERO_DURATION; + use crate::core::timestamp::{Timestamp, ZERO_DURATION}; use crate::mock::context::MockContext; #[test] diff --git a/crates/ibc/src/core/ics04_channel/handler/timeout.rs b/crates/ibc/src/core/ics04_channel/handler/timeout.rs index 12d479744..f8b68814a 100644 --- a/crates/ibc/src/core/ics04_channel/handler/timeout.rs +++ b/crates/ibc/src/core/ics04_channel/handler/timeout.rs @@ -1,28 +1,23 @@ -use crate::core::ics02_client::client_state::ClientStateValidation; -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; use prost::Message; -use crate::core::events::IbcEvent; -use crate::core::events::MessageEvent; -use crate::core::ics02_client::client_state::ClientStateCommon; +use crate::core::events::{IbcEvent, MessageEvent}; +use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; +use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::delay::verify_conn_delay_passed; -use crate::core::ics04_channel::channel::State; -use crate::core::ics04_channel::channel::{Counterparty, Order}; +use crate::core::ics04_channel::channel::{Counterparty, Order, State}; use crate::core::ics04_channel::commitment::compute_packet_commitment; -use crate::core::ics04_channel::error::ChannelError; -use crate::core::ics04_channel::error::PacketError; -use crate::core::ics04_channel::events::ChannelClosed; +use crate::core::ics04_channel::error::{ChannelError, PacketError}; +use crate::core::ics04_channel::events::{ChannelClosed, TimeoutPacket}; +use crate::core::ics04_channel::handler::timeout_on_close; use crate::core::ics04_channel::msgs::timeout::MsgTimeout; use crate::core::ics04_channel::msgs::timeout_on_close::MsgTimeoutOnClose; -use crate::core::ics04_channel::{events::TimeoutPacket, handler::timeout_on_close}; -use crate::core::ics24_host::path::Path; use crate::core::ics24_host::path::{ - ChannelEndPath, ClientConsensusStatePath, CommitmentPath, ReceiptPath, SeqRecvPath, + ChannelEndPath, ClientConsensusStatePath, CommitmentPath, Path, ReceiptPath, SeqRecvPath, }; use crate::core::router::Module; use crate::core::{ContextError, ExecutionContext, ValidationContext}; +use crate::prelude::*; pub(crate) enum TimeoutMsgType { Timeout(MsgTimeout), @@ -274,13 +269,14 @@ where #[cfg(test)] mod tests { - use super::*; use rstest::*; + use super::*; + use crate::applications::transfer::MODULE_ID_STR; use crate::core::ics02_client::height::Height; - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order, State}; use crate::core::ics04_channel::commitment::PacketCommitment; @@ -289,12 +285,8 @@ mod tests { use crate::core::ics04_channel::msgs::timeout::MsgTimeout; use crate::core::ics04_channel::Version; use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; - use crate::core::router::ModuleId; - use crate::core::router::Router; - use crate::core::timestamp::Timestamp; - use crate::core::timestamp::ZERO_DURATION; - - use crate::applications::transfer::MODULE_ID_STR; + use crate::core::router::{ModuleId, Router}; + use crate::core::timestamp::{Timestamp, ZERO_DURATION}; use crate::mock::context::MockContext; use crate::mock::router::MockRouter; use crate::test_utils::DummyTransferModule; diff --git a/crates/ibc/src/core/ics04_channel/handler/timeout_on_close.rs b/crates/ibc/src/core/ics04_channel/handler/timeout_on_close.rs index 9215d588a..5a37f8de5 100644 --- a/crates/ibc/src/core/ics04_channel/handler/timeout_on_close.rs +++ b/crates/ibc/src/core/ics04_channel/handler/timeout_on_close.rs @@ -1,21 +1,19 @@ -use crate::core::ics02_client::error::ClientError; -use crate::prelude::*; use ibc_proto::protobuf::Protobuf; use prost::Message; use crate::core::ics02_client::client_state::{ClientStateCommon, ClientStateValidation}; use crate::core::ics02_client::consensus_state::ConsensusState; +use crate::core::ics02_client::error::ClientError; use crate::core::ics03_connection::delay::verify_conn_delay_passed; -use crate::core::ics04_channel::channel::State; -use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order}; +use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order, State}; use crate::core::ics04_channel::commitment::compute_packet_commitment; use crate::core::ics04_channel::error::{ChannelError, PacketError}; use crate::core::ics04_channel::msgs::timeout_on_close::MsgTimeoutOnClose; -use crate::core::ics24_host::path::Path; use crate::core::ics24_host::path::{ - ChannelEndPath, ClientConsensusStatePath, CommitmentPath, ReceiptPath, SeqRecvPath, + ChannelEndPath, ClientConsensusStatePath, CommitmentPath, Path, ReceiptPath, SeqRecvPath, }; use crate::core::{ContextError, ValidationContext}; +use crate::prelude::*; pub fn validate(ctx_a: &Ctx, msg: &MsgTimeoutOnClose) -> Result<(), ContextError> where @@ -175,26 +173,24 @@ where #[cfg(test)] mod tests { - use crate::core::ics04_channel::commitment::compute_packet_commitment; - use crate::core::ics04_channel::commitment::PacketCommitment; - use crate::core::ics04_channel::handler::timeout_on_close::validate; - use crate::core::timestamp::Timestamp; - use crate::core::ExecutionContext; - use crate::mock::context::MockContext; - use crate::prelude::*; - use crate::Height; use rstest::*; - use crate::core::ics03_connection::connection::ConnectionEnd; - use crate::core::ics03_connection::connection::Counterparty as ConnectionCounterparty; - use crate::core::ics03_connection::connection::State as ConnectionState; + use crate::core::ics03_connection::connection::{ + ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, + }; use crate::core::ics03_connection::version::get_compatible_versions; use crate::core::ics04_channel::channel::{ChannelEnd, Counterparty, Order, State}; + use crate::core::ics04_channel::commitment::{compute_packet_commitment, PacketCommitment}; + use crate::core::ics04_channel::handler::timeout_on_close::validate; use crate::core::ics04_channel::msgs::timeout_on_close::test_util::get_dummy_raw_msg_timeout_on_close; use crate::core::ics04_channel::msgs::timeout_on_close::MsgTimeoutOnClose; use crate::core::ics04_channel::Version; use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; - use crate::core::timestamp::ZERO_DURATION; + use crate::core::timestamp::{Timestamp, ZERO_DURATION}; + use crate::core::ExecutionContext; + use crate::mock::context::MockContext; + use crate::prelude::*; + use crate::Height; pub struct Fixture { pub context: MockContext, diff --git a/crates/ibc/src/core/ics04_channel/msgs.rs b/crates/ibc/src/core/ics04_channel/msgs.rs index 728c8926c..a5e87c6e5 100644 --- a/crates/ibc/src/core/ics04_channel/msgs.rs +++ b/crates/ibc/src/core/ics04_channel/msgs.rs @@ -13,17 +13,15 @@ pub(crate) mod timeout; pub(crate) mod timeout_on_close; // Opening handshake messages. +// Packet specific messages. +pub use acknowledgement::MsgAcknowledgement; +// Closing handshake messages. +pub use chan_close_confirm::MsgChannelCloseConfirm; +pub use chan_close_init::MsgChannelCloseInit; pub use chan_open_ack::MsgChannelOpenAck; pub use chan_open_confirm::MsgChannelOpenConfirm; pub use chan_open_init::MsgChannelOpenInit; pub use chan_open_try::MsgChannelOpenTry; - -// Closing handshake messages. -pub use chan_close_confirm::MsgChannelCloseConfirm; -pub use chan_close_init::MsgChannelCloseInit; - -// Packet specific messages. -pub use acknowledgement::MsgAcknowledgement; pub use recv_packet::MsgRecvPacket; pub use timeout::MsgTimeout; pub use timeout_on_close::MsgTimeoutOnClose; diff --git a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs index 6f448d6fc..250c33921 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs @@ -1,5 +1,3 @@ -use crate::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgAcknowledgement as RawMsgAcknowledgement; use ibc_proto::protobuf::Protobuf; @@ -8,6 +6,7 @@ use crate::core::ics04_channel::error::PacketError; use crate::core::ics04_channel::packet::Packet; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; use crate::Height; @@ -78,8 +77,9 @@ impl From for RawMsgAcknowledgement { #[cfg(test)] pub mod test_util { - use ibc_proto::ibc::core::channel::v1::MsgAcknowledgement as RawMsgAcknowledgement; - use ibc_proto::ibc::core::channel::v1::Packet as RawPacket; + use ibc_proto::ibc::core::channel::v1::{ + MsgAcknowledgement as RawMsgAcknowledgement, Packet as RawPacket, + }; use ibc_proto::ibc::core::client::v1::Height as RawHeight; use crate::core::ics04_channel::packet::test_utils::get_dummy_raw_packet; @@ -110,15 +110,13 @@ pub mod test_util { #[cfg(test)] mod test { - use crate::prelude::*; - - use test_log::test; - use ibc_proto::ibc::core::channel::v1::MsgAcknowledgement as RawMsgAcknowledgement; + use test_log::test; use crate::core::ics04_channel::error::PacketError; use crate::core::ics04_channel::msgs::acknowledgement::test_util::get_dummy_raw_msg_acknowledgement; use crate::core::ics04_channel::msgs::acknowledgement::MsgAcknowledgement; + use crate::prelude::*; use crate::test_utils::get_dummy_bech32_account; #[test] diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs index c40c88c5a..ed03904f6 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs @@ -1,14 +1,13 @@ -use crate::core::ics23_commitment::commitment::CommitmentProofBytes; -use crate::{prelude::*, Height}; - -use ibc_proto::protobuf::Protobuf; - use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm; +use ibc_proto::protobuf::Protobuf; use crate::core::ics04_channel::error::ChannelError; +use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::ics24_host::identifier::{ChannelId, PortId}; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; +use crate::Height; pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseConfirm"; @@ -74,11 +73,11 @@ impl From for RawMsgChannelCloseConfirm { #[cfg(test)] pub mod test_util { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm; use ibc_proto::ibc::core::client::v1::Height; use crate::core::ics24_host::identifier::{ChannelId, PortId}; + use crate::prelude::*; use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof}; /// Returns a dummy `RawMsgChannelCloseConfirm`, for testing only! @@ -98,13 +97,12 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm; use ibc_proto::ibc::core::client::v1::Height; use crate::core::ics04_channel::msgs::chan_close_confirm::test_util::get_dummy_raw_msg_chan_close_confirm; use crate::core::ics04_channel::msgs::chan_close_confirm::MsgChannelCloseConfirm; + use crate::prelude::*; #[test] fn parse_channel_close_confirm_msg() { diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs index d3a569217..4ad83ef81 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs @@ -1,12 +1,10 @@ -use crate::prelude::*; - -use ibc_proto::protobuf::Protobuf; - use ibc_proto::ibc::core::channel::v1::MsgChannelCloseInit as RawMsgChannelCloseInit; +use ibc_proto::protobuf::Protobuf; use crate::core::ics04_channel::error::ChannelError; use crate::core::ics24_host::identifier::{ChannelId, PortId}; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseInit"; @@ -60,10 +58,10 @@ impl From for RawMsgChannelCloseInit { #[cfg(test)] pub mod test_util { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::MsgChannelCloseInit as RawMsgChannelCloseInit; use crate::core::ics24_host::identifier::{ChannelId, PortId}; + use crate::prelude::*; use crate::test_utils::get_dummy_bech32_account; /// Returns a dummy `RawMsgChannelCloseInit`, for testing only! @@ -78,14 +76,12 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::prelude::*; - - use test_log::test; - use ibc_proto::ibc::core::channel::v1::MsgChannelCloseInit as RawMsgChannelCloseInit; + use test_log::test; use crate::core::ics04_channel::msgs::chan_close_init::test_util::get_dummy_raw_msg_chan_close_init; use crate::core::ics04_channel::msgs::chan_close_init::MsgChannelCloseInit; + use crate::prelude::*; #[test] fn parse_channel_close_init_msg() { diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs index 9fca241ff..56dc166e4 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs @@ -1,13 +1,14 @@ +use ibc_proto::ibc::core::channel::v1::MsgChannelOpenAck as RawMsgChannelOpenAck; +use ibc_proto::protobuf::Protobuf; + use crate::core::ics04_channel::error::ChannelError; use crate::core::ics04_channel::Version; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::ics24_host::identifier::{ChannelId, PortId}; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; -use crate::{prelude::*, Height}; - -use ibc_proto::ibc::core::channel::v1::MsgChannelOpenAck as RawMsgChannelOpenAck; -use ibc_proto::protobuf::Protobuf; +use crate::Height; pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenAck"; @@ -77,12 +78,12 @@ impl From for RawMsgChannelOpenAck { #[cfg(test)] pub mod test_util { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::MsgChannelOpenAck as RawMsgChannelOpenAck; + use ibc_proto::ibc::core::client::v1::Height; use crate::core::ics24_host::identifier::{ChannelId, PortId}; + use crate::prelude::*; use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof}; - use ibc_proto::ibc::core::client::v1::Height; /// Returns a dummy `RawMsgChannelOpenAck`, for testing only! pub fn get_dummy_raw_msg_chan_open_ack(proof_height: u64) -> RawMsgChannelOpenAck { @@ -103,14 +104,13 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::MsgChannelOpenAck as RawMsgChannelOpenAck; + use ibc_proto::ibc::core::client::v1::Height; use test_log::test; use crate::core::ics04_channel::msgs::chan_open_ack::test_util::get_dummy_raw_msg_chan_open_ack; use crate::core::ics04_channel::msgs::chan_open_ack::MsgChannelOpenAck; - - use ibc_proto::ibc::core::client::v1::Height; + use crate::prelude::*; #[test] fn parse_channel_open_ack_msg() { diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs index 4bd43bd39..a0daea61d 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs @@ -1,12 +1,13 @@ +use ibc_proto::ibc::core::channel::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm; +use ibc_proto::protobuf::Protobuf; + use crate::core::ics04_channel::error::ChannelError; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::ics24_host::identifier::{ChannelId, PortId}; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; -use crate::{prelude::*, Height}; - -use ibc_proto::ibc::core::channel::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm; -use ibc_proto::protobuf::Protobuf; +use crate::Height; pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenConfirm"; @@ -72,12 +73,12 @@ impl From for RawMsgChannelOpenConfirm { #[cfg(test)] pub mod test_util { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm; + use ibc_proto::ibc::core::client::v1::Height; use crate::core::ics24_host::identifier::{ChannelId, PortId}; + use crate::prelude::*; use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof}; - use ibc_proto::ibc::core::client::v1::Height; /// Returns a dummy `RawMsgChannelOpenConfirm`, for testing only! pub fn get_dummy_raw_msg_chan_open_confirm(proof_height: u64) -> RawMsgChannelOpenConfirm { @@ -96,14 +97,13 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm; + use ibc_proto::ibc::core::client::v1::Height; use test_log::test; use crate::core::ics04_channel::msgs::chan_open_confirm::test_util::get_dummy_raw_msg_chan_open_confirm; use crate::core::ics04_channel::msgs::chan_open_confirm::MsgChannelOpenConfirm; - - use ibc_proto::ibc::core::client::v1::Height; + use crate::prelude::*; #[test] fn parse_channel_open_confirm_msg() { diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs index 08f034eb2..f2c081252 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs @@ -1,7 +1,9 @@ -use crate::core::ics04_channel::channel::verify_connection_hops_length; -use crate::core::ics04_channel::channel::ChannelEnd; -use crate::core::ics04_channel::channel::Counterparty; -use crate::core::ics04_channel::channel::{Order, State}; +use ibc_proto::ibc::core::channel::v1::MsgChannelOpenInit as RawMsgChannelOpenInit; +use ibc_proto::protobuf::Protobuf; + +use crate::core::ics04_channel::channel::{ + verify_connection_hops_length, ChannelEnd, Counterparty, Order, State, +}; use crate::core::ics04_channel::error::ChannelError; use crate::core::ics04_channel::Version; use crate::core::ics24_host::identifier::{ConnectionId, PortId}; @@ -9,9 +11,6 @@ use crate::core::Msg; use crate::prelude::*; use crate::signer::Signer; -use ibc_proto::ibc::core::channel::v1::MsgChannelOpenInit as RawMsgChannelOpenInit; -use ibc_proto::protobuf::Protobuf; - pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenInit"; /// @@ -93,11 +92,11 @@ impl From for RawMsgChannelOpenInit { #[cfg(test)] pub mod test_util { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::MsgChannelOpenInit as RawMsgChannelOpenInit; use crate::core::ics04_channel::channel::test_util::get_dummy_raw_channel_end; use crate::core::ics24_host::identifier::PortId; + use crate::prelude::*; use crate::test_utils::get_dummy_bech32_account; /// Returns a dummy `RawMsgChannelOpenInit`, for testing only! @@ -114,13 +113,13 @@ pub mod test_util { #[cfg(test)] mod tests { + use ibc_proto::ibc::core::channel::v1::MsgChannelOpenInit as RawMsgChannelOpenInit; + use test_log::test; + use crate::core::ics04_channel::msgs::chan_open_init::test_util::get_dummy_raw_msg_chan_open_init; use crate::core::ics04_channel::msgs::chan_open_init::MsgChannelOpenInit; use crate::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgChannelOpenInit as RawMsgChannelOpenInit; - use test_log::test; - #[test] fn channel_open_init_from_raw() { struct Test { diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs index ad0e93ca4..6e2876332 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs @@ -1,17 +1,17 @@ -use crate::core::ics04_channel::channel::verify_connection_hops_length; -use crate::core::ics04_channel::channel::ChannelEnd; -use crate::core::ics04_channel::channel::Counterparty; -use crate::core::ics04_channel::channel::{Order, State}; +use ibc_proto::ibc::core::channel::v1::MsgChannelOpenTry as RawMsgChannelOpenTry; +use ibc_proto::protobuf::Protobuf; + +use crate::core::ics04_channel::channel::{ + verify_connection_hops_length, ChannelEnd, Counterparty, Order, State, +}; use crate::core::ics04_channel::error::ChannelError; use crate::core::ics04_channel::Version; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; -use crate::{prelude::*, Height}; - -use ibc_proto::ibc::core::channel::v1::MsgChannelOpenTry as RawMsgChannelOpenTry; -use ibc_proto::protobuf::Protobuf; +use crate::Height; pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenTry"; @@ -129,13 +129,13 @@ impl From for RawMsgChannelOpenTry { #[cfg(test)] pub mod test_util { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::MsgChannelOpenTry as RawMsgChannelOpenTry; + use ibc_proto::ibc::core::client::v1::Height; use crate::core::ics04_channel::channel::test_util::get_dummy_raw_channel_end; use crate::core::ics24_host::identifier::PortId; + use crate::prelude::*; use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof}; - use ibc_proto::ibc::core::client::v1::Height; /// Returns a dummy `RawMsgChannelOpenTry`, for testing only! pub fn get_dummy_raw_msg_chan_open_try(proof_height: u64) -> RawMsgChannelOpenTry { @@ -157,14 +157,14 @@ pub mod test_util { #[cfg(test)] mod tests { - use crate::core::ics04_channel::msgs::chan_open_try::test_util::get_dummy_raw_msg_chan_open_try; - use crate::core::ics04_channel::msgs::chan_open_try::MsgChannelOpenTry; - use crate::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgChannelOpenTry as RawMsgChannelOpenTry; use ibc_proto::ibc::core::client::v1::Height; use test_log::test; + use crate::core::ics04_channel::msgs::chan_open_try::test_util::get_dummy_raw_msg_chan_open_try; + use crate::core::ics04_channel::msgs::chan_open_try::MsgChannelOpenTry; + use crate::prelude::*; + #[test] fn channel_open_try_from_raw() { struct Test { diff --git a/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs b/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs index 241c67976..9b342a7d1 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs @@ -1,13 +1,11 @@ -use crate::prelude::*; - -use ibc_proto::protobuf::Protobuf; - use ibc_proto::ibc::core::channel::v1::MsgRecvPacket as RawMsgRecvPacket; +use ibc_proto::protobuf::Protobuf; use crate::core::ics04_channel::error::PacketError; use crate::core::ics04_channel::packet::Packet; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; use crate::Height; @@ -77,6 +75,9 @@ impl From for RawMsgRecvPacket { #[cfg(test)] pub mod test_util { + use core::ops::Add; + use core::time::Duration; + use ibc_proto::ibc::core::channel::v1::MsgRecvPacket as RawMsgRecvPacket; use ibc_proto::ibc::core::client::v1::Height as RawHeight; @@ -87,8 +88,6 @@ pub mod test_util { use crate::core::timestamp::Timestamp; use crate::signer::Signer; use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof}; - use core::ops::Add; - use core::time::Duration; impl MsgRecvPacket { pub fn new( @@ -127,15 +126,13 @@ pub mod test_util { #[cfg(test)] mod test { - use crate::prelude::*; - - use test_log::test; - use ibc_proto::ibc::core::channel::v1::MsgRecvPacket as RawMsgRecvPacket; + use test_log::test; use crate::core::ics04_channel::error::PacketError; use crate::core::ics04_channel::msgs::recv_packet::test_util::get_dummy_raw_msg_recv_packet; use crate::core::ics04_channel::msgs::recv_packet::MsgRecvPacket; + use crate::prelude::*; use crate::test_utils::get_dummy_bech32_account; #[test] diff --git a/crates/ibc/src/core/ics04_channel/msgs/timeout.rs b/crates/ibc/src/core/ics04_channel/msgs/timeout.rs index b3104bca3..b2244b268 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/timeout.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/timeout.rs @@ -1,13 +1,11 @@ -use crate::prelude::*; - -use ibc_proto::protobuf::Protobuf; - use ibc_proto::ibc::core::channel::v1::MsgTimeout as RawMsgTimeout; +use ibc_proto::protobuf::Protobuf; use crate::core::ics04_channel::error::PacketError; use crate::core::ics04_channel::packet::{Packet, Sequence}; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; use crate::Height; @@ -108,15 +106,13 @@ pub mod test_util { #[cfg(test)] mod test { - use crate::prelude::*; - - use test_log::test; - use ibc_proto::ibc::core::channel::v1::MsgTimeout as RawMsgTimeout; + use test_log::test; use crate::core::ics04_channel::error::PacketError; use crate::core::ics04_channel::msgs::timeout::test_util::get_dummy_raw_msg_timeout; use crate::core::ics04_channel::msgs::timeout::MsgTimeout; + use crate::prelude::*; use crate::test_utils::get_dummy_bech32_account; #[test] diff --git a/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs b/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs index e299d9a18..6e965edc4 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs @@ -1,5 +1,3 @@ -use crate::prelude::*; - use ibc_proto::ibc::core::channel::v1::MsgTimeoutOnClose as RawMsgTimeoutOnClose; use ibc_proto::protobuf::Protobuf; @@ -7,6 +5,7 @@ use crate::core::ics04_channel::error::PacketError; use crate::core::ics04_channel::packet::{Packet, Sequence}; use crate::core::ics23_commitment::commitment::CommitmentProofBytes; use crate::core::Msg; +use crate::prelude::*; use crate::signer::Signer; use crate::Height; @@ -85,12 +84,12 @@ impl From for RawMsgTimeoutOnClose { #[cfg(test)] mod tests { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::MsgTimeoutOnClose as RawMsgTimeoutOnClose; use test_log::test; use crate::core::ics04_channel::msgs::timeout_on_close::test_util::get_dummy_raw_msg_timeout_on_close; use crate::core::ics04_channel::msgs::timeout_on_close::MsgTimeoutOnClose; + use crate::prelude::*; #[test] fn msg_timeout_on_close_try_from_raw() { diff --git a/crates/ibc/src/core/ics04_channel/packet.rs b/crates/ibc/src/core/ics04_channel/packet.rs index 91ca8fd88..b80069acc 100644 --- a/crates/ibc/src/core/ics04_channel/packet.rs +++ b/crates/ibc/src/core/ics04_channel/packet.rs @@ -1,7 +1,5 @@ //! Defines the packet type -use crate::prelude::*; - use core::str::FromStr; use ibc_proto::ibc::core::channel::v1::Packet as RawPacket; @@ -9,7 +7,9 @@ use ibc_proto::ibc::core::channel::v1::Packet as RawPacket; use super::timeout::TimeoutHeight; use crate::core::ics04_channel::error::{ChannelError, PacketError}; use crate::core::ics24_host::identifier::{ChannelId, PortId}; -use crate::core::timestamp::{Expiry::Expired, Timestamp}; +use crate::core::timestamp::Expiry::Expired; +use crate::core::timestamp::Timestamp; +use crate::prelude::*; use crate::Height; /// Enumeration of proof carrying ICS4 message, helper for relayer. @@ -287,11 +287,11 @@ impl From for RawPacket { #[cfg(test)] pub mod test_utils { - use crate::prelude::*; use ibc_proto::ibc::core::channel::v1::Packet as RawPacket; use ibc_proto::ibc::core::client::v1::Height as RawHeight; use crate::core::ics24_host::identifier::{ChannelId, PortId}; + use crate::prelude::*; /// Returns a dummy `RawPacket`, for testing only! pub fn get_dummy_raw_packet(timeout_height: u64, timeout_timestamp: u64) -> RawPacket { @@ -313,15 +313,13 @@ pub mod test_utils { #[cfg(test)] mod tests { - use crate::prelude::*; - - use test_log::test; - use ibc_proto::ibc::core::channel::v1::Packet as RawPacket; use ibc_proto::ibc::core::client::v1::Height as RawHeight; + use test_log::test; use crate::core::ics04_channel::packet::test_utils::get_dummy_raw_packet; use crate::core::ics04_channel::packet::Packet; + use crate::prelude::*; #[test] fn packet_try_from_raw() { diff --git a/crates/ibc/src/core/ics04_channel/timeout.rs b/crates/ibc/src/core/ics04_channel/timeout.rs index 96f3096b5..e70a1efd7 100644 --- a/crates/ibc/src/core/ics04_channel/timeout.rs +++ b/crates/ibc/src/core/ics04_channel/timeout.rs @@ -4,7 +4,8 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use ibc_proto::ibc::core::client::v1::Height as RawHeight; -use crate::core::ics02_client::{error::ClientError, height::Height}; +use crate::core::ics02_client::error::ClientError; +use crate::core::ics02_client::height::Height; use crate::prelude::*; /// Indicates a consensus height on the destination chain after which the packet @@ -150,9 +151,10 @@ impl Display for TimeoutHeight { #[cfg(feature = "serde")] mod tests { - use super::TimeoutHeight; use serde::{Deserialize, Serialize}; + use super::TimeoutHeight; + impl Serialize for TimeoutHeight { fn serialize(&self, serializer: S) -> Result where diff --git a/crates/ibc/src/core/ics04_channel/version.rs b/crates/ibc/src/core/ics04_channel/version.rs index dd3e39bf7..84feb5e7e 100644 --- a/crates/ibc/src/core/ics04_channel/version.rs +++ b/crates/ibc/src/core/ics04_channel/version.rs @@ -6,9 +6,8 @@ use core::convert::Infallible; use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; -use crate::prelude::*; - use super::error::ChannelError; +use crate::prelude::*; /// The version field for a `ChannelEnd`. /// diff --git a/crates/ibc/src/core/ics23_commitment/commitment.rs b/crates/ibc/src/core/ics23_commitment/commitment.rs index b5b876b71..1b8af341e 100644 --- a/crates/ibc/src/core/ics23_commitment/commitment.rs +++ b/crates/ibc/src/core/ics23_commitment/commitment.rs @@ -1,13 +1,14 @@ //! Defines core commitment types -use crate::core::ics23_commitment::error::CommitmentError; -use crate::prelude::*; +use core::convert::TryFrom; +use core::fmt; -use core::{convert::TryFrom, fmt}; use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof; use subtle_encoding::{Encoding, Hex}; use super::merkle::MerkleProof; +use crate::core::ics23_commitment::error::CommitmentError; +use crate::prelude::*; /// Encodes a commitment root; most often a Merkle tree root hash. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -198,11 +199,12 @@ impl serde::Serialize for CommitmentPrefix { #[cfg(test)] pub mod test_util { - use super::CommitmentProofBytes; - use crate::prelude::*; use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof; use ibc_proto::ics23::CommitmentProof; + use super::CommitmentProofBytes; + use crate::prelude::*; + /// Returns a dummy `CommitmentProofBytes`, for testing only! pub fn get_dummy_commitment_proof_bytes() -> CommitmentProofBytes { let parsed = CommitmentProof { proof: None }; diff --git a/crates/ibc/src/core/ics23_commitment/error.rs b/crates/ibc/src/core/ics23_commitment/error.rs index 5d70fac03..1a4bcaaeb 100644 --- a/crates/ibc/src/core/ics23_commitment/error.rs +++ b/crates/ibc/src/core/ics23_commitment/error.rs @@ -1,6 +1,7 @@ //! Defines the commitment error type use alloc::string::String; + use displaydoc::Display; use prost::DecodeError; diff --git a/crates/ibc/src/core/ics23_commitment/merkle.rs b/crates/ibc/src/core/ics23_commitment/merkle.rs index 81f679851..3f5bfb437 100644 --- a/crates/ibc/src/core/ics23_commitment/merkle.rs +++ b/crates/ibc/src/core/ics23_commitment/merkle.rs @@ -1,10 +1,6 @@ //! Merkle proof utilities -use crate::prelude::*; - -use ibc_proto::ibc::core::commitment::v1::MerklePath; -use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof; -use ibc_proto::ibc::core::commitment::v1::MerkleRoot; +use ibc_proto::ibc::core::commitment::v1::{MerklePath, MerkleProof as RawMerkleProof, MerkleRoot}; use ibc_proto::ics23::commitment_proof::Proof; use ibc_proto::ics23::{ calculate_existence_root, verify_membership, verify_non_membership, CommitmentProof, @@ -14,6 +10,7 @@ use ibc_proto::ics23::{ use crate::core::ics23_commitment::commitment::{CommitmentPrefix, CommitmentRoot}; use crate::core::ics23_commitment::error::CommitmentError; use crate::core::ics23_commitment::specs::ProofSpecs; +use crate::prelude::*; pub fn apply_prefix(prefix: &CommitmentPrefix, mut path: Vec) -> MerklePath { let mut key_path: Vec = vec![format!("{prefix:?}")]; diff --git a/crates/ibc/src/core/ics23_commitment/specs.rs b/crates/ibc/src/core/ics23_commitment/specs.rs index 902a97315..ae7787a39 100644 --- a/crates/ibc/src/core/ics23_commitment/specs.rs +++ b/crates/ibc/src/core/ics23_commitment/specs.rs @@ -1,7 +1,8 @@ //! Defines proof specs, which encode the structure of proofs -use crate::prelude::*; use ibc_proto::ics23::{InnerSpec as RawInnerSpec, LeafOp as RawLeafOp, ProofSpec as RawProofSpec}; + +use crate::prelude::*; /// An array of proof specifications. /// /// This type encapsulates different types of proof specifications, mostly predefined, e.g., for diff --git a/crates/ibc/src/core/ics24_host/identifier.rs b/crates/ibc/src/core/ics24_host/identifier.rs index 6ce2f4b18..d669d8731 100644 --- a/crates/ibc/src/core/ics24_host/identifier.rs +++ b/crates/ibc/src/core/ics24_host/identifier.rs @@ -1,17 +1,15 @@ //! Defines identifier types pub(crate) mod validate; -use validate::*; - use core::fmt::{Debug, Display, Error as FmtError, Formatter}; use core::str::FromStr; use derive_more::Into; use displaydoc::Display; +use validate::*; use crate::clients::ics07_tendermint::client_type as tm_client_type; use crate::core::ics02_client::client_type::ClientType; - use crate::prelude::*; const CONNECTION_ID_PREFIX: &str = "connection"; diff --git a/crates/ibc/src/core/ics24_host/identifier/validate.rs b/crates/ibc/src/core/ics24_host/identifier/validate.rs index f926a4c5d..ddf8c98b8 100644 --- a/crates/ibc/src/core/ics24_host/identifier/validate.rs +++ b/crates/ibc/src/core/ics24_host/identifier/validate.rs @@ -1,6 +1,5 @@ -use crate::prelude::*; - use super::IdentifierError as Error; +use crate::prelude::*; /// Path separator (ie. forward slash '/') const PATH_SEPARATOR: char = '/'; @@ -123,10 +122,10 @@ pub fn validate_channel_identifier(id: &str) -> Result<(), Error> { #[cfg(test)] mod tests { - use super::*; - use test_log::test; + use super::*; + #[test] fn parse_invalid_port_id_min() { // invalid min port id diff --git a/crates/ibc/src/core/ics24_host/path.rs b/crates/ibc/src/core/ics24_host/path.rs index 24dc1bb48..c01eb5797 100644 --- a/crates/ibc/src/core/ics24_host/path.rs +++ b/crates/ibc/src/core/ics24_host/path.rs @@ -1,17 +1,17 @@ //! Defines all store paths used by IBC -use crate::{prelude::*, Height}; - /// Path-space as listed in ICS-024 /// https://github.com/cosmos/ibc/tree/master/spec/core/ics-024-host-requirements#path-space /// Some of these are implemented in other ICSs, but ICS-024 has a nice summary table. /// use core::str::FromStr; +use derive_more::{Display, From}; + use crate::core::ics04_channel::packet::Sequence; use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; - -use derive_more::{Display, From}; +use crate::prelude::*; +use crate::Height; /// ABCI client upgrade keys /// - The key identifying the upgraded IBC state within the upgrade sub-store @@ -834,9 +834,10 @@ fn parse_upgrades(components: &[&str]) -> Option { #[cfg(test)] mod tests { - use super::*; use core::str::FromStr; + use super::*; + #[test] fn invalid_path_doesnt_parse() { let invalid_path = Path::from_str("clients/clientType"); diff --git a/crates/ibc/src/core/mod.rs b/crates/ibc/src/core/mod.rs index 66d10b0dd..3bef22053 100644 --- a/crates/ibc/src/core/mod.rs +++ b/crates/ibc/src/core/mod.rs @@ -36,15 +36,9 @@ mod context; mod handler; mod msgs; -pub use handler::dispatch; -pub use handler::execute; -pub use handler::validate; - pub use context::*; - -pub use msgs::Msg; -pub use msgs::MsgEnvelope; - +pub use handler::{dispatch, execute, validate}; pub use ics04_channel::handler::send_packet::{ send_packet, send_packet_execute, send_packet_validate, }; +pub use msgs::{Msg, MsgEnvelope}; diff --git a/crates/ibc/src/core/msgs.rs b/crates/ibc/src/core/msgs.rs index 66a2c6eaf..7f8fe8a53 100644 --- a/crates/ibc/src/core/msgs.rs +++ b/crates/ibc/src/core/msgs.rs @@ -1,6 +1,5 @@ -use crate::prelude::*; - use ibc_proto::google::protobuf::Any; +use ibc_proto::protobuf::Protobuf; use crate::core::context::RouterError; use crate::core::ics02_client::msgs::{ @@ -13,7 +12,7 @@ use crate::core::ics04_channel::msgs::{ acknowledgement, chan_close_confirm, chan_close_init, chan_open_ack, chan_open_confirm, chan_open_init, chan_open_try, recv_packet, timeout, timeout_on_close, ChannelMsg, PacketMsg, }; -use ibc_proto::protobuf::Protobuf; +use crate::prelude::*; /// Trait to be implemented by all IBC messages pub trait Msg: Clone { diff --git a/crates/ibc/src/core/router.rs b/crates/ibc/src/core/router.rs index 81adbf99d..4cdb66524 100644 --- a/crates/ibc/src/core/router.rs +++ b/crates/ibc/src/core/router.rs @@ -1,6 +1,5 @@ //! Defines the `Router`, which binds modules to ports -use crate::prelude::*; use alloc::borrow::Borrow; use core::fmt::{Debug, Display, Error as FmtError, Formatter}; @@ -10,8 +9,8 @@ use crate::core::ics04_channel::channel::{Counterparty, Order}; use crate::core::ics04_channel::error::{ChannelError, PacketError}; use crate::core::ics04_channel::packet::Packet; use crate::core::ics04_channel::Version; -use crate::core::ics24_host::identifier::PortId; -use crate::core::ics24_host::identifier::{ChannelId, ConnectionId}; +use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; +use crate::prelude::*; use crate::signer::Signer; /// Router as defined in ICS-26, which binds modules to ports. diff --git a/crates/ibc/src/core/timestamp.rs b/crates/ibc/src/core/timestamp.rs index e0c6079fb..64add0694 100644 --- a/crates/ibc/src/core/timestamp.rs +++ b/crates/ibc/src/core/timestamp.rs @@ -1,7 +1,5 @@ //! Defines the representation of timestamps used in packet timeouts -use crate::prelude::*; - use core::fmt::{Display, Error as FmtError, Formatter}; use core::hash::{Hash, Hasher}; use core::num::ParseIntError; @@ -13,6 +11,8 @@ use displaydoc::Display; use tendermint::Time; use time::OffsetDateTime; +use crate::prelude::*; + pub const ZERO_DURATION: Duration = Duration::from_secs(0); /// A newtype wrapper over `Option