From 4f68431cfd8bc1e6348cb8dd852fef7e1acbc221 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 24 Feb 2024 17:30:21 +0700 Subject: [PATCH 01/34] use concrete channel order enum --- ibc-core/ics04-channel/types/src/channel.rs | 3 +-- ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/chan_close_init.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/recv_packet.rs | 2 +- ibc-testkit/tests/core/ics04_channel/send_packet.rs | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ibc-core/ics04-channel/types/src/channel.rs b/ibc-core/ics04-channel/types/src/channel.rs index f42d8b86f..0f9720002 100644 --- a/ibc-core/ics04-channel/types/src/channel.rs +++ b/ibc-core/ics04-channel/types/src/channel.rs @@ -435,10 +435,9 @@ impl From for RawCounterparty { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Order { None = 0isize, - #[default] Unordered = 1isize, Ordered = 2isize, } diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs index d337c7d4a..6b8668bcf 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs @@ -42,7 +42,7 @@ fn test_chan_close_confirm_validate() { let chan_end = ChannelEnd::new( ChannelState::Open, - Order::default(), + Order::Unordered, Counterparty::new( msg_chan_close_confirm.port_id_on_b.clone(), Some(msg_chan_close_confirm.chan_id_on_b.clone()), @@ -101,7 +101,7 @@ fn test_chan_close_confirm_execute() { let chan_end = ChannelEnd::new( ChannelState::Open, - Order::default(), + Order::Unordered, Counterparty::new( msg_chan_close_confirm.port_id_on_b.clone(), Some(msg_chan_close_confirm.chan_id_on_b.clone()), diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs index ccf040f85..4e7331d54 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs @@ -38,7 +38,7 @@ fn test_chan_close_init_validate() { let chan_end = ChannelEnd::new( ChannelState::Open, - Order::default(), + Order::Unordered, Counterparty::new( msg_chan_close_init.port_id_on_a.clone(), Some(msg_chan_close_init.chan_id_on_a.clone()), @@ -98,7 +98,7 @@ fn test_chan_close_init_execute() { let chan_end = ChannelEnd::new( ChannelState::Open, - Order::default(), + Order::Unordered, Counterparty::new( msg_chan_close_init.port_id_on_a.clone(), Some(msg_chan_close_init.chan_id_on_a.clone()), diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index 773390f17..47a3e737e 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -49,7 +49,7 @@ fn fixture() -> Fixture { let chan_end_on_b = ChannelEnd::new( State::Open, - Order::default(), + Order::Unordered, Counterparty::new(packet.port_id_on_a, Some(packet.chan_id_on_a)), vec![ConnectionId::default()], Version::new("ics20-1".to_string()), diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 333563ee0..9d2befbd1 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -30,7 +30,7 @@ fn send_packet_processing() { let chan_end_on_a = ChannelEnd::new( State::Open, - Order::default(), + Order::Unordered, Counterparty::new(PortId::transfer(), Some(ChannelId::default())), vec![ConnectionId::default()], Version::new("ics20-1".to_string()), From f19438316c9cfff1794a6b41f90cec125272d4fe Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Mon, 26 Feb 2024 13:09:04 +0700 Subject: [PATCH 02/34] refactor(ics04): remove Version::default() --- ibc-core/ics04-channel/types/src/version.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ibc-core/ics04-channel/types/src/version.rs b/ibc-core/ics04-channel/types/src/version.rs index bf41109da..2cfc1e46c 100644 --- a/ibc-core/ics04-channel/types/src/version.rs +++ b/ibc-core/ics04-channel/types/src/version.rs @@ -74,13 +74,6 @@ impl FromStr for Version { } } -/// The default version is empty (unspecified). -impl Default for Version { - fn default() -> Self { - Version::empty() - } -} - impl Display for Version { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { write!(f, "{}", self.0) From de47605488ebb5e0be9deacec781a36f291fcfb7 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Mon, 26 Feb 2024 13:11:39 +0700 Subject: [PATCH 03/34] refactor(ics04): remove TimeoutHeight::default() --- ibc-core/ics04-channel/types/src/timeout.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ibc-core/ics04-channel/types/src/timeout.rs b/ibc-core/ics04-channel/types/src/timeout.rs index 3a7e825ce..e20ccf0d8 100644 --- a/ibc-core/ics04-channel/types/src/timeout.rs +++ b/ibc-core/ics04-channel/types/src/timeout.rs @@ -84,12 +84,6 @@ impl TimeoutHeight { } } -impl Default for TimeoutHeight { - fn default() -> Self { - Self::Never - } -} - impl TryFrom for TimeoutHeight { type Error = ClientError; From e384dca573ad9c62644beb54cfe63012734b4694 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Mon, 26 Feb 2024 13:25:20 +0700 Subject: [PATCH 04/34] refactor: remove channelId::default() --- .../types/src/identifiers/channel_id.rs | 6 ---- ibc-core/ics24-host/types/src/path.rs | 30 +++++++++---------- .../core/channel/chan_close_confirm.rs | 2 +- .../fixtures/core/channel/chan_close_init.rs | 2 +- .../fixtures/core/channel/chan_open_ack.rs | 4 +-- .../core/channel/chan_open_confirm.rs | 2 +- .../core/ics04_channel/acknowledgement.rs | 12 +++----- .../core/ics04_channel/chan_open_confirm.rs | 22 ++++---------- .../tests/core/ics04_channel/recv_packet.rs | 10 +++---- .../tests/core/ics04_channel/send_packet.rs | 30 ++++++------------- .../tests/core/ics04_channel/timeout.rs | 22 +++++--------- .../core/ics04_channel/timeout_on_close.rs | 4 +-- 12 files changed, 52 insertions(+), 94 deletions(-) diff --git a/ibc-core/ics24-host/types/src/identifiers/channel_id.rs b/ibc-core/ics24-host/types/src/identifiers/channel_id.rs index 3cfeacb7b..1f986c831 100644 --- a/ibc-core/ics24-host/types/src/identifiers/channel_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/channel_id.rs @@ -80,12 +80,6 @@ impl AsRef for ChannelId { } } -impl Default for ChannelId { - fn default() -> Self { - Self::new(0) - } -} - /// Equality check against string literal (satisfies &ChannelId == &str). /// ``` /// use core::str::FromStr; diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index c016f772b..b695a0747 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1219,25 +1219,25 @@ mod tests { #[case("ports/transfer", Path::Ports(PortPath(PortId::transfer())))] #[case( "channelEnds/ports/transfer/channels/channel-0", - Path::ChannelEnd(ChannelEndPath(PortId::transfer(), ChannelId::default())) + Path::ChannelEnd(ChannelEndPath(PortId::transfer(), ChannelId::new(0))) )] #[case( "nextSequenceSend/ports/transfer/channels/channel-0", - Path::SeqSend(SeqSendPath(PortId::transfer(), ChannelId::default())) + Path::SeqSend(SeqSendPath(PortId::transfer(), ChannelId::new(0))) )] #[case( "nextSequenceRecv/ports/transfer/channels/channel-0", - Path::SeqRecv(SeqRecvPath(PortId::transfer(), ChannelId::default())) + Path::SeqRecv(SeqRecvPath(PortId::transfer(), ChannelId::new(0))) )] #[case( "nextSequenceAck/ports/transfer/channels/channel-0", - Path::SeqAck(SeqAckPath(PortId::transfer(), ChannelId::default())) + Path::SeqAck(SeqAckPath(PortId::transfer(), ChannelId::new(0))) )] #[case( "commitments/ports/transfer/channels/channel-0/sequences/0", Path::Commitment(CommitmentPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), + channel_id: ChannelId::new(0), sequence: Sequence::default(), }) )] @@ -1245,7 +1245,7 @@ mod tests { "acks/ports/transfer/channels/channel-0/sequences/0", Path::Ack(AckPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), + channel_id: ChannelId::new(0), sequence: Sequence::default(), }) )] @@ -1253,7 +1253,7 @@ mod tests { "receipts/ports/transfer/channels/channel-0/sequences/0", Path::Receipt(ReceiptPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), + channel_id: ChannelId::new(0), sequence: Sequence::default(), }) )] @@ -1360,7 +1360,7 @@ mod tests { assert_eq!( parse_channels(&components), - Some(SubPath::Channels(ChannelId::default())), + Some(SubPath::Channels(ChannelId::new(0))), ); } @@ -1384,7 +1384,7 @@ mod tests { parse_channel_ends(&components), Some(Path::ChannelEnd(ChannelEndPath( PortId::transfer(), - ChannelId::default() + ChannelId::new(0) ))), ); } @@ -1398,7 +1398,7 @@ mod tests { parse_seqs(&components), Some(Path::SeqSend(SeqSendPath( PortId::transfer(), - ChannelId::default() + ChannelId::new(0) ))), ); @@ -1409,7 +1409,7 @@ mod tests { parse_seqs(&components), Some(Path::SeqRecv(SeqRecvPath( PortId::transfer(), - ChannelId::default() + ChannelId::new(0) ))), ); @@ -1420,7 +1420,7 @@ mod tests { parse_seqs(&components), Some(Path::SeqAck(SeqAckPath( PortId::transfer(), - ChannelId::default() + ChannelId::new(0) ))), ); } @@ -1434,7 +1434,7 @@ mod tests { parse_commitments(&components), Some(Path::Commitment(CommitmentPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), + channel_id: ChannelId::new(0), sequence: Sequence::default(), })), ); @@ -1449,7 +1449,7 @@ mod tests { parse_acks(&components), Some(Path::Ack(AckPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), + channel_id: ChannelId::new(0), sequence: Sequence::default(), })), ); @@ -1464,7 +1464,7 @@ mod tests { parse_receipts(&components), Some(Path::Receipt(ReceiptPath { port_id: PortId::transfer(), - channel_id: ChannelId::default(), + channel_id: ChannelId::new(0), sequence: Sequence::default(), })), ); diff --git a/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs b/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs index 650c735ac..15476e098 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs @@ -10,7 +10,7 @@ use crate::fixtures::core::signer::dummy_bech32_account; pub fn dummy_raw_msg_chan_close_confirm(proof_height: u64) -> RawMsgChannelCloseConfirm { RawMsgChannelCloseConfirm { port_id: PortId::transfer().to_string(), - channel_id: ChannelId::default().to_string(), + channel_id: ChannelId::new(0).to_string(), proof_init: dummy_proof(), proof_height: Some(Height { revision_number: 0, diff --git a/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs b/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs index dd770443d..02a613e61 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs @@ -8,7 +8,7 @@ use crate::fixtures::core::signer::dummy_bech32_account; pub fn dummy_raw_msg_chan_close_init() -> RawMsgChannelCloseInit { RawMsgChannelCloseInit { port_id: PortId::transfer().to_string(), - channel_id: ChannelId::default().to_string(), + channel_id: ChannelId::new(0).to_string(), signer: dummy_bech32_account(), } } diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs index 8b9a0b952..cde483a66 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs @@ -10,8 +10,8 @@ use crate::fixtures::core::signer::dummy_bech32_account; pub fn dummy_raw_msg_chan_open_ack(proof_height: u64) -> RawMsgChannelOpenAck { RawMsgChannelOpenAck { port_id: PortId::transfer().to_string(), - channel_id: ChannelId::default().to_string(), - counterparty_channel_id: ChannelId::default().to_string(), + channel_id: ChannelId::new(0).to_string(), + counterparty_channel_id: ChannelId::new(0).to_string(), counterparty_version: "".to_string(), proof_try: dummy_proof(), proof_height: Some(Height { diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs index dfb1c797e..6c3498e0a 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs @@ -10,7 +10,7 @@ use crate::fixtures::core::signer::dummy_bech32_account; pub fn dummy_raw_msg_chan_open_confirm(proof_height: u64) -> RawMsgChannelOpenConfirm { RawMsgChannelOpenConfirm { port_id: PortId::transfer().to_string(), - channel_id: ChannelId::default().to_string(), + channel_id: ChannelId::new(0).to_string(), proof_ack: dummy_proof(), proof_height: Some(Height { revision_number: 0, diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index 056936fd1..fcb275c13 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -128,7 +128,7 @@ fn ack_success_no_packet_commitment(fixture: Fixture) { ) .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::new(0), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a); @@ -163,7 +163,7 @@ fn ack_success_happy_path(fixture: Fixture) { ) .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::new(0), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a) @@ -206,7 +206,7 @@ fn ack_unordered_chan_execute(fixture: Fixture) { let mut ctx = ctx .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::new(0), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a) @@ -245,11 +245,7 @@ fn ack_ordered_chan_execute(fixture: Fixture) { .. } = fixture; let mut ctx = ctx - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a_ordered, - ) + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a_ordered) .with_connection(ConnectionId::default(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs index f01b4adfd..ed20fc280 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs @@ -54,7 +54,7 @@ fn fixture() -> Fixture { let chan_end_on_b = ChannelEnd::new( State::TryOpen, Order::Unordered, - Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::default())), + Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::new(0))), vec![conn_id_on_b.clone()], Version::default(), ) @@ -94,11 +94,7 @@ fn chan_open_confirm_validate_happy_path(fixture: Fixture) { .build(), ) .with_connection(conn_id_on_b, conn_end_on_b) - .with_channel( - msg.port_id_on_b.clone(), - ChannelId::default(), - chan_end_on_b, - ); + .with_channel(msg.port_id_on_b.clone(), ChannelId::new(0), chan_end_on_b); let msg_envelope = MsgEnvelope::from(ChannelMsg::from(msg)); @@ -129,11 +125,7 @@ fn chan_open_confirm_execute_happy_path(fixture: Fixture) { .build(), ) .with_connection(conn_id_on_b, conn_end_on_b) - .with_channel( - msg.port_id_on_b.clone(), - ChannelId::default(), - chan_end_on_b, - ); + .with_channel(msg.port_id_on_b.clone(), ChannelId::new(0), chan_end_on_b); let msg_envelope = MsgEnvelope::from(ChannelMsg::from(msg)); @@ -200,7 +192,7 @@ fn chan_open_confirm_fail_channel_wrong_state(fixture: Fixture) { let wrong_chan_end = ChannelEnd::new( State::Init, Order::Unordered, - Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::default())), + Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::new(0))), vec![conn_id_on_b.clone()], Version::default(), ) @@ -213,11 +205,7 @@ fn chan_open_confirm_fail_channel_wrong_state(fixture: Fixture) { .build(), ) .with_connection(conn_id_on_b, conn_end_on_b) - .with_channel( - msg.port_id_on_b.clone(), - ChannelId::default(), - wrong_chan_end, - ); + .with_channel(msg.port_id_on_b.clone(), ChannelId::new(0), wrong_chan_end); let msg_envelope = MsgEnvelope::from(ChannelMsg::from(msg)); diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index 47a3e737e..9bb56975d 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -174,9 +174,9 @@ fn recv_packet_timeout_expired(fixture: Fixture) { let packet_old = Packet { seq_on_a: 1.into(), port_id_on_a: PortId::transfer(), - chan_id_on_a: ChannelId::default(), + chan_id_on_a: ChannelId::new(0), port_id_on_b: PortId::transfer(), - chan_id_on_b: ChannelId::default(), + chan_id_on_b: ChannelId::new(0), data: Vec::new(), timeout_height_on_b: client_height.into(), timeout_timestamp_on_b: Timestamp::from_nanoseconds(1).unwrap(), @@ -198,8 +198,8 @@ fn recv_packet_timeout_expired(fixture: Fixture) { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_b) - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_b) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()) + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_b) + .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()) .with_height(host_height); let res = validate(&context, &router, msg_envelope); @@ -228,7 +228,7 @@ fn recv_packet_execute_happy_path(fixture: Fixture) { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_b) - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_b); + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_b); let msg_env = MsgEnvelope::from(PacketMsg::from(msg)); diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 9d2befbd1..8c1689cf5 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -31,7 +31,7 @@ fn send_packet_processing() { let chan_end_on_a = ChannelEnd::new( State::Open, Order::Unordered, - Counterparty::new(PortId::transfer(), Some(ChannelId::default())), + Counterparty::new(PortId::transfer(), Some(ChannelId::new(0))), vec![ConnectionId::default()], Version::new("ics20-1".to_string()), ) @@ -98,12 +98,8 @@ fn send_packet_processing() { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a.clone()) - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a.clone(), - ) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()), + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a.clone()) + .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()), packet, want_pass: true, }, @@ -117,12 +113,8 @@ fn send_packet_processing() { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a.clone()) - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a.clone(), - ) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()), + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a.clone()) + .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()), packet: packet_timeout_equal_client_height, want_pass: true, }, @@ -136,12 +128,8 @@ fn send_packet_processing() { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a.clone()) - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a.clone(), - ) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()), + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a.clone()) + .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()), packet: packet_timeout_one_before_client_height, want_pass: false, }, @@ -154,8 +142,8 @@ fn send_packet_processing() { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a) - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_a) - .with_send_sequence(PortId::transfer(), ChannelId::default(), 1.into()), + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a) + .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()), packet: packet_with_timestamp_old, want_pass: false, }, diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 55d964b68..035a467f6 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -139,7 +139,7 @@ fn timeout_fail_no_consensus_state_for_height(fixture: Fixture) { let ctx = ctx .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::new(0), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a) @@ -193,7 +193,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { .with_connection(ConnectionId::default(), conn_end_on_a) .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::new(0), chan_end_on_a_unordered, ) .with_packet_commitment( @@ -235,7 +235,7 @@ fn timeout_success_no_packet_commitment(fixture: Fixture) { let ctx = ctx .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::new(0), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a); @@ -274,7 +274,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { .with_connection(ConnectionId::default(), conn_end_on_a) .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::new(0), chan_end_on_a_unordered, ) .with_packet_commitment( @@ -322,11 +322,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a) - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a_ordered, - ) + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a_ordered) .with_packet_commitment( packet.port_id_on_a, packet.chan_id_on_a, @@ -363,7 +359,7 @@ fn timeout_unordered_chan_execute(fixture: Fixture) { let mut ctx = ctx .with_channel( PortId::transfer(), - ChannelId::default(), + ChannelId::new(0), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a) @@ -403,11 +399,7 @@ fn timeout_ordered_chan_execute(fixture: Fixture) { .. } = fixture; let mut ctx = ctx - .with_channel( - PortId::transfer(), - ChannelId::default(), - chan_end_on_a_ordered, - ) + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a_ordered) .with_connection(ConnectionId::default(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), diff --git a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs index c0321e8b1..e6bc9e650 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -115,7 +115,7 @@ fn timeout_on_close_success_no_packet_commitment(fixture: Fixture) { .. } = fixture; let context = context - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_a) + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a) .with_connection(ConnectionId::default(), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -140,7 +140,7 @@ fn timeout_on_close_success_happy_path(fixture: Fixture) { .. } = fixture; let mut context = context - .with_channel(PortId::transfer(), ChannelId::default(), chan_end_on_a) + .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a) .with_connection(ConnectionId::default(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), From 526acde97182f3e6149470af33992a05b77e9aec Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Mon, 26 Feb 2024 14:20:05 +0700 Subject: [PATCH 05/34] fix: Version::default() to Version::empty() --- ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/chan_close_init.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs index 6b8668bcf..b430b8c00 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs @@ -48,7 +48,7 @@ fn test_chan_close_confirm_validate() { Some(msg_chan_close_confirm.chan_id_on_b.clone()), ), vec![conn_id.clone()], - Version::default(), + Version::empty(), ) .unwrap(); @@ -107,7 +107,7 @@ fn test_chan_close_confirm_execute() { Some(msg_chan_close_confirm.chan_id_on_b.clone()), ), vec![conn_id.clone()], - Version::default(), + Version::empty(), ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs index 4e7331d54..c1ca85865 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs @@ -44,7 +44,7 @@ fn test_chan_close_init_validate() { Some(msg_chan_close_init.chan_id_on_a.clone()), ), vec![conn_id.clone()], - Version::default(), + Version::empty(), ) .unwrap(); @@ -104,7 +104,7 @@ fn test_chan_close_init_execute() { Some(msg_chan_close_init.chan_id_on_a.clone()), ), vec![conn_id.clone()], - Version::default(), + Version::empty(), ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs index ed20fc280..7ca6542a7 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs @@ -56,7 +56,7 @@ fn fixture() -> Fixture { Order::Unordered, Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::new(0))), vec![conn_id_on_b.clone()], - Version::default(), + Version::empty(), ) .unwrap(); @@ -194,7 +194,7 @@ fn chan_open_confirm_fail_channel_wrong_state(fixture: Fixture) { Order::Unordered, Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::new(0))), vec![conn_id_on_b.clone()], - Version::default(), + Version::empty(), ) .unwrap(); let context = context From f4f0daec24483f5137753e8b01c7231a2a30806a Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Mon, 26 Feb 2024 14:33:10 +0700 Subject: [PATCH 06/34] remove derive default from Timestamp --- ibc-primitives/src/types/timestamp.rs | 4 ++-- ibc-testkit/src/testapp/ibc/clients/mock/header.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ibc-primitives/src/types/timestamp.rs b/ibc-primitives/src/types/timestamp.rs index c7d8e5aae..af1991b86 100644 --- a/ibc-primitives/src/types/timestamp.rs +++ b/ibc-primitives/src/types/timestamp.rs @@ -24,7 +24,7 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0); /// of timestamp. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(PartialEq, Eq, Copy, Clone, Debug, Default, PartialOrd, Ord, Hash)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, PartialOrd, Ord, Hash)] pub struct Timestamp { // Note: The schema representation is the timestamp in nanoseconds (as we do with borsh). #[cfg_attr(feature = "schema", schemars(with = "u64"))] @@ -170,7 +170,7 @@ impl Timestamp { /// let ti = Timestamp::from_nanoseconds(min).unwrap(); /// let uti = ti.nanoseconds(); /// assert_eq!(uti, min); - /// let tz = Timestamp::default(); + /// let tz = Timestamp::none(); /// let utz = tz.nanoseconds(); /// assert_eq!(utz, 0); /// ``` diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs index 072b7bba7..a861ac311 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs @@ -21,7 +21,7 @@ impl Default for MockHeader { fn default() -> Self { Self { height: Height::min(0), - timestamp: Default::default(), + timestamp: Timestamp::none(), } } } From 000959eb875c2215bfeae17bd240ab1800132e98 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Mon, 26 Feb 2024 14:33:36 +0700 Subject: [PATCH 07/34] refactor default builder --- ibc-testkit/src/fixtures/applications/transfer.rs | 8 ++++---- ibc-testkit/src/fixtures/core/channel/packet.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ibc-testkit/src/fixtures/applications/transfer.rs b/ibc-testkit/src/fixtures/applications/transfer.rs index b352f1a42..069e75ae4 100644 --- a/ibc-testkit/src/fixtures/applications/transfer.rs +++ b/ibc-testkit/src/fixtures/applications/transfer.rs @@ -17,12 +17,12 @@ use crate::fixtures::core::signer::dummy_account_id; pub struct MsgTransferConfig { #[builder(default = PortId::transfer())] pub port_id_on_a: PortId, - #[builder(default)] + #[builder(default = ChannelId::new(0))] pub chan_id_on_a: ChannelId, pub packet_data: PacketData, - #[builder(default)] + #[builder(default = TimeoutHeight::Never)] pub timeout_height_on_b: TimeoutHeight, - #[builder(default)] + #[builder(default = Timestamp::none())] pub timeout_timestamp_on_b: Timestamp, } @@ -47,7 +47,7 @@ pub fn extract_transfer_packet(msg: &MsgTransfer, sequence: Sequence) -> Packet port_id_on_a: msg.port_id_on_a.clone(), chan_id_on_a: msg.chan_id_on_a.clone(), port_id_on_b: PortId::transfer(), - chan_id_on_b: ChannelId::default(), + chan_id_on_b: ChannelId::new(0), data, timeout_height_on_b: msg.timeout_height_on_b, timeout_timestamp_on_b: msg.timeout_timestamp_on_b, diff --git a/ibc-testkit/src/fixtures/core/channel/packet.rs b/ibc-testkit/src/fixtures/core/channel/packet.rs index 1161dae40..13b6d7974 100644 --- a/ibc-testkit/src/fixtures/core/channel/packet.rs +++ b/ibc-testkit/src/fixtures/core/channel/packet.rs @@ -15,17 +15,17 @@ pub struct PacketConfig { pub seq_on_a: Sequence, #[builder(default = PortId::transfer())] pub port_id_on_a: PortId, - #[builder(default)] + #[builder(default = ChannelId::new(0))] pub chan_id_on_a: ChannelId, #[builder(default = PortId::transfer())] pub port_id_on_b: PortId, - #[builder(default)] + #[builder(default = ChannelId::new(0))] pub chan_id_on_b: ChannelId, #[builder(default)] pub data: Vec, - #[builder(default)] + #[builder(default = TimeoutHeight::Never)] pub timeout_height_on_b: TimeoutHeight, - #[builder(default)] + #[builder(default = Timestamp::none())] pub timeout_timestamp_on_b: Timestamp, } @@ -49,9 +49,9 @@ pub fn dummy_raw_packet(timeout_height: u64, timeout_timestamp: u64) -> RawPacke RawPacket { sequence: 1, source_port: PortId::transfer().to_string(), - source_channel: ChannelId::default().to_string(), + source_channel: ChannelId::new(0).to_string(), destination_port: PortId::transfer().to_string(), - destination_channel: ChannelId::default().to_string(), + destination_channel: ChannelId::new(0).to_string(), data: vec![0], timeout_height: Some(RawHeight { revision_number: 0, From 2cb08081230260c1b18adea8ff4b664f8f35117d Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Mon, 26 Feb 2024 15:55:01 +0700 Subject: [PATCH 08/34] remove Sequence::default() --- .../ics24-host/types/src/identifiers/sequence.rs | 2 +- ibc-core/ics24-host/types/src/path.rs | 14 +++++++------- ibc-testkit/src/fixtures/core/channel/packet.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ibc-core/ics24-host/types/src/identifiers/sequence.rs b/ibc-core/ics24-host/types/src/identifiers/sequence.rs index 7919ba56e..9e8b2ccbc 100644 --- a/ibc-core/ics24-host/types/src/identifiers/sequence.rs +++ b/ibc-core/ics24-host/types/src/identifiers/sequence.rs @@ -17,7 +17,7 @@ use crate::error::IdentifierError; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] /// The sequence number of a packet enforces ordering among packets from the same source. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Sequence(u64); impl core::str::FromStr for Sequence { diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index b695a0747..a47fd23c3 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1238,7 +1238,7 @@ mod tests { Path::Commitment(CommitmentPath { port_id: PortId::transfer(), channel_id: ChannelId::new(0), - sequence: Sequence::default(), + sequence: Sequence::from(0), }) )] #[case( @@ -1246,7 +1246,7 @@ mod tests { Path::Ack(AckPath { port_id: PortId::transfer(), channel_id: ChannelId::new(0), - sequence: Sequence::default(), + sequence: Sequence::from(0), }) )] #[case( @@ -1254,7 +1254,7 @@ mod tests { Path::Receipt(ReceiptPath { port_id: PortId::transfer(), channel_id: ChannelId::new(0), - sequence: Sequence::default(), + sequence: Sequence::from(0), }) )] #[case( @@ -1371,7 +1371,7 @@ mod tests { assert_eq!( parse_sequences(&components), - Some(SubPath::Sequences(Sequence::default())) + Some(SubPath::Sequences(Sequence::from(0))) ); } @@ -1435,7 +1435,7 @@ mod tests { Some(Path::Commitment(CommitmentPath { port_id: PortId::transfer(), channel_id: ChannelId::new(0), - sequence: Sequence::default(), + sequence: Sequence::from(0), })), ); } @@ -1450,7 +1450,7 @@ mod tests { Some(Path::Ack(AckPath { port_id: PortId::transfer(), channel_id: ChannelId::new(0), - sequence: Sequence::default(), + sequence: Sequence::from(0), })), ); } @@ -1465,7 +1465,7 @@ mod tests { Some(Path::Receipt(ReceiptPath { port_id: PortId::transfer(), channel_id: ChannelId::new(0), - sequence: Sequence::default(), + sequence: Sequence::from(0), })), ); } diff --git a/ibc-testkit/src/fixtures/core/channel/packet.rs b/ibc-testkit/src/fixtures/core/channel/packet.rs index 13b6d7974..f5c466405 100644 --- a/ibc-testkit/src/fixtures/core/channel/packet.rs +++ b/ibc-testkit/src/fixtures/core/channel/packet.rs @@ -11,7 +11,7 @@ use typed_builder::TypedBuilder; #[derive(TypedBuilder, Debug)] #[builder(build_method(into = Packet))] pub struct PacketConfig { - #[builder(default)] + #[builder(default = Sequence::from(0))] pub seq_on_a: Sequence, #[builder(default = PortId::transfer())] pub port_id_on_a: PortId, From 6a31d851b57b0566d04615c3d37776bd647a13d2 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Mon, 26 Feb 2024 16:03:25 +0700 Subject: [PATCH 09/34] remove Memo::default() --- .../src/handler/send_transfer.rs | 23 +++++++++++++++---- ibc-apps/ics721-nft-transfer/src/module.rs | 7 +++--- .../ics721-nft-transfer/types/src/memo.rs | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs b/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs index 270164701..539c7de7d 100644 --- a/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs +++ b/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs @@ -1,3 +1,4 @@ +use ibc_app_nft_transfer_types::Memo; use ibc_core::channel::context::{SendPacketExecutionContext, SendPacketValidationContext}; use ibc_core::channel::handler::{send_packet_execute, send_packet_validate}; use ibc_core::channel::types::packet::Packet; @@ -81,14 +82,20 @@ where &msg.chan_id_on_a, class_id, token_id, - &packet_data.memo.clone().unwrap_or_default(), + &packet_data + .memo + .clone() + .unwrap_or(Memo::from("".to_string())), )?; } else { transfer_ctx.burn_nft_validate( &sender, class_id, token_id, - &packet_data.memo.clone().unwrap_or_default(), + &packet_data + .memo + .clone() + .unwrap_or(Memo::from("".to_string())), )?; } let nft = transfer_ctx.get_nft(class_id, token_id)?; @@ -184,14 +191,20 @@ where &msg.chan_id_on_a, class_id, token_id, - &packet_data.memo.clone().unwrap_or_default(), + &packet_data + .memo + .clone() + .unwrap_or(Memo::from("".to_string())), )?; } else { transfer_ctx.burn_nft_execute( &sender, class_id, token_id, - &packet_data.memo.clone().unwrap_or_default(), + &packet_data + .memo + .clone() + .unwrap_or(Memo::from("".to_string())), )?; } let nft = transfer_ctx.get_nft(class_id, token_id)?; @@ -242,7 +255,7 @@ where receiver: packet_data.receiver, class: packet_data.class_id, tokens: packet_data.token_ids, - memo: packet_data.memo.unwrap_or_default(), + memo: packet_data.memo.unwrap_or(Memo::from("".to_string())), }; send_packet_ctx_a.emit_ibc_event(ModuleEvent::from(transfer_event).into())?; diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index 87fdfc637..612040922 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -1,5 +1,6 @@ //! Provides IBC module callbacks implementation for the ICS-721 transfer. +use ibc_app_nft_transfer_types::Memo; use ibc_core::channel::types::acknowledgement::{Acknowledgement, AcknowledgementStatus}; use ibc_core::channel::types::channel::{Counterparty, Order}; use ibc_core::channel::types::packet::Packet; @@ -194,7 +195,7 @@ pub fn on_recv_packet_execute( receiver: data.receiver, class: data.class_id, tokens: data.token_ids, - memo: data.memo.unwrap_or_default(), + memo: data.memo.unwrap_or(Memo::from("".to_string())), success: ack.is_successful(), }; extras.events.push(recv_event.into()); @@ -259,7 +260,7 @@ pub fn on_acknowledgement_packet_execute( receiver: data.receiver, class: data.class_id, tokens: data.token_ids, - memo: data.memo.unwrap_or_default(), + memo: data.memo.unwrap_or(Memo::from("".to_string())), acknowledgement: acknowledgement.clone(), }; @@ -307,7 +308,7 @@ pub fn on_timeout_packet_execute( refund_receiver: data.sender, refund_class: data.class_id, refund_tokens: data.token_ids, - memo: data.memo.unwrap_or_default(), + memo: data.memo.unwrap_or(Memo::from("".to_string())), }; let extras = ModuleExtras { diff --git a/ibc-apps/ics721-nft-transfer/types/src/memo.rs b/ibc-apps/ics721-nft-transfer/types/src/memo.rs index 432dd4fc6..9db8e4e11 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/memo.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/memo.rs @@ -24,7 +24,7 @@ use ibc_core::primitives::prelude::*; )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Memo(String); impl AsRef for Memo { From bab6785b5a7248f70f9e2e21b9123ec690d7baa3 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Thu, 29 Feb 2024 23:50:02 +0700 Subject: [PATCH 10/34] refactor: add ChannelId::zero() --- .../ics04-channel/types/src/events/mod.rs | 2 +- .../types/src/identifiers/channel_id.rs | 4 +++ ibc-core/ics24-host/types/src/path.rs | 30 +++++++++---------- .../src/fixtures/applications/transfer.rs | 4 +-- .../core/channel/chan_close_confirm.rs | 2 +- .../fixtures/core/channel/chan_close_init.rs | 2 +- .../fixtures/core/channel/chan_open_ack.rs | 4 +-- .../core/channel/chan_open_confirm.rs | 2 +- .../src/fixtures/core/channel/packet.rs | 8 ++--- .../core/ics04_channel/acknowledgement.rs | 8 ++--- .../core/ics04_channel/chan_open_confirm.rs | 10 +++---- .../tests/core/ics04_channel/recv_packet.rs | 10 +++---- .../tests/core/ics04_channel/send_packet.rs | 18 +++++------ .../tests/core/ics04_channel/timeout.rs | 14 ++++----- .../core/ics04_channel/timeout_on_close.rs | 4 +-- 15 files changed, 63 insertions(+), 59 deletions(-) diff --git a/ibc-core/ics04-channel/types/src/events/mod.rs b/ibc-core/ics04-channel/types/src/events/mod.rs index 606d248db..03dd36723 100644 --- a/ibc-core/ics04-channel/types/src/events/mod.rs +++ b/ibc-core/ics04-channel/types/src/events/mod.rs @@ -1132,7 +1132,7 @@ mod tests { } let port_id = PortId::transfer(); - let channel_id = ChannelId::new(0); + let channel_id = ChannelId::zero(); let connection_id = ConnectionId::new(0); let counterparty_port_id = PortId::transfer(); let counterparty_channel_id = ChannelId::new(1); diff --git a/ibc-core/ics24-host/types/src/identifiers/channel_id.rs b/ibc-core/ics24-host/types/src/identifiers/channel_id.rs index 1f986c831..5d4583dc6 100644 --- a/ibc-core/ics24-host/types/src/identifiers/channel_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/channel_id.rs @@ -57,6 +57,10 @@ impl ChannelId { pub fn as_bytes(&self) -> &[u8] { self.0.as_bytes() } + + pub fn zero() -> Self { + Self::new(0) + } } /// This implementation provides a `to_string` method. diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index a47fd23c3..a3d0ca775 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1219,25 +1219,25 @@ mod tests { #[case("ports/transfer", Path::Ports(PortPath(PortId::transfer())))] #[case( "channelEnds/ports/transfer/channels/channel-0", - Path::ChannelEnd(ChannelEndPath(PortId::transfer(), ChannelId::new(0))) + Path::ChannelEnd(ChannelEndPath(PortId::transfer(), ChannelId::zero())) )] #[case( "nextSequenceSend/ports/transfer/channels/channel-0", - Path::SeqSend(SeqSendPath(PortId::transfer(), ChannelId::new(0))) + Path::SeqSend(SeqSendPath(PortId::transfer(), ChannelId::zero())) )] #[case( "nextSequenceRecv/ports/transfer/channels/channel-0", - Path::SeqRecv(SeqRecvPath(PortId::transfer(), ChannelId::new(0))) + Path::SeqRecv(SeqRecvPath(PortId::transfer(), ChannelId::zero())) )] #[case( "nextSequenceAck/ports/transfer/channels/channel-0", - Path::SeqAck(SeqAckPath(PortId::transfer(), ChannelId::new(0))) + Path::SeqAck(SeqAckPath(PortId::transfer(), ChannelId::zero())) )] #[case( "commitments/ports/transfer/channels/channel-0/sequences/0", Path::Commitment(CommitmentPath { port_id: PortId::transfer(), - channel_id: ChannelId::new(0), + channel_id: ChannelId::zero(), sequence: Sequence::from(0), }) )] @@ -1245,7 +1245,7 @@ mod tests { "acks/ports/transfer/channels/channel-0/sequences/0", Path::Ack(AckPath { port_id: PortId::transfer(), - channel_id: ChannelId::new(0), + channel_id: ChannelId::zero(), sequence: Sequence::from(0), }) )] @@ -1253,7 +1253,7 @@ mod tests { "receipts/ports/transfer/channels/channel-0/sequences/0", Path::Receipt(ReceiptPath { port_id: PortId::transfer(), - channel_id: ChannelId::new(0), + channel_id: ChannelId::zero(), sequence: Sequence::from(0), }) )] @@ -1360,7 +1360,7 @@ mod tests { assert_eq!( parse_channels(&components), - Some(SubPath::Channels(ChannelId::new(0))), + Some(SubPath::Channels(ChannelId::zero())), ); } @@ -1384,7 +1384,7 @@ mod tests { parse_channel_ends(&components), Some(Path::ChannelEnd(ChannelEndPath( PortId::transfer(), - ChannelId::new(0) + ChannelId::zero() ))), ); } @@ -1398,7 +1398,7 @@ mod tests { parse_seqs(&components), Some(Path::SeqSend(SeqSendPath( PortId::transfer(), - ChannelId::new(0) + ChannelId::zero() ))), ); @@ -1409,7 +1409,7 @@ mod tests { parse_seqs(&components), Some(Path::SeqRecv(SeqRecvPath( PortId::transfer(), - ChannelId::new(0) + ChannelId::zero() ))), ); @@ -1420,7 +1420,7 @@ mod tests { parse_seqs(&components), Some(Path::SeqAck(SeqAckPath( PortId::transfer(), - ChannelId::new(0) + ChannelId::zero() ))), ); } @@ -1434,7 +1434,7 @@ mod tests { parse_commitments(&components), Some(Path::Commitment(CommitmentPath { port_id: PortId::transfer(), - channel_id: ChannelId::new(0), + channel_id: ChannelId::zero(), sequence: Sequence::from(0), })), ); @@ -1449,7 +1449,7 @@ mod tests { parse_acks(&components), Some(Path::Ack(AckPath { port_id: PortId::transfer(), - channel_id: ChannelId::new(0), + channel_id: ChannelId::zero(), sequence: Sequence::from(0), })), ); @@ -1464,7 +1464,7 @@ mod tests { parse_receipts(&components), Some(Path::Receipt(ReceiptPath { port_id: PortId::transfer(), - channel_id: ChannelId::new(0), + channel_id: ChannelId::zero(), sequence: Sequence::from(0), })), ); diff --git a/ibc-testkit/src/fixtures/applications/transfer.rs b/ibc-testkit/src/fixtures/applications/transfer.rs index 069e75ae4..f9e0d0c86 100644 --- a/ibc-testkit/src/fixtures/applications/transfer.rs +++ b/ibc-testkit/src/fixtures/applications/transfer.rs @@ -17,7 +17,7 @@ use crate::fixtures::core::signer::dummy_account_id; pub struct MsgTransferConfig { #[builder(default = PortId::transfer())] pub port_id_on_a: PortId, - #[builder(default = ChannelId::new(0))] + #[builder(default = ChannelId::zero())] pub chan_id_on_a: ChannelId, pub packet_data: PacketData, #[builder(default = TimeoutHeight::Never)] @@ -47,7 +47,7 @@ pub fn extract_transfer_packet(msg: &MsgTransfer, sequence: Sequence) -> Packet port_id_on_a: msg.port_id_on_a.clone(), chan_id_on_a: msg.chan_id_on_a.clone(), port_id_on_b: PortId::transfer(), - chan_id_on_b: ChannelId::new(0), + chan_id_on_b: ChannelId::zero(), data, timeout_height_on_b: msg.timeout_height_on_b, timeout_timestamp_on_b: msg.timeout_timestamp_on_b, diff --git a/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs b/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs index 15476e098..df833f545 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_close_confirm.rs @@ -10,7 +10,7 @@ use crate::fixtures::core::signer::dummy_bech32_account; pub fn dummy_raw_msg_chan_close_confirm(proof_height: u64) -> RawMsgChannelCloseConfirm { RawMsgChannelCloseConfirm { port_id: PortId::transfer().to_string(), - channel_id: ChannelId::new(0).to_string(), + channel_id: ChannelId::zero().to_string(), proof_init: dummy_proof(), proof_height: Some(Height { revision_number: 0, diff --git a/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs b/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs index 02a613e61..89956ddab 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_close_init.rs @@ -8,7 +8,7 @@ use crate::fixtures::core::signer::dummy_bech32_account; pub fn dummy_raw_msg_chan_close_init() -> RawMsgChannelCloseInit { RawMsgChannelCloseInit { port_id: PortId::transfer().to_string(), - channel_id: ChannelId::new(0).to_string(), + channel_id: ChannelId::zero().to_string(), signer: dummy_bech32_account(), } } diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs index cde483a66..2b89bd3b4 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_ack.rs @@ -10,8 +10,8 @@ use crate::fixtures::core::signer::dummy_bech32_account; pub fn dummy_raw_msg_chan_open_ack(proof_height: u64) -> RawMsgChannelOpenAck { RawMsgChannelOpenAck { port_id: PortId::transfer().to_string(), - channel_id: ChannelId::new(0).to_string(), - counterparty_channel_id: ChannelId::new(0).to_string(), + channel_id: ChannelId::zero().to_string(), + counterparty_channel_id: ChannelId::zero().to_string(), counterparty_version: "".to_string(), proof_try: dummy_proof(), proof_height: Some(Height { diff --git a/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs b/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs index 6c3498e0a..3871fc9f2 100644 --- a/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs +++ b/ibc-testkit/src/fixtures/core/channel/chan_open_confirm.rs @@ -10,7 +10,7 @@ use crate::fixtures::core::signer::dummy_bech32_account; pub fn dummy_raw_msg_chan_open_confirm(proof_height: u64) -> RawMsgChannelOpenConfirm { RawMsgChannelOpenConfirm { port_id: PortId::transfer().to_string(), - channel_id: ChannelId::new(0).to_string(), + channel_id: ChannelId::zero().to_string(), proof_ack: dummy_proof(), proof_height: Some(Height { revision_number: 0, diff --git a/ibc-testkit/src/fixtures/core/channel/packet.rs b/ibc-testkit/src/fixtures/core/channel/packet.rs index f5c466405..c4debd594 100644 --- a/ibc-testkit/src/fixtures/core/channel/packet.rs +++ b/ibc-testkit/src/fixtures/core/channel/packet.rs @@ -15,11 +15,11 @@ pub struct PacketConfig { pub seq_on_a: Sequence, #[builder(default = PortId::transfer())] pub port_id_on_a: PortId, - #[builder(default = ChannelId::new(0))] + #[builder(default = ChannelId::zero())] pub chan_id_on_a: ChannelId, #[builder(default = PortId::transfer())] pub port_id_on_b: PortId, - #[builder(default = ChannelId::new(0))] + #[builder(default = ChannelId::zero())] pub chan_id_on_b: ChannelId, #[builder(default)] pub data: Vec, @@ -49,9 +49,9 @@ pub fn dummy_raw_packet(timeout_height: u64, timeout_timestamp: u64) -> RawPacke RawPacket { sequence: 1, source_port: PortId::transfer().to_string(), - source_channel: ChannelId::new(0).to_string(), + source_channel: ChannelId::zero().to_string(), destination_port: PortId::transfer().to_string(), - destination_channel: ChannelId::new(0).to_string(), + destination_channel: ChannelId::zero().to_string(), data: vec![0], timeout_height: Some(RawHeight { revision_number: 0, diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index fcb275c13..cdd17f52e 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -128,7 +128,7 @@ fn ack_success_no_packet_commitment(fixture: Fixture) { ) .with_channel( PortId::transfer(), - ChannelId::new(0), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a); @@ -163,7 +163,7 @@ fn ack_success_happy_path(fixture: Fixture) { ) .with_channel( PortId::transfer(), - ChannelId::new(0), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a) @@ -206,7 +206,7 @@ fn ack_unordered_chan_execute(fixture: Fixture) { let mut ctx = ctx .with_channel( PortId::transfer(), - ChannelId::new(0), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a) @@ -245,7 +245,7 @@ fn ack_ordered_chan_execute(fixture: Fixture) { .. } = fixture; let mut ctx = ctx - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a_ordered) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) .with_connection(ConnectionId::default(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs index 7ca6542a7..a29cd244c 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs @@ -54,7 +54,7 @@ fn fixture() -> Fixture { let chan_end_on_b = ChannelEnd::new( State::TryOpen, Order::Unordered, - Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::new(0))), + Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::zero())), vec![conn_id_on_b.clone()], Version::empty(), ) @@ -94,7 +94,7 @@ fn chan_open_confirm_validate_happy_path(fixture: Fixture) { .build(), ) .with_connection(conn_id_on_b, conn_end_on_b) - .with_channel(msg.port_id_on_b.clone(), ChannelId::new(0), chan_end_on_b); + .with_channel(msg.port_id_on_b.clone(), ChannelId::zero(), chan_end_on_b); let msg_envelope = MsgEnvelope::from(ChannelMsg::from(msg)); @@ -125,7 +125,7 @@ fn chan_open_confirm_execute_happy_path(fixture: Fixture) { .build(), ) .with_connection(conn_id_on_b, conn_end_on_b) - .with_channel(msg.port_id_on_b.clone(), ChannelId::new(0), chan_end_on_b); + .with_channel(msg.port_id_on_b.clone(), ChannelId::zero(), chan_end_on_b); let msg_envelope = MsgEnvelope::from(ChannelMsg::from(msg)); @@ -192,7 +192,7 @@ fn chan_open_confirm_fail_channel_wrong_state(fixture: Fixture) { let wrong_chan_end = ChannelEnd::new( State::Init, Order::Unordered, - Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::new(0))), + Counterparty::new(msg.port_id_on_b.clone(), Some(ChannelId::zero())), vec![conn_id_on_b.clone()], Version::empty(), ) @@ -205,7 +205,7 @@ fn chan_open_confirm_fail_channel_wrong_state(fixture: Fixture) { .build(), ) .with_connection(conn_id_on_b, conn_end_on_b) - .with_channel(msg.port_id_on_b.clone(), ChannelId::new(0), wrong_chan_end); + .with_channel(msg.port_id_on_b.clone(), ChannelId::zero(), wrong_chan_end); let msg_envelope = MsgEnvelope::from(ChannelMsg::from(msg)); diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index 9bb56975d..7c9fa37b1 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -174,9 +174,9 @@ fn recv_packet_timeout_expired(fixture: Fixture) { let packet_old = Packet { seq_on_a: 1.into(), port_id_on_a: PortId::transfer(), - chan_id_on_a: ChannelId::new(0), + chan_id_on_a: ChannelId::zero(), port_id_on_b: PortId::transfer(), - chan_id_on_b: ChannelId::new(0), + chan_id_on_b: ChannelId::zero(), data: Vec::new(), timeout_height_on_b: client_height.into(), timeout_timestamp_on_b: Timestamp::from_nanoseconds(1).unwrap(), @@ -198,8 +198,8 @@ fn recv_packet_timeout_expired(fixture: Fixture) { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_b) - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_b) - .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_b) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()) .with_height(host_height); let res = validate(&context, &router, msg_envelope); @@ -228,7 +228,7 @@ fn recv_packet_execute_happy_path(fixture: Fixture) { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_b) - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_b); + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_b); let msg_env = MsgEnvelope::from(PacketMsg::from(msg)); diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 8c1689cf5..58e5cfe38 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -31,7 +31,7 @@ fn send_packet_processing() { let chan_end_on_a = ChannelEnd::new( State::Open, Order::Unordered, - Counterparty::new(PortId::transfer(), Some(ChannelId::new(0))), + Counterparty::new(PortId::transfer(), Some(ChannelId::zero())), vec![ConnectionId::default()], Version::new("ics20-1".to_string()), ) @@ -98,8 +98,8 @@ fn send_packet_processing() { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a.clone()) - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a.clone()) - .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()), + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet, want_pass: true, }, @@ -113,8 +113,8 @@ fn send_packet_processing() { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a.clone()) - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a.clone()) - .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()), + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_timeout_equal_client_height, want_pass: true, }, @@ -128,8 +128,8 @@ fn send_packet_processing() { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a.clone()) - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a.clone()) - .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()), + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_timeout_one_before_client_height, want_pass: false, }, @@ -142,8 +142,8 @@ fn send_packet_processing() { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a) - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a) - .with_send_sequence(PortId::transfer(), ChannelId::new(0), 1.into()), + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) + .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_with_timestamp_old, want_pass: false, }, diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 035a467f6..6790520b2 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -139,7 +139,7 @@ fn timeout_fail_no_consensus_state_for_height(fixture: Fixture) { let ctx = ctx .with_channel( PortId::transfer(), - ChannelId::new(0), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a) @@ -193,7 +193,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { .with_connection(ConnectionId::default(), conn_end_on_a) .with_channel( PortId::transfer(), - ChannelId::new(0), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_packet_commitment( @@ -235,7 +235,7 @@ fn timeout_success_no_packet_commitment(fixture: Fixture) { let ctx = ctx .with_channel( PortId::transfer(), - ChannelId::new(0), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a); @@ -274,7 +274,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { .with_connection(ConnectionId::default(), conn_end_on_a) .with_channel( PortId::transfer(), - ChannelId::new(0), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_packet_commitment( @@ -322,7 +322,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { .build(), ) .with_connection(ConnectionId::default(), conn_end_on_a) - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a_ordered) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) .with_packet_commitment( packet.port_id_on_a, packet.chan_id_on_a, @@ -359,7 +359,7 @@ fn timeout_unordered_chan_execute(fixture: Fixture) { let mut ctx = ctx .with_channel( PortId::transfer(), - ChannelId::new(0), + ChannelId::zero(), chan_end_on_a_unordered, ) .with_connection(ConnectionId::default(), conn_end_on_a) @@ -399,7 +399,7 @@ fn timeout_ordered_chan_execute(fixture: Fixture) { .. } = fixture; let mut ctx = ctx - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a_ordered) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) .with_connection(ConnectionId::default(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), diff --git a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs index e6bc9e650..ae930b87a 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -115,7 +115,7 @@ fn timeout_on_close_success_no_packet_commitment(fixture: Fixture) { .. } = fixture; let context = context - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) .with_connection(ConnectionId::default(), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -140,7 +140,7 @@ fn timeout_on_close_success_happy_path(fixture: Fixture) { .. } = fixture; let mut context = context - .with_channel(PortId::transfer(), ChannelId::new(0), chan_end_on_a) + .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) .with_connection(ConnectionId::default(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), From e800ea8ab2400e5d738d0112a23628f7963faa5c Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Thu, 29 Feb 2024 23:59:27 +0700 Subject: [PATCH 11/34] add From<&str> implmentation --- ibc-apps/ics20-transfer/types/src/memo.rs | 6 +++++ .../src/handler/send_transfer.rs | 22 +++++-------------- ibc-apps/ics721-nft-transfer/src/module.rs | 6 ++--- .../ics721-nft-transfer/types/src/memo.rs | 6 +++++ .../src/fixtures/applications/transfer.rs | 4 +--- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/memo.rs b/ibc-apps/ics20-transfer/types/src/memo.rs index 9a3caea74..a49c40beb 100644 --- a/ibc-apps/ics20-transfer/types/src/memo.rs +++ b/ibc-apps/ics20-transfer/types/src/memo.rs @@ -45,6 +45,12 @@ impl From for Memo { } } +impl From<&str> for Memo { + fn from(memo: &str) -> Self { + Self(memo.to_owned()) + } +} + impl FromStr for Memo { type Err = Infallible; diff --git a/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs b/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs index 539c7de7d..d192be202 100644 --- a/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs +++ b/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs @@ -82,20 +82,14 @@ where &msg.chan_id_on_a, class_id, token_id, - &packet_data - .memo - .clone() - .unwrap_or(Memo::from("".to_string())), + &packet_data.memo.clone().unwrap_or(Memo::from("")), )?; } else { transfer_ctx.burn_nft_validate( &sender, class_id, token_id, - &packet_data - .memo - .clone() - .unwrap_or(Memo::from("".to_string())), + &packet_data.memo.clone().unwrap_or(Memo::from("")), )?; } let nft = transfer_ctx.get_nft(class_id, token_id)?; @@ -191,20 +185,14 @@ where &msg.chan_id_on_a, class_id, token_id, - &packet_data - .memo - .clone() - .unwrap_or(Memo::from("".to_string())), + &packet_data.memo.clone().unwrap_or(Memo::from("")), )?; } else { transfer_ctx.burn_nft_execute( &sender, class_id, token_id, - &packet_data - .memo - .clone() - .unwrap_or(Memo::from("".to_string())), + &packet_data.memo.clone().unwrap_or(Memo::from("")), )?; } let nft = transfer_ctx.get_nft(class_id, token_id)?; @@ -255,7 +243,7 @@ where receiver: packet_data.receiver, class: packet_data.class_id, tokens: packet_data.token_ids, - memo: packet_data.memo.unwrap_or(Memo::from("".to_string())), + memo: packet_data.memo.unwrap_or(Memo::from("")), }; send_packet_ctx_a.emit_ibc_event(ModuleEvent::from(transfer_event).into())?; diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index 612040922..cc5d33b1d 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -195,7 +195,7 @@ pub fn on_recv_packet_execute( receiver: data.receiver, class: data.class_id, tokens: data.token_ids, - memo: data.memo.unwrap_or(Memo::from("".to_string())), + memo: data.memo.unwrap_or(Memo::from("")), success: ack.is_successful(), }; extras.events.push(recv_event.into()); @@ -260,7 +260,7 @@ pub fn on_acknowledgement_packet_execute( receiver: data.receiver, class: data.class_id, tokens: data.token_ids, - memo: data.memo.unwrap_or(Memo::from("".to_string())), + memo: data.memo.unwrap_or(Memo::from("")), acknowledgement: acknowledgement.clone(), }; @@ -308,7 +308,7 @@ pub fn on_timeout_packet_execute( refund_receiver: data.sender, refund_class: data.class_id, refund_tokens: data.token_ids, - memo: data.memo.unwrap_or(Memo::from("".to_string())), + memo: data.memo.unwrap_or(Memo::from("")), }; let extras = ModuleExtras { diff --git a/ibc-apps/ics721-nft-transfer/types/src/memo.rs b/ibc-apps/ics721-nft-transfer/types/src/memo.rs index 9db8e4e11..b18f2027d 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/memo.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/memo.rs @@ -45,6 +45,12 @@ impl From for Memo { } } +impl From<&str> for Memo { + fn from(memo: &str) -> Self { + Self(memo.to_owned()) + } +} + impl FromStr for Memo { type Err = Infallible; diff --git a/ibc-testkit/src/fixtures/applications/transfer.rs b/ibc-testkit/src/fixtures/applications/transfer.rs index f9e0d0c86..18b219e58 100644 --- a/ibc-testkit/src/fixtures/applications/transfer.rs +++ b/ibc-testkit/src/fixtures/applications/transfer.rs @@ -1,5 +1,3 @@ -use alloc::string::ToString; - use ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use ibc::apps::transfer::types::packet::PacketData; use ibc::apps::transfer::types::{Memo, PrefixedCoin}; @@ -63,7 +61,7 @@ pub struct PacketDataConfig { pub sender: Signer, #[builder(default = dummy_account_id())] pub receiver: Signer, - #[builder(default = Memo::from("".to_string()))] + #[builder(default = Memo::from(""))] pub memo: Memo, } From c957bd9512021b0f8a26071042dfe0420616d70e Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 9 Mar 2024 01:32:37 +0700 Subject: [PATCH 12/34] refactor(ibccore): remove ClientId::default() --- .../ics03-connection/types/src/connection.rs | 2 +- .../types/src/identifiers/client_id.rs | 6 +++--- ibc-core/ics24-host/types/src/path.rs | 20 ++++++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index d73d53930..6f5a0ccf9 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -204,7 +204,7 @@ impl Default for ConnectionEnd { fn default() -> Self { Self { state: State::Uninitialized, - client_id: Default::default(), + client_id: ClientId::from("07-tendermint-0"), counterparty: Default::default(), versions: Vec::new(), delay_period: ZERO_DURATION, diff --git a/ibc-core/ics24-host/types/src/identifiers/client_id.rs b/ibc-core/ics24-host/types/src/identifiers/client_id.rs index 62a5662d6..25304adb3 100644 --- a/ibc-core/ics24-host/types/src/identifiers/client_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/client_id.rs @@ -76,9 +76,9 @@ impl FromStr for ClientId { } } -impl Default for ClientId { - fn default() -> Self { - Self::from_str("07-tendermint-0").expect("Never fails because we use a valid client id") +impl From<&str> for ClientId { + fn from(s: &str) -> Self { + Self::from_str(s).expect("Invalid client id") } } diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index a3d0ca775..629018a03 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1182,12 +1182,12 @@ mod tests { )] #[case( "clients/07-tendermint-0/clientState", - Path::ClientState(ClientStatePath(ClientId::default())) + Path::ClientState(ClientStatePath(ClientId::from("07-tendermint-0"))) )] #[case( "clients/07-tendermint-0/consensusStates/15-31", Path::ClientConsensusState(ClientConsensusStatePath { - client_id: ClientId::default(), + client_id: ClientId::from("07-tendermint-0"), revision_number: 15, revision_height: 31, }) @@ -1195,7 +1195,7 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedTime", Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: ClientId::default(), + client_id: ClientId::from("07-tendermint-0"), revision_number: 15, revision_height: 31, }) @@ -1203,14 +1203,14 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedHeight", Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: ClientId::default(), + client_id: ClientId::from("07-tendermint-0"), revision_number: 15, revision_height: 31, }) )] #[case( "clients/07-tendermint-0/connections", - Path::ClientConnection(ClientConnectionPath(ClientId::default())) + Path::ClientConnection(ClientConnectionPath(ClientId::from("07-tendermint-0"))) )] #[case( "connections/connection-0", @@ -1288,7 +1288,9 @@ mod tests { assert_eq!( parse_client_paths(&components), - Some(Path::ClientState(ClientStatePath(ClientId::default()))) + Some(Path::ClientState(ClientStatePath(ClientId::from( + "07-tendermint-0" + )))) ); let path = "clients/07-tendermint-0/consensusStates/15-31"; @@ -1297,7 +1299,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientConsensusState(ClientConsensusStatePath { - client_id: ClientId::default(), + client_id: ClientId::from("07-tendermint-0"), revision_number: 15, revision_height: 31, })) @@ -1312,7 +1314,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: ClientId::default(), + client_id: ClientId::from("07-tendermint-0"), revision_number: 15, revision_height: 31, })) @@ -1324,7 +1326,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: ClientId::default(), + client_id: ClientId::from("07-tendermint-0"), revision_number: 15, revision_height: 31, })) From 36fba964aedc9ffec67593929ffc7cfb2602548c Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 9 Mar 2024 01:43:44 +0700 Subject: [PATCH 13/34] refactor(ibccore): remove version::Default() --- .../ics03-connection/types/src/version.rs | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/version.rs b/ibc-core/ics03-connection/types/src/version.rs index 46029c68c..b491a58d9 100644 --- a/ibc-core/ics03-connection/types/src/version.rs +++ b/ibc-core/ics03-connection/types/src/version.rs @@ -89,14 +89,14 @@ impl From for RawVersion { } } -impl Default for Version { - fn default() -> Self { - Version { - identifier: "1".to_string(), - features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], - } - } -} +// impl Default for Version { +// fn default() -> Self { +// Version { +// identifier: "1".to_string(), +// features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], +// } +// } +// } impl Display for Version { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -111,7 +111,10 @@ impl Display for Version { /// Returns the lists of supported versions pub fn get_compatible_versions() -> Vec { - vec![Version::default()] + vec![Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + }] } /// Iterates over the descending ordered set of compatible IBC versions and @@ -197,7 +200,11 @@ mod tests { fn good_versions() -> Vec { vec![ - Version::default().into(), + Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + } + .into(), RawVersion { identifier: "2".to_string(), features: get_dummy_features(), @@ -228,7 +235,10 @@ mod tests { fn overlapping() -> (Vec, Vec, Version) { ( vec![ - Version::default(), + Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + }, Version { identifier: "3".to_string(), features: get_dummy_features(), @@ -291,7 +301,11 @@ mod tests { let tests: Vec = vec![ Test { name: "Compatible versions".to_string(), - versions: vec![Version::default().into()], + versions: vec![Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + } + .into()], want_pass: true, }, Test { @@ -346,7 +360,10 @@ mod tests { name: "Compatible versions".to_string(), supported: get_compatible_versions(), counterparty: get_compatible_versions(), - picked: Ok(Version::default()), + picked: Ok(Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + }), want_pass: true, }, Test { @@ -382,7 +399,10 @@ mod tests { } #[test] fn serialize() { - let def = Version::default(); + let def = Version { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + }; let def_raw: RawVersion = def.clone().into(); let def_back = def_raw.try_into().unwrap(); assert_eq!(def, def_back); From 48656b7349d7c0b21630e04d939743d141d0be98 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 9 Mar 2024 01:44:32 +0700 Subject: [PATCH 14/34] refactor(ibccore): remove ConnectionEnd::default() --- .../ics03-connection/types/src/connection.rs | 26 +++++++++---------- ibc-core/ics03-connection/types/src/events.rs | 4 +-- .../ics23-commitment/types/src/commitment.rs | 6 ++++- .../types/src/identifiers/connection_id.rs | 10 +++---- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index 6f5a0ccf9..c642ebaa0 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -200,18 +200,6 @@ mod sealed { } } -impl Default for ConnectionEnd { - fn default() -> Self { - Self { - state: State::Uninitialized, - client_id: ClientId::from("07-tendermint-0"), - counterparty: Default::default(), - versions: Vec::new(), - delay_period: ZERO_DURATION, - } - } -} - impl Protobuf for ConnectionEnd {} impl TryFrom for ConnectionEnd { @@ -220,7 +208,17 @@ impl TryFrom for ConnectionEnd { let state = value.state.try_into()?; if state == State::Uninitialized { - return Ok(ConnectionEnd::default()); + return ConnectionEnd::new( + State::Uninitialized, + ClientId::from("07-tendermint-0"), + Counterparty::new( + ClientId::from("07-tendermint-0"), + None, + CommitmentPrefix::empty(), + ), + Vec::new(), + ZERO_DURATION, + ); } if value.client_id.is_empty() { @@ -378,7 +376,7 @@ impl ConnectionEnd { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Counterparty { pub client_id: ClientId, pub connection_id: Option, diff --git a/ibc-core/ics03-connection/types/src/events.rs b/ibc-core/ics03-connection/types/src/events.rs index 0d10512a4..7c478c21f 100644 --- a/ibc-core/ics03-connection/types/src/events.rs +++ b/ibc-core/ics03-connection/types/src/events.rs @@ -29,7 +29,7 @@ pub const COUNTERPARTY_CLIENT_ID_ATTRIBUTE_KEY: &str = "counterparty_client_id"; derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] struct Attributes { pub connection_id: ConnectionId, pub client_id: ClientId, @@ -323,7 +323,7 @@ mod tests { let client_type = ClientType::from_str("07-tendermint") .expect("never fails because it's a valid client type"); - let conn_id_on_a = ConnectionId::default(); + let conn_id_on_a = ConnectionId::new(0); let client_id_on_a = client_type.build_client_id(0); let conn_id_on_b = ConnectionId::new(1); let client_id_on_b = client_type.build_client_id(1); diff --git a/ibc-core/ics23-commitment/types/src/commitment.rs b/ibc-core/ics23-commitment/types/src/commitment.rs index e4ae8fcf0..25f4ca579 100644 --- a/ibc-core/ics23-commitment/types/src/commitment.rs +++ b/ibc-core/ics23-commitment/types/src/commitment.rs @@ -143,7 +143,7 @@ impl<'a> TryFrom<&'a CommitmentProofBytes> for MerkleProof { )] #[cfg_attr(feature = "serde", derive(serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, PartialEq, Eq, Hash, Default)] +#[derive(Clone, PartialEq, Eq, Hash)] pub struct CommitmentPrefix { bytes: Vec, } @@ -156,6 +156,10 @@ impl CommitmentPrefix { pub fn into_vec(self) -> Vec { self.bytes } + + pub fn empty() -> Self { + Self { bytes: Vec::new() } + } } impl TryFrom> for CommitmentPrefix { diff --git a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs index a0283f5f4..4c8b99adf 100644 --- a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs @@ -73,11 +73,11 @@ impl FromStr for ConnectionId { } } -impl Default for ConnectionId { - fn default() -> Self { - Self::new(0) - } -} +// impl Default for ConnectionId { +// fn default() -> Self { +// Self::new(0) +// } +// } /// Equality check against string literal (satisfies &ConnectionId == &str). /// ``` From f1c1f134a9ab5f4cc4e56021256e2d4ff435a1df Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 9 Mar 2024 01:51:11 +0700 Subject: [PATCH 15/34] refactor(ibc-apps): remove TracePath::default() --- ibc-apps/ics20-transfer/types/src/denom.rs | 11 ++++++++--- ibc-apps/ics721-nft-transfer/types/src/class.rs | 11 ++++++++--- ibc-apps/ics721-nft-transfer/types/src/data.rs | 6 +++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/denom.rs b/ibc-apps/ics20-transfer/types/src/denom.rs index c76eaf062..65b38fe67 100644 --- a/ibc-apps/ics20-transfer/types/src/denom.rs +++ b/ibc-apps/ics20-transfer/types/src/denom.rs @@ -109,7 +109,7 @@ impl Display for TracePrefix { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, From)] +#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, From)] pub struct TracePath(Vec); impl TracePath { @@ -134,6 +134,11 @@ impl TracePath { pub fn is_empty(&self) -> bool { self.0.is_empty() } + + /// Return empty trace path + pub fn empty() -> Self { + Self(vec![]) + } } impl<'a> TryFrom> for TracePath { @@ -294,7 +299,7 @@ impl FromStr for PrefixedDenom { let (base_denom, trace_path) = { if last_part == s { - (BaseDenom::from_str(s)?, TracePath::default()) + (BaseDenom::from_str(s)?, TracePath::empty()) } else { let base_denom = BaseDenom::from_str(last_part)?; let trace_path = TracePath::try_from(parts)?; @@ -334,7 +339,7 @@ impl From for RawDenomTrace { impl From for PrefixedDenom { fn from(denom: BaseDenom) -> Self { Self { - trace_path: Default::default(), + trace_path: TracePath::empty(), base_denom: denom, } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/class.rs b/ibc-apps/ics721-nft-transfer/types/src/class.rs index adbc95f92..c2ff9afd4 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/class.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/class.rs @@ -106,7 +106,7 @@ impl Display for TracePrefix { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, From)] +#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, From)] pub struct TracePath(Vec); impl TracePath { @@ -131,6 +131,11 @@ impl TracePath { pub fn is_empty(&self) -> bool { self.0.is_empty() } + + /// Return empty trace path + pub fn empty() -> Self { + Self(vec![]) + } } impl<'a> TryFrom> for TracePath { @@ -268,7 +273,7 @@ impl FromStr for PrefixedClassId { let (base_class_id, trace_path) = { if last_part == s { - (ClassId::from_str(s)?, TracePath::default()) + (ClassId::from_str(s)?, TracePath::empty()) } else { let base_class_id = ClassId::from_str(last_part)?; let trace_path = TracePath::try_from(parts)?; @@ -308,7 +313,7 @@ impl From for RawClassTrace { impl From for PrefixedClassId { fn from(class_id: ClassId) -> Self { Self { - trace_path: Default::default(), + trace_path: TracePath::empty(), base_class_id: class_id, } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/data.rs b/ibc-apps/ics721-nft-transfer/types/src/data.rs index c94e9ee31..d958c0836 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/data.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/data.rs @@ -24,7 +24,7 @@ use crate::error::NftTransferError; derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, PartialEq, Eq, derive_more::From)] +#[derive(Clone, Debug, PartialEq, Eq, derive_more::From)] pub struct Data(String); #[cfg(feature = "serde")] @@ -88,7 +88,7 @@ impl<'de> serde::Deserialize<'de> for Data { )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Ics721Data(BTreeMap); #[cfg(feature = "serde")] @@ -100,7 +100,7 @@ impl FromStr for Ics721Data { } } -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct DataValue { value: String, mime: Option, From 436703fab340525f4ba5bbf0bb63bff234521469 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 9 Mar 2024 01:55:02 +0700 Subject: [PATCH 16/34] refactor(ibc-core): remove ProofSpecs::default() --- ibc-clients/ics07-tendermint/src/client_state.rs | 2 +- ibc-clients/ics07-tendermint/types/src/client_state.rs | 2 +- ibc-core/ics23-commitment/types/src/specs.rs | 6 ------ ibc-testkit/src/fixtures/core/channel/mod.rs | 2 +- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/ibc-clients/ics07-tendermint/src/client_state.rs b/ibc-clients/ics07-tendermint/src/client_state.rs index bb9415487..07ab942e9 100644 --- a/ibc-clients/ics07-tendermint/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/src/client_state.rs @@ -112,7 +112,7 @@ mod tests { unbonding_period: Duration::new(128000, 0), max_clock_drift: Duration::new(3, 0), latest_height: Height::new(1, 10).expect("Never fails"), - proof_specs: ProofSpecs::default(), + proof_specs: ProofSpecs::cosmos(), upgrade_path: Default::default(), allow_update: AllowUpdate { after_expiry: false, diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index 5fbb53189..b401515c2 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -444,7 +444,7 @@ mod tests { unbonding_period: Duration::new(128000, 0), max_clock_drift: Duration::new(3, 0), latest_height: Height::new(0, 10).expect("Never fails"), - proof_specs: ProofSpecs::default(), + proof_specs: ProofSpecs::cosmos(), upgrade_path: Default::default(), allow_update: AllowUpdate { after_expiry: false, diff --git a/ibc-core/ics23-commitment/types/src/specs.rs b/ibc-core/ics23-commitment/types/src/specs.rs index 3c2b1df75..3db7953f2 100644 --- a/ibc-core/ics23-commitment/types/src/specs.rs +++ b/ibc-core/ics23-commitment/types/src/specs.rs @@ -25,12 +25,6 @@ impl ProofSpecs { } } -impl Default for ProofSpecs { - fn default() -> Self { - Self::cosmos() - } -} - impl From> for ProofSpecs { fn from(ics23_specs: Vec) -> Self { Self( diff --git a/ibc-testkit/src/fixtures/core/channel/mod.rs b/ibc-testkit/src/fixtures/core/channel/mod.rs index 0f0df1bf4..fc69b7dbe 100644 --- a/ibc-testkit/src/fixtures/core/channel/mod.rs +++ b/ibc-testkit/src/fixtures/core/channel/mod.rs @@ -46,7 +46,7 @@ pub fn dummy_raw_channel_end(state: i32, channel_id: Option) -> RawChannel state, ordering: 2, counterparty: Some(dummy_raw_counterparty_chan(channel_id)), - connection_hops: vec![ConnectionId::default().to_string()], + connection_hops: vec![ConnectionId::new(0).to_string()], version: "".to_string(), // The version is not validated. } } From 6d41e9376a8ef62cc0a314d396a1036fbbc48cfb Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 9 Mar 2024 01:57:06 +0700 Subject: [PATCH 17/34] fix(ibc-app): remove upgrade path default --- ibc-clients/ics07-tendermint/src/client_state.rs | 2 +- ibc-clients/ics07-tendermint/types/src/client_state.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ibc-clients/ics07-tendermint/src/client_state.rs b/ibc-clients/ics07-tendermint/src/client_state.rs index 07ab942e9..e4c1e8308 100644 --- a/ibc-clients/ics07-tendermint/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/src/client_state.rs @@ -113,7 +113,7 @@ mod tests { max_clock_drift: Duration::new(3, 0), latest_height: Height::new(1, 10).expect("Never fails"), proof_specs: ProofSpecs::cosmos(), - upgrade_path: Default::default(), + upgrade_path: Vec::new(), allow_update: AllowUpdate { after_expiry: false, after_misbehaviour: false, diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index b401515c2..92341f113 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -445,7 +445,7 @@ mod tests { max_clock_drift: Duration::new(3, 0), latest_height: Height::new(0, 10).expect("Never fails"), proof_specs: ProofSpecs::cosmos(), - upgrade_path: Default::default(), + upgrade_path: Vec::new(), allow_update: AllowUpdate { after_expiry: false, after_misbehaviour: false, From 04ae141fd869ba9bd72d1afdd6f7a6fa3c3e4f2a Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 9 Mar 2024 01:58:48 +0700 Subject: [PATCH 18/34] remove trust threshold default --- .../ics07-tendermint/types/src/trust_threshold.rs | 10 +++++----- ibc-testkit/src/fixtures/clients/tendermint.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs b/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs index 9ca77a660..edc430fa0 100644 --- a/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs +++ b/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs @@ -134,11 +134,11 @@ impl TryFrom for TrustThreshold { } } -impl Default for TrustThreshold { - fn default() -> Self { - Self::ONE_THIRD - } -} +// impl Default for TrustThreshold { +// fn default() -> Self { +// Self::ONE_THIRD +// } +// } impl Display for TrustThreshold { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { diff --git a/ibc-testkit/src/fixtures/clients/tendermint.rs b/ibc-testkit/src/fixtures/clients/tendermint.rs index 39f8de82f..8e6b29937 100644 --- a/ibc-testkit/src/fixtures/clients/tendermint.rs +++ b/ibc-testkit/src/fixtures/clients/tendermint.rs @@ -26,7 +26,7 @@ pub fn dummy_tm_client_state_from_header(tm_header: TmHeader) -> TmClientState { let chain_id = ChainId::from_str(tm_header.chain_id.as_str()).expect("Never fails"); let client_state = ClientStateType::new( chain_id.clone(), - Default::default(), + TrustThreshold::ONE_THIRD, Duration::from_secs(64000), Duration::from_secs(128000), Duration::from_millis(3000), From d0562e021f4e7484ec2bbb20eabaeaa8243abd23 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 9 Mar 2024 02:10:15 +0700 Subject: [PATCH 19/34] refactor(ibc-testkit): remove Default from client_state initialization --- ibc-testkit/src/fixtures/clients/tendermint.rs | 12 ++++++------ ibc-testkit/src/fixtures/core/channel/packet.rs | 2 +- .../src/fixtures/core/connection/conn_open_ack.rs | 4 ++-- .../src/fixtures/core/connection/conn_open_init.rs | 6 +++--- .../src/fixtures/core/connection/conn_open_try.rs | 4 ++-- ibc-testkit/src/fixtures/core/connection/mod.rs | 2 +- ibc-testkit/tests/core/ics02_client/update_client.rs | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ibc-testkit/src/fixtures/clients/tendermint.rs b/ibc-testkit/src/fixtures/clients/tendermint.rs index 8e6b29937..39ec88605 100644 --- a/ibc-testkit/src/fixtures/clients/tendermint.rs +++ b/ibc-testkit/src/fixtures/clients/tendermint.rs @@ -31,8 +31,8 @@ pub fn dummy_tm_client_state_from_header(tm_header: TmHeader) -> TmClientState { Duration::from_secs(128000), Duration::from_millis(3000), Height::new(chain_id.revision_number(), u64::from(tm_header.height)).expect("Never fails"), - Default::default(), - Default::default(), + ProofSpecs::cosmos(), + Vec::new(), AllowUpdate { after_expiry: false, after_misbehaviour: false, @@ -56,8 +56,8 @@ pub fn dummy_raw_tm_client_state(frozen_height: RawHeight) -> RawTmClientState { unbonding_period: Some(Duration::from_secs(128000).into()), max_clock_drift: Some(Duration::from_millis(3000).into()), latest_height: Some(Height::new(0, 10).expect("Never fails").into()), - proof_specs: ProofSpecs::default().into(), - upgrade_path: Default::default(), + proof_specs: ProofSpecs::cosmos().into(), + upgrade_path: Vec::new(), frozen_height: Some(frozen_height), allow_update_after_expiry: false, allow_update_after_misbehaviour: false, @@ -67,7 +67,7 @@ pub fn dummy_raw_tm_client_state(frozen_height: RawHeight) -> RawTmClientState { #[derive(typed_builder::TypedBuilder, Debug)] pub struct ClientStateConfig { pub chain_id: ChainId, - #[builder(default)] + #[builder(default = TrustThreshold::ONE_THIRD)] pub trust_level: TrustThreshold, #[builder(default = Duration::from_secs(64000))] pub trusting_period: Duration, @@ -76,7 +76,7 @@ pub struct ClientStateConfig { #[builder(default = Duration::from_millis(3000))] max_clock_drift: Duration, pub latest_height: Height, - #[builder(default)] + #[builder(default = ProofSpecs::cosmos())] pub proof_specs: ProofSpecs, #[builder(default)] pub upgrade_path: Vec, diff --git a/ibc-testkit/src/fixtures/core/channel/packet.rs b/ibc-testkit/src/fixtures/core/channel/packet.rs index c4debd594..d7923c47f 100644 --- a/ibc-testkit/src/fixtures/core/channel/packet.rs +++ b/ibc-testkit/src/fixtures/core/channel/packet.rs @@ -267,7 +267,7 @@ mod tests { let ibc_event = IbcEvent::SendPacket(SendPacket::new( packet, Order::Unordered, - ConnectionId::default(), + ConnectionId::new(0), )); let _ = tendermint::abci::Event::try_from(ibc_event); } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs index f690e430a..5eda1c9b3 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs @@ -2,7 +2,7 @@ use ibc::core::client::types::proto::v1::Height as RawHeight; use ibc::core::client::types::Height; use ibc::core::connection::types::msgs::MsgConnectionOpenAck; use ibc::core::connection::types::proto::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::get_compatible_versions; use ibc::core::host::types::identifiers::ConnectionId; use ibc::core::primitives::prelude::*; @@ -38,7 +38,7 @@ pub fn dummy_raw_msg_conn_open_ack( }), client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), proof_client: dummy_proof(), - version: Some(Version::default().into()), + version: Some(get_compatible_versions()[0].into()), signer: dummy_bech32_account(), host_consensus_state_proof: vec![], } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs index 07302e0de..7b1f11412 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs @@ -2,7 +2,7 @@ use ibc::core::connection::types::msgs::MsgConnectionOpenInit; use ibc::core::connection::types::proto::v1::{ MsgConnectionOpenInit as RawMsgConnectionOpenInit, Version as RawVersion, }; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::{get_compatible_versions, Version}; use ibc::core::connection::types::Counterparty; use ibc::core::host::types::identifiers::ClientId; use ibc::core::primitives::prelude::*; @@ -71,9 +71,9 @@ pub fn msg_conn_open_with_version( /// Returns a dummy `RawMsgConnectionOpenInit`, for testing purposes only! pub fn dummy_raw_msg_conn_open_init() -> RawMsgConnectionOpenInit { RawMsgConnectionOpenInit { - client_id: ClientId::default().to_string(), + client_id: ClientId::from("07-tendermint-0").to_string(), counterparty: Some(dummy_raw_counterparty_conn(None)), - version: Some(Version::default().into()), + version: Some(get_compatible_versions()[0].into()), delay_period: 0, signer: dummy_bech32_account(), } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs index 5780dd928..afcf2cbf9 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs @@ -40,8 +40,8 @@ pub fn dummy_raw_msg_conn_open_try( #[allow(deprecated)] RawMsgConnectionOpenTry { - client_id: ClientId::default().to_string(), - previous_connection_id: ConnectionId::default().to_string(), + client_id: ClientId::from("07-tendermint-0").to_string(), + previous_connection_id: ConnectionId::new(0).to_string(), client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), counterparty: Some(dummy_raw_counterparty_conn(Some(0))), delay_period: 0, diff --git a/ibc-testkit/src/fixtures/core/connection/mod.rs b/ibc-testkit/src/fixtures/core/connection/mod.rs index 0567705c0..1e371bfbb 100644 --- a/ibc-testkit/src/fixtures/core/connection/mod.rs +++ b/ibc-testkit/src/fixtures/core/connection/mod.rs @@ -42,7 +42,7 @@ pub fn dummy_raw_counterparty_conn(conn_id: Option) -> RawCounterparty { None => "".to_string(), }; RawCounterparty { - client_id: ClientId::default().to_string(), + client_id: ClientId::from("07-tendermint-0").to_string(), connection_id, prefix: Some(MerklePrefix { key_prefix: b"ibc".to_vec(), diff --git a/ibc-testkit/tests/core/ics02_client/update_client.rs b/ibc-testkit/tests/core/ics02_client/update_client.rs index bc7bf02ad..4ded7b02f 100644 --- a/ibc-testkit/tests/core/ics02_client/update_client.rs +++ b/ibc-testkit/tests/core/ics02_client/update_client.rs @@ -678,7 +678,7 @@ fn test_update_synthetic_tendermint_client_duplicate_ok() { .into(), ), proof_specs: ProofSpecs::default().into(), - upgrade_path: Default::default(), + upgrade_path: Vec::new(), frozen_height: Some(RawHeight { revision_number: 0, revision_height: 0, From 8aea66d40a9760af2d115bf2a2da7d3f1f6635d2 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sat, 9 Mar 2024 02:19:11 +0700 Subject: [PATCH 20/34] refactor(ibc-testkit): remove Default() of ClientId, ConnectionId,... --- .../fixtures/core/connection/conn_open_ack.rs | 2 +- .../core/connection/conn_open_init.rs | 2 +- .../testapp/ibc/clients/mock/misbehaviour.rs | 2 +- ibc-testkit/src/testapp/ibc/core/types.rs | 2 +- .../tests/core/ics02_client/update_client.rs | 12 +++---- .../core/ics04_channel/acknowledgement.rs | 21 +++++++------ .../core/ics04_channel/chan_open_init.rs | 2 +- .../tests/core/ics04_channel/recv_packet.rs | 19 ++++++------ .../tests/core/ics04_channel/send_packet.rs | 19 ++++++------ .../tests/core/ics04_channel/timeout.rs | 31 ++++++++++--------- .../core/ics04_channel/timeout_on_close.rs | 17 +++++----- 11 files changed, 67 insertions(+), 62 deletions(-) diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs index 5eda1c9b3..852a024f3 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs @@ -38,7 +38,7 @@ pub fn dummy_raw_msg_conn_open_ack( }), client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), proof_client: dummy_proof(), - version: Some(get_compatible_versions()[0].into()), + version: Some(get_compatible_versions()[0].clone().into()), signer: dummy_bech32_account(), host_consensus_state_proof: vec![], } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs index 7b1f11412..8488e59c7 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs @@ -73,7 +73,7 @@ pub fn dummy_raw_msg_conn_open_init() -> RawMsgConnectionOpenInit { RawMsgConnectionOpenInit { client_id: ClientId::from("07-tendermint-0").to_string(), counterparty: Some(dummy_raw_counterparty_conn(None)), - version: Some(get_compatible_versions()[0].into()), + version: Some(get_compatible_versions()[0].clone().into()), delay_period: 0, signer: dummy_bech32_account(), } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index f0769e4df..aea1d3aa3 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -23,7 +23,7 @@ impl TryFrom for Misbehaviour { fn try_from(raw: RawMisbehaviour) -> Result { Ok(Self { - client_id: Default::default(), + client_id: ClientId::from("07-tendermint-0"), header1: raw .header1 .ok_or(ClientError::MissingRawMisbehaviour)? diff --git a/ibc-testkit/src/testapp/ibc/core/types.rs b/ibc-testkit/src/testapp/ibc/core/types.rs index ddd3ec96c..5c5cd514e 100644 --- a/ibc-testkit/src/testapp/ibc/core/types.rs +++ b/ibc-testkit/src/testapp/ibc/core/types.rs @@ -125,7 +125,7 @@ pub struct MockContext { pub struct MockClientConfig { #[builder(default = ChainId::new("mockZ-1").expect("no error"))] client_chain_id: ChainId, - #[builder(default)] + #[builder(default = ClientId::from("07-tendermint-0"))] client_id: ClientId, #[builder(default = mock_client_type())] client_type: ClientType, diff --git a/ibc-testkit/tests/core/ics02_client/update_client.rs b/ibc-testkit/tests/core/ics02_client/update_client.rs index 4ded7b02f..b84761167 100644 --- a/ibc-testkit/tests/core/ics02_client/update_client.rs +++ b/ibc-testkit/tests/core/ics02_client/update_client.rs @@ -43,7 +43,7 @@ struct Fixture { #[fixture] fn fixture() -> Fixture { - let client_id = ClientId::default(); + let client_id = ClientId::from("07-tendermint-0"); let ctx = MockContext::default().with_client_config( MockClientConfig::builder() @@ -82,7 +82,7 @@ fn test_update_client_ok(fixture: Fixture) { mut router, } = fixture; - let client_id = ClientId::default(); + let client_id = ClientId::from("07-tendermint-0"); let signer = dummy_account_id(); let timestamp = Timestamp::now(); @@ -114,7 +114,7 @@ fn test_update_client_ok(fixture: Fixture) { // client's height and ensures that `ConsensusState` is stored at the correct // path (header height). fn test_update_client_with_prev_header() { - let client_id = ClientId::default(); + let client_id = ClientId::from("07-tendermint-0"); let chain_id_b = ChainId::new("mockgaiaA-0").unwrap(); let latest_height = Height::new(0, 42).unwrap(); let height_1 = Height::new(0, 43).unwrap(); @@ -677,7 +677,7 @@ fn test_update_synthetic_tendermint_client_duplicate_ok() { .unwrap() .into(), ), - proof_specs: ProofSpecs::default().into(), + proof_specs: ProofSpecs::cosmos().into(), upgrade_path: Vec::new(), frozen_height: Some(RawHeight { revision_number: 0, @@ -778,7 +778,7 @@ fn test_update_client_events(fixture: Fixture) { mut router, } = fixture; - let client_id = ClientId::default(); + let client_id = ClientId::from("07-tendermint-0"); let signer = dummy_account_id(); let timestamp = Timestamp::now(); @@ -839,7 +839,7 @@ fn test_misbehaviour_client_ok(fixture: Fixture) { mut router, } = fixture; - let client_id = ClientId::default(); + let client_id = ClientId::from("07-tendermint-0"); let msg_envelope = msg_update_client(&client_id); let res = validate(&ctx, &router, msg_envelope.clone()); diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index cdd17f52e..805adcab3 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -4,6 +4,7 @@ use ibc::core::channel::types::msgs::{MsgAcknowledgement, PacketMsg}; use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; +use ibc::core::commitment_types::commitment::CommitmentPrefix; use ibc::core::connection::types::version::get_compatible_versions; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, @@ -59,7 +60,7 @@ fn fixture() -> Fixture { State::Open, Order::Unordered, Counterparty::new(packet.port_id_on_b, Some(packet.chan_id_on_b)), - vec![ConnectionId::default()], + vec![ConnectionId::new(0)], Version::new("ics20-1".to_string()), ) .unwrap(); @@ -69,11 +70,11 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + ClientId::from("07-tendermint-0"), + Some(ConnectionId::new(0)), + CommitmentPrefix::empty(), ), get_compatible_versions(), ZERO_DURATION, @@ -131,7 +132,7 @@ fn ack_success_no_packet_commitment(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a); + .with_connection(ConnectionId::new(0), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -166,7 +167,7 @@ fn ack_success_happy_path(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -175,7 +176,7 @@ fn ack_success_happy_path(fixture: Fixture) { ); ctx.get_client_execution_context() .store_update_meta( - ClientId::default(), + ClientId::from("07-tendermint-0"), client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 4).unwrap(), @@ -209,7 +210,7 @@ fn ack_unordered_chan_execute(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -246,7 +247,7 @@ fn ack_ordered_chan_execute(fixture: Fixture) { } = fixture; let mut ctx = ctx .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs index d79f8989c..a1474a60c 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs @@ -52,7 +52,7 @@ fn fixture() -> Fixture { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a); + .with_connection(ConnectionId::new(0), conn_end_on_a); Fixture { ctx, router, msg } } diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index 7c9fa37b1..fe8acb4c6 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -4,6 +4,7 @@ use ibc::core::channel::types::packet::Packet; use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; +use ibc::core::commitment_types::commitment::CommitmentPrefix; use ibc::core::connection::types::version::get_compatible_versions; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, @@ -51,18 +52,18 @@ fn fixture() -> Fixture { State::Open, Order::Unordered, Counterparty::new(packet.port_id_on_a, Some(packet.chan_id_on_a)), - vec![ConnectionId::default()], + vec![ConnectionId::new(0)], Version::new("ics20-1".to_string()), ) .unwrap(); let conn_end_on_b = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + ClientId::from("07-tendermint-0"), + Some(ConnectionId::new(0)), + CommitmentPrefix::empty(), ), get_compatible_versions(), ZERO_DURATION, @@ -119,7 +120,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_b) + .with_connection(ConnectionId::new(0), conn_end_on_b) .with_channel( packet.port_id_on_b.clone(), packet.chan_id_on_b.clone(), @@ -141,7 +142,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { context .get_client_execution_context() .store_update_meta( - ClientId::default(), + ClientId::from("07-tendermint-0"), client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), @@ -197,7 +198,7 @@ fn recv_packet_timeout_expired(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_b) + .with_connection(ConnectionId::new(0), conn_end_on_b) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_b) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()) .with_height(host_height); @@ -227,7 +228,7 @@ fn recv_packet_execute_happy_path(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_b) + .with_connection(ConnectionId::new(0), conn_end_on_b) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_b); let msg_env = MsgEnvelope::from(PacketMsg::from(msg)); diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 58e5cfe38..16fbb5777 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -6,6 +6,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State} use ibc::core::channel::types::packet::Packet; use ibc::core::channel::types::Version; use ibc::core::client::types::Height; +use ibc::core::commitment_types::commitment::CommitmentPrefix; use ibc::core::connection::types::version::get_compatible_versions; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, @@ -32,18 +33,18 @@ fn send_packet_processing() { State::Open, Order::Unordered, Counterparty::new(PortId::transfer(), Some(ChannelId::zero())), - vec![ConnectionId::default()], + vec![ConnectionId::new(0)], Version::new("ics20-1".to_string()), ) .unwrap(); let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + ClientId::from("07-tendermint-0"), + Some(ConnectionId::new(0)), + CommitmentPrefix::empty(), ), get_compatible_versions(), ZERO_DURATION, @@ -97,7 +98,7 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a.clone()) + .with_connection(ConnectionId::new(0), conn_end_on_a.clone()) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet, @@ -112,7 +113,7 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a.clone()) + .with_connection(ConnectionId::new(0), conn_end_on_a.clone()) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_timeout_equal_client_height, @@ -127,7 +128,7 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a.clone()) + .with_connection(ConnectionId::new(0), conn_end_on_a.clone()) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_timeout_one_before_client_height, @@ -141,7 +142,7 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_with_timestamp_old, diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 6790520b2..39d110898 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -4,6 +4,7 @@ use ibc::core::channel::types::msgs::{MsgTimeout, PacketMsg}; use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; +use ibc::core::commitment_types::commitment::CommitmentPrefix; use ibc::core::connection::types::version::get_compatible_versions; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, @@ -66,7 +67,7 @@ fn fixture() -> Fixture { State::Open, Order::Unordered, Counterparty::new(packet.port_id_on_b.clone(), Some(packet.chan_id_on_b)), - vec![ConnectionId::default()], + vec![ConnectionId::new(0)], Version::new("ics20-1".to_string()), ) .unwrap(); @@ -76,11 +77,11 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + ClientId::from("07-tendermint-0"), + Some(ConnectionId::new(0)), + CommitmentPrefix::empty(), ), get_compatible_versions(), ZERO_DURATION, @@ -142,7 +143,7 @@ fn timeout_fail_no_consensus_state_for_height(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_packet_commitment( packet.port_id_on_a, packet.chan_id_on_a, @@ -190,7 +191,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_channel( PortId::transfer(), ChannelId::zero(), @@ -204,7 +205,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { ); ctx.store_update_meta( - ClientId::default(), + ClientId::from("07-tendermint-0"), client_height, Timestamp::from_nanoseconds(5).unwrap(), Height::new(0, 4).unwrap(), @@ -238,7 +239,7 @@ fn timeout_success_no_packet_commitment(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a); + .with_connection(ConnectionId::new(0), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -271,7 +272,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_channel( PortId::transfer(), ChannelId::zero(), @@ -286,7 +287,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { ctx.get_client_execution_context() .store_update_meta( - ClientId::default(), + ClientId::from("07-tendermint-0"), client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), @@ -321,7 +322,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) .with_packet_commitment( packet.port_id_on_a, @@ -331,7 +332,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { ); ctx.store_update_meta( - ClientId::default(), + ClientId::from("07-tendermint-0"), client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 4).unwrap(), @@ -362,7 +363,7 @@ fn timeout_unordered_chan_execute(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -400,7 +401,7 @@ fn timeout_ordered_chan_execute(fixture: Fixture) { } = fixture; let mut ctx = ctx .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), diff --git a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs index ae930b87a..13a655686 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -4,6 +4,7 @@ use ibc::core::channel::types::msgs::{MsgTimeoutOnClose, PacketMsg}; use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; +use ibc::core::commitment_types::commitment::CommitmentPrefix; use ibc::core::connection::types::version::get_compatible_versions; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, @@ -56,18 +57,18 @@ fn fixture() -> Fixture { State::Open, Order::Ordered, Counterparty::new(packet.port_id_on_b.clone(), Some(packet.chan_id_on_b)), - vec![ConnectionId::default()], + vec![ConnectionId::new(0)], Version::new("ics20-1".to_string()), ) .unwrap(); let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::default(), + ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( - ClientId::default(), - Some(ConnectionId::default()), - Default::default(), + ClientId::from("07-tendermint-0"), + Some(ConnectionId::new(0)), + CommitmentPrefix::empty(), ), get_compatible_versions(), ZERO_DURATION, @@ -116,7 +117,7 @@ fn timeout_on_close_success_no_packet_commitment(fixture: Fixture) { } = fixture; let context = context .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) - .with_connection(ConnectionId::default(), conn_end_on_a); + .with_connection(ConnectionId::new(0), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -141,7 +142,7 @@ fn timeout_on_close_success_happy_path(fixture: Fixture) { } = fixture; let mut context = context .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) - .with_connection(ConnectionId::default(), conn_end_on_a) + .with_connection(ConnectionId::new(0), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -152,7 +153,7 @@ fn timeout_on_close_success_happy_path(fixture: Fixture) { context .get_client_execution_context() .store_update_meta( - ClientId::default(), + ClientId::from("07-tendermint-0"), Height::new(0, 2).unwrap(), Timestamp::from_nanoseconds(5000).unwrap(), Height::new(0, 5).unwrap(), From 37ce28896ce8cdc6008293ea7ec95ac6f2c12220 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sun, 10 Mar 2024 01:12:06 +0700 Subject: [PATCH 21/34] chore: add unclog --- .../improvements/1074-refactor-default-implemetation.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/1074-refactor-default-implemetation.md diff --git a/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md b/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md new file mode 100644 index 000000000..1a7e66073 --- /dev/null +++ b/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md @@ -0,0 +1,2 @@ +- [types] Refactor Default implementations with concrete names + ([\#1074](https://github.com/cosmos/ibc-rs/issues/1074)) \ No newline at end of file From cd2addd0781a4070ed494b1b435e562c3de62474 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 00:11:28 +0700 Subject: [PATCH 22/34] refactor: add Connection::zero() --- ibc-core/ics03-connection/types/src/events.rs | 2 +- ibc-core/ics04-channel/types/src/events/mod.rs | 2 +- .../types/src/identifiers/connection_id.rs | 5 +++++ ibc-core/ics24-host/types/src/path.rs | 4 ++-- ibc-testkit/src/fixtures/core/channel/mod.rs | 2 +- .../src/fixtures/core/channel/packet.rs | 2 +- .../fixtures/core/connection/conn_open_ack.rs | 2 +- .../fixtures/core/connection/conn_open_try.rs | 2 +- .../core/ics04_channel/acknowledgement.rs | 12 ++++++------ .../tests/core/ics04_channel/chan_open_init.rs | 2 +- .../tests/core/ics04_channel/recv_packet.rs | 10 +++++----- .../tests/core/ics04_channel/send_packet.rs | 12 ++++++------ .../tests/core/ics04_channel/timeout.rs | 18 +++++++++--------- .../core/ics04_channel/timeout_on_close.rs | 8 ++++---- 14 files changed, 44 insertions(+), 39 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/events.rs b/ibc-core/ics03-connection/types/src/events.rs index 7c478c21f..54d312a74 100644 --- a/ibc-core/ics03-connection/types/src/events.rs +++ b/ibc-core/ics03-connection/types/src/events.rs @@ -323,7 +323,7 @@ mod tests { let client_type = ClientType::from_str("07-tendermint") .expect("never fails because it's a valid client type"); - let conn_id_on_a = ConnectionId::new(0); + let conn_id_on_a = ConnectionId::zero(); let client_id_on_a = client_type.build_client_id(0); let conn_id_on_b = ConnectionId::new(1); let client_id_on_b = client_type.build_client_id(1); diff --git a/ibc-core/ics04-channel/types/src/events/mod.rs b/ibc-core/ics04-channel/types/src/events/mod.rs index 03dd36723..aab030ef9 100644 --- a/ibc-core/ics04-channel/types/src/events/mod.rs +++ b/ibc-core/ics04-channel/types/src/events/mod.rs @@ -1133,7 +1133,7 @@ mod tests { let port_id = PortId::transfer(); let channel_id = ChannelId::zero(); - let connection_id = ConnectionId::new(0); + let connection_id = ConnectionId::zero(); let counterparty_port_id = PortId::transfer(); let counterparty_channel_id = ChannelId::new(1); let version = Version::new("ics20-1".to_string()); diff --git a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs index 4c8b99adf..30b6cde9f 100644 --- a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs @@ -56,6 +56,11 @@ impl ConnectionId { pub fn as_bytes(&self) -> &[u8] { self.0.as_bytes() } + + /// Return ConnectionId with identifier 0 + pub fn zero() -> Self { + Self::new(0) + } } /// This implementation provides a `to_string` method. diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index 629018a03..848fa48d7 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1214,7 +1214,7 @@ mod tests { )] #[case( "connections/connection-0", - Path::Connection(ConnectionPath(ConnectionId::new(0))) + Path::Connection(ConnectionPath(ConnectionId::zero())) )] #[case("ports/transfer", Path::Ports(PortPath(PortId::transfer())))] #[case( @@ -1340,7 +1340,7 @@ mod tests { assert_eq!( parse_connections(&components), - Some(Path::Connection(ConnectionPath(ConnectionId::new(0)))), + Some(Path::Connection(ConnectionPath(ConnectionId::zero()))), ); } diff --git a/ibc-testkit/src/fixtures/core/channel/mod.rs b/ibc-testkit/src/fixtures/core/channel/mod.rs index fc69b7dbe..a1375cd72 100644 --- a/ibc-testkit/src/fixtures/core/channel/mod.rs +++ b/ibc-testkit/src/fixtures/core/channel/mod.rs @@ -46,7 +46,7 @@ pub fn dummy_raw_channel_end(state: i32, channel_id: Option) -> RawChannel state, ordering: 2, counterparty: Some(dummy_raw_counterparty_chan(channel_id)), - connection_hops: vec![ConnectionId::new(0).to_string()], + connection_hops: vec![ConnectionId::zero().to_string()], version: "".to_string(), // The version is not validated. } } diff --git a/ibc-testkit/src/fixtures/core/channel/packet.rs b/ibc-testkit/src/fixtures/core/channel/packet.rs index d7923c47f..5aff2d475 100644 --- a/ibc-testkit/src/fixtures/core/channel/packet.rs +++ b/ibc-testkit/src/fixtures/core/channel/packet.rs @@ -267,7 +267,7 @@ mod tests { let ibc_event = IbcEvent::SendPacket(SendPacket::new( packet, Order::Unordered, - ConnectionId::new(0), + ConnectionId::zero(), )); let _ = tendermint::abci::Event::try_from(ibc_event); } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs index 852a024f3..cb4656cc8 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs @@ -24,7 +24,7 @@ pub fn dummy_raw_msg_conn_open_ack( ) -> RawMsgConnectionOpenAck { let client_state_height = Height::new(0, consensus_height).expect("invalid height"); RawMsgConnectionOpenAck { - connection_id: ConnectionId::new(0).to_string(), + connection_id: ConnectionId::zero().to_string(), counterparty_connection_id: ConnectionId::new(1).to_string(), proof_try: dummy_proof(), proof_height: Some(RawHeight { diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs index afcf2cbf9..662124161 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs @@ -41,7 +41,7 @@ pub fn dummy_raw_msg_conn_open_try( #[allow(deprecated)] RawMsgConnectionOpenTry { client_id: ClientId::from("07-tendermint-0").to_string(), - previous_connection_id: ConnectionId::new(0).to_string(), + previous_connection_id: ConnectionId::zero().to_string(), client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), counterparty: Some(dummy_raw_counterparty_conn(Some(0))), delay_period: 0, diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index 805adcab3..d2b26d723 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -60,7 +60,7 @@ fn fixture() -> Fixture { State::Open, Order::Unordered, Counterparty::new(packet.port_id_on_b, Some(packet.chan_id_on_b)), - vec![ConnectionId::new(0)], + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); @@ -73,7 +73,7 @@ fn fixture() -> Fixture { ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( ClientId::from("07-tendermint-0"), - Some(ConnectionId::new(0)), + Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), get_compatible_versions(), @@ -132,7 +132,7 @@ fn ack_success_no_packet_commitment(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::new(0), conn_end_on_a); + .with_connection(ConnectionId::zero(), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -167,7 +167,7 @@ fn ack_success_happy_path(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -210,7 +210,7 @@ fn ack_unordered_chan_execute(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -247,7 +247,7 @@ fn ack_ordered_chan_execute(fixture: Fixture) { } = fixture; let mut ctx = ctx .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs index a1474a60c..60bc54a4e 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs @@ -52,7 +52,7 @@ fn fixture() -> Fixture { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_a); + .with_connection(ConnectionId::zero(), conn_end_on_a); Fixture { ctx, router, msg } } diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index fe8acb4c6..f897de8ec 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -52,7 +52,7 @@ fn fixture() -> Fixture { State::Open, Order::Unordered, Counterparty::new(packet.port_id_on_a, Some(packet.chan_id_on_a)), - vec![ConnectionId::new(0)], + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); @@ -62,7 +62,7 @@ fn fixture() -> Fixture { ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( ClientId::from("07-tendermint-0"), - Some(ConnectionId::new(0)), + Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), get_compatible_versions(), @@ -120,7 +120,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_b) + .with_connection(ConnectionId::zero(), conn_end_on_b) .with_channel( packet.port_id_on_b.clone(), packet.chan_id_on_b.clone(), @@ -198,7 +198,7 @@ fn recv_packet_timeout_expired(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_b) + .with_connection(ConnectionId::zero(), conn_end_on_b) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_b) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()) .with_height(host_height); @@ -228,7 +228,7 @@ fn recv_packet_execute_happy_path(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_b) + .with_connection(ConnectionId::zero(), conn_end_on_b) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_b); let msg_env = MsgEnvelope::from(PacketMsg::from(msg)); diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 16fbb5777..8345a78c6 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -33,7 +33,7 @@ fn send_packet_processing() { State::Open, Order::Unordered, Counterparty::new(PortId::transfer(), Some(ChannelId::zero())), - vec![ConnectionId::new(0)], + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); @@ -43,7 +43,7 @@ fn send_packet_processing() { ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( ClientId::from("07-tendermint-0"), - Some(ConnectionId::new(0)), + Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), get_compatible_versions(), @@ -98,7 +98,7 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_a.clone()) + .with_connection(ConnectionId::zero(), conn_end_on_a.clone()) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet, @@ -113,7 +113,7 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_a.clone()) + .with_connection(ConnectionId::zero(), conn_end_on_a.clone()) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_timeout_equal_client_height, @@ -128,7 +128,7 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_a.clone()) + .with_connection(ConnectionId::zero(), conn_end_on_a.clone()) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a.clone()) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_timeout_one_before_client_height, @@ -142,7 +142,7 @@ fn send_packet_processing() { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) .with_send_sequence(PortId::transfer(), ChannelId::zero(), 1.into()), packet: packet_with_timestamp_old, diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 39d110898..60904d004 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -67,7 +67,7 @@ fn fixture() -> Fixture { State::Open, Order::Unordered, Counterparty::new(packet.port_id_on_b.clone(), Some(packet.chan_id_on_b)), - vec![ConnectionId::new(0)], + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); @@ -80,7 +80,7 @@ fn fixture() -> Fixture { ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( ClientId::from("07-tendermint-0"), - Some(ConnectionId::new(0)), + Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), get_compatible_versions(), @@ -143,7 +143,7 @@ fn timeout_fail_no_consensus_state_for_height(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( packet.port_id_on_a, packet.chan_id_on_a, @@ -191,7 +191,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_channel( PortId::transfer(), ChannelId::zero(), @@ -239,7 +239,7 @@ fn timeout_success_no_packet_commitment(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::new(0), conn_end_on_a); + .with_connection(ConnectionId::zero(), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -272,7 +272,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_channel( PortId::transfer(), ChannelId::zero(), @@ -322,7 +322,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { .latest_height(client_height) .build(), ) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) .with_packet_commitment( packet.port_id_on_a, @@ -363,7 +363,7 @@ fn timeout_unordered_chan_execute(fixture: Fixture) { ChannelId::zero(), chan_end_on_a_unordered, ) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), @@ -401,7 +401,7 @@ fn timeout_ordered_chan_execute(fixture: Fixture) { } = fixture; let mut ctx = ctx .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), diff --git a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs index 13a655686..c5b8a28aa 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -57,7 +57,7 @@ fn fixture() -> Fixture { State::Open, Order::Ordered, Counterparty::new(packet.port_id_on_b.clone(), Some(packet.chan_id_on_b)), - vec![ConnectionId::new(0)], + vec![ConnectionId::zero()], Version::new("ics20-1".to_string()), ) .unwrap(); @@ -67,7 +67,7 @@ fn fixture() -> Fixture { ClientId::from("07-tendermint-0"), ConnectionCounterparty::new( ClientId::from("07-tendermint-0"), - Some(ConnectionId::new(0)), + Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), get_compatible_versions(), @@ -117,7 +117,7 @@ fn timeout_on_close_success_no_packet_commitment(fixture: Fixture) { } = fixture; let context = context .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) - .with_connection(ConnectionId::new(0), conn_end_on_a); + .with_connection(ConnectionId::zero(), conn_end_on_a); let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg)); @@ -142,7 +142,7 @@ fn timeout_on_close_success_happy_path(fixture: Fixture) { } = fixture; let mut context = context .with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a) - .with_connection(ConnectionId::new(0), conn_end_on_a) + .with_connection(ConnectionId::zero(), conn_end_on_a) .with_packet_commitment( msg.packet.port_id_on_a.clone(), msg.packet.chan_id_on_a.clone(), From ec84de56bc2b168e51d1e911c1e9faa37300549f Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 00:12:34 +0700 Subject: [PATCH 23/34] use into() instead of ::from() --- .../src/handler/send_transfer.rs | 11 +++++------ ibc-apps/ics721-nft-transfer/src/module.rs | 8 +++----- .../ics03-connection/types/src/connection.rs | 8 ++------ ibc-core/ics24-host/types/src/path.rs | 16 ++++++++-------- .../src/fixtures/applications/transfer.rs | 2 +- .../fixtures/core/connection/conn_open_init.rs | 2 +- .../fixtures/core/connection/conn_open_try.rs | 2 +- ibc-testkit/src/fixtures/core/connection/mod.rs | 4 ++-- .../src/testapp/ibc/clients/mock/misbehaviour.rs | 2 +- ibc-testkit/src/testapp/ibc/core/types.rs | 2 +- .../tests/core/ics04_channel/acknowledgement.rs | 8 ++++---- .../tests/core/ics04_channel/recv_packet.rs | 8 ++++---- .../tests/core/ics04_channel/send_packet.rs | 6 +++--- ibc-testkit/tests/core/ics04_channel/timeout.rs | 12 ++++++------ .../tests/core/ics04_channel/timeout_on_close.rs | 8 ++++---- 15 files changed, 46 insertions(+), 53 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs b/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs index d192be202..4cf1a759c 100644 --- a/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs +++ b/ibc-apps/ics721-nft-transfer/src/handler/send_transfer.rs @@ -1,4 +1,3 @@ -use ibc_app_nft_transfer_types::Memo; use ibc_core::channel::context::{SendPacketExecutionContext, SendPacketValidationContext}; use ibc_core::channel::handler::{send_packet_execute, send_packet_validate}; use ibc_core::channel::types::packet::Packet; @@ -82,14 +81,14 @@ where &msg.chan_id_on_a, class_id, token_id, - &packet_data.memo.clone().unwrap_or(Memo::from("")), + &packet_data.memo.clone().unwrap_or("".into()), )?; } else { transfer_ctx.burn_nft_validate( &sender, class_id, token_id, - &packet_data.memo.clone().unwrap_or(Memo::from("")), + &packet_data.memo.clone().unwrap_or("".into()), )?; } let nft = transfer_ctx.get_nft(class_id, token_id)?; @@ -185,14 +184,14 @@ where &msg.chan_id_on_a, class_id, token_id, - &packet_data.memo.clone().unwrap_or(Memo::from("")), + &packet_data.memo.clone().unwrap_or("".into()), )?; } else { transfer_ctx.burn_nft_execute( &sender, class_id, token_id, - &packet_data.memo.clone().unwrap_or(Memo::from("")), + &packet_data.memo.clone().unwrap_or("".into()), )?; } let nft = transfer_ctx.get_nft(class_id, token_id)?; @@ -243,7 +242,7 @@ where receiver: packet_data.receiver, class: packet_data.class_id, tokens: packet_data.token_ids, - memo: packet_data.memo.unwrap_or(Memo::from("")), + memo: packet_data.memo.unwrap_or("".into()), }; send_packet_ctx_a.emit_ibc_event(ModuleEvent::from(transfer_event).into())?; diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index cc5d33b1d..10859e176 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -1,6 +1,4 @@ //! Provides IBC module callbacks implementation for the ICS-721 transfer. - -use ibc_app_nft_transfer_types::Memo; use ibc_core::channel::types::acknowledgement::{Acknowledgement, AcknowledgementStatus}; use ibc_core::channel::types::channel::{Counterparty, Order}; use ibc_core::channel::types::packet::Packet; @@ -195,7 +193,7 @@ pub fn on_recv_packet_execute( receiver: data.receiver, class: data.class_id, tokens: data.token_ids, - memo: data.memo.unwrap_or(Memo::from("")), + memo: data.memo.unwrap_or("".into()), success: ack.is_successful(), }; extras.events.push(recv_event.into()); @@ -260,7 +258,7 @@ pub fn on_acknowledgement_packet_execute( receiver: data.receiver, class: data.class_id, tokens: data.token_ids, - memo: data.memo.unwrap_or(Memo::from("")), + memo: data.memo.unwrap_or("".into()), acknowledgement: acknowledgement.clone(), }; @@ -308,7 +306,7 @@ pub fn on_timeout_packet_execute( refund_receiver: data.sender, refund_class: data.class_id, refund_tokens: data.token_ids, - memo: data.memo.unwrap_or(Memo::from("")), + memo: data.memo.unwrap_or("".into()), }; let extras = ModuleExtras { diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index c642ebaa0..bc5172275 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -210,12 +210,8 @@ impl TryFrom for ConnectionEnd { if state == State::Uninitialized { return ConnectionEnd::new( State::Uninitialized, - ClientId::from("07-tendermint-0"), - Counterparty::new( - ClientId::from("07-tendermint-0"), - None, - CommitmentPrefix::empty(), - ), + "07-tendermint-0".into(), + Counterparty::new("07-tendermint-0".into(), None, CommitmentPrefix::empty()), Vec::new(), ZERO_DURATION, ); diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index 848fa48d7..003e4997d 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1182,12 +1182,12 @@ mod tests { )] #[case( "clients/07-tendermint-0/clientState", - Path::ClientState(ClientStatePath(ClientId::from("07-tendermint-0"))) + Path::ClientState(ClientStatePath("07-tendermint-0".into())) )] #[case( "clients/07-tendermint-0/consensusStates/15-31", Path::ClientConsensusState(ClientConsensusStatePath { - client_id: ClientId::from("07-tendermint-0"), + client_id: "07-tendermint-0".into(), revision_number: 15, revision_height: 31, }) @@ -1195,7 +1195,7 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedTime", Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: ClientId::from("07-tendermint-0"), + client_id: "07-tendermint-0".into(), revision_number: 15, revision_height: 31, }) @@ -1203,14 +1203,14 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedHeight", Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: ClientId::from("07-tendermint-0"), + client_id: "07-tendermint-0".into(), revision_number: 15, revision_height: 31, }) )] #[case( "clients/07-tendermint-0/connections", - Path::ClientConnection(ClientConnectionPath(ClientId::from("07-tendermint-0"))) + Path::ClientConnection(ClientConnectionPath("07-tendermint-0".into())) )] #[case( "connections/connection-0", @@ -1299,7 +1299,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientConsensusState(ClientConsensusStatePath { - client_id: ClientId::from("07-tendermint-0"), + client_id: "07-tendermint-0".into(), revision_number: 15, revision_height: 31, })) @@ -1314,7 +1314,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: ClientId::from("07-tendermint-0"), + client_id: "07-tendermint-0".into(), revision_number: 15, revision_height: 31, })) @@ -1326,7 +1326,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: ClientId::from("07-tendermint-0"), + client_id: "07-tendermint-0".into(), revision_number: 15, revision_height: 31, })) diff --git a/ibc-testkit/src/fixtures/applications/transfer.rs b/ibc-testkit/src/fixtures/applications/transfer.rs index 18b219e58..35e71fac0 100644 --- a/ibc-testkit/src/fixtures/applications/transfer.rs +++ b/ibc-testkit/src/fixtures/applications/transfer.rs @@ -61,7 +61,7 @@ pub struct PacketDataConfig { pub sender: Signer, #[builder(default = dummy_account_id())] pub receiver: Signer, - #[builder(default = Memo::from(""))] + #[builder(default = "".into())] pub memo: Memo, } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs index 8488e59c7..d13b1936e 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs @@ -71,7 +71,7 @@ pub fn msg_conn_open_with_version( /// Returns a dummy `RawMsgConnectionOpenInit`, for testing purposes only! pub fn dummy_raw_msg_conn_open_init() -> RawMsgConnectionOpenInit { RawMsgConnectionOpenInit { - client_id: ClientId::from("07-tendermint-0").to_string(), + client_id: "07-tendermint-0".to_string(), counterparty: Some(dummy_raw_counterparty_conn(None)), version: Some(get_compatible_versions()[0].clone().into()), delay_period: 0, diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs index 662124161..3b2630e37 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs @@ -40,7 +40,7 @@ pub fn dummy_raw_msg_conn_open_try( #[allow(deprecated)] RawMsgConnectionOpenTry { - client_id: ClientId::from("07-tendermint-0").to_string(), + client_id: "07-tendermint-0".to_string(), previous_connection_id: ConnectionId::zero().to_string(), client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), counterparty: Some(dummy_raw_counterparty_conn(Some(0))), diff --git a/ibc-testkit/src/fixtures/core/connection/mod.rs b/ibc-testkit/src/fixtures/core/connection/mod.rs index 1e371bfbb..329d06632 100644 --- a/ibc-testkit/src/fixtures/core/connection/mod.rs +++ b/ibc-testkit/src/fixtures/core/connection/mod.rs @@ -9,7 +9,7 @@ pub use conn_open_init::*; pub use conn_open_try::*; use ibc::core::commitment_types::proto::v1::MerklePrefix; use ibc::core::connection::types::proto::v1::Counterparty as RawCounterparty; -use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; +use ibc::core::host::types::identifiers::ConnectionId; use ibc::core::primitives::prelude::*; use typed_builder::TypedBuilder; @@ -42,7 +42,7 @@ pub fn dummy_raw_counterparty_conn(conn_id: Option) -> RawCounterparty { None => "".to_string(), }; RawCounterparty { - client_id: ClientId::from("07-tendermint-0").to_string(), + client_id: "07-tendermint-0".to_string(), connection_id, prefix: Some(MerklePrefix { key_prefix: b"ibc".to_vec(), diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index aea1d3aa3..04a5a10a5 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -23,7 +23,7 @@ impl TryFrom for Misbehaviour { fn try_from(raw: RawMisbehaviour) -> Result { Ok(Self { - client_id: ClientId::from("07-tendermint-0"), + client_id: "07-tendermint-0".into(), header1: raw .header1 .ok_or(ClientError::MissingRawMisbehaviour)? diff --git a/ibc-testkit/src/testapp/ibc/core/types.rs b/ibc-testkit/src/testapp/ibc/core/types.rs index 5c5cd514e..535f39613 100644 --- a/ibc-testkit/src/testapp/ibc/core/types.rs +++ b/ibc-testkit/src/testapp/ibc/core/types.rs @@ -125,7 +125,7 @@ pub struct MockContext { pub struct MockClientConfig { #[builder(default = ChainId::new("mockZ-1").expect("no error"))] client_chain_id: ChainId, - #[builder(default = ClientId::from("07-tendermint-0"))] + #[builder(default = "07-tendermint-0".into())] client_id: ClientId, #[builder(default = mock_client_type())] client_type: ClientType, diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index d2b26d723..f7ff3f88a 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -12,7 +12,7 @@ use ibc::core::connection::types::{ use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::handler::types::msgs::MsgEnvelope; -use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::dummy_raw_msg_acknowledgement; @@ -70,9 +70,9 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), ConnectionCounterparty::new( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -176,7 +176,7 @@ fn ack_success_happy_path(fixture: Fixture) { ); ctx.get_client_execution_context() .store_update_meta( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 4).unwrap(), diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index f897de8ec..b6cedfacc 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -12,7 +12,7 @@ use ibc::core::connection::types::{ use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::handler::types::msgs::MsgEnvelope; -use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::{dummy_msg_recv_packet, dummy_raw_msg_recv_packet}; @@ -59,9 +59,9 @@ fn fixture() -> Fixture { let conn_end_on_b = ConnectionEnd::new( ConnectionState::Open, - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), ConnectionCounterparty::new( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -142,7 +142,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { context .get_client_execution_context() .store_update_meta( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 8345a78c6..66194da47 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -12,7 +12,7 @@ use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; -use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::dummy_raw_packet; use ibc_testkit::testapp::ibc::core::types::{MockClientConfig, MockContext}; @@ -40,9 +40,9 @@ fn send_packet_processing() { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), ConnectionCounterparty::new( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 60904d004..7c3e7c281 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -12,7 +12,7 @@ use ibc::core::connection::types::{ use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::handler::types::msgs::MsgEnvelope; -use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::dummy_raw_msg_timeout; @@ -77,9 +77,9 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), ConnectionCounterparty::new( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -205,7 +205,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { ); ctx.store_update_meta( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), client_height, Timestamp::from_nanoseconds(5).unwrap(), Height::new(0, 4).unwrap(), @@ -287,7 +287,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { ctx.get_client_execution_context() .store_update_meta( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), @@ -332,7 +332,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { ); ctx.store_update_meta( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 4).unwrap(), diff --git a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs index c5b8a28aa..266fab3d2 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -11,7 +11,7 @@ use ibc::core::connection::types::{ }; use ibc::core::entrypoint::validate; use ibc::core::handler::types::msgs::MsgEnvelope; -use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::dummy_raw_msg_timeout_on_close; @@ -64,9 +64,9 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), ConnectionCounterparty::new( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -153,7 +153,7 @@ fn timeout_on_close_success_happy_path(fixture: Fixture) { context .get_client_execution_context() .store_update_meta( - ClientId::from("07-tendermint-0"), + "07-tendermint-0".into(), Height::new(0, 2).unwrap(), Timestamp::from_nanoseconds(5000).unwrap(), Height::new(0, 5).unwrap(), From 7750afdaac7b78efb454360c7c93c5039610b9e5 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 00:23:35 +0700 Subject: [PATCH 24/34] refactor: add Version::compatibles() --- ibc-core/ics03-connection/types/src/version.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/version.rs b/ibc-core/ics03-connection/types/src/version.rs index b491a58d9..886be1318 100644 --- a/ibc-core/ics03-connection/types/src/version.rs +++ b/ibc-core/ics03-connection/types/src/version.rs @@ -58,6 +58,13 @@ impl Version { } Ok(()) } + /// Returns the lists of supported versions + pub fn compatibles() -> Vec { + vec![Self { + identifier: "1".to_string(), + features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + }] + } } impl Protobuf for Version {} @@ -111,10 +118,7 @@ impl Display for Version { /// Returns the lists of supported versions pub fn get_compatible_versions() -> Vec { - vec![Version { - identifier: "1".to_string(), - features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], - }] + Version::compatibles() } /// Iterates over the descending ordered set of compatible IBC versions and From a860979a4496c873f16149a1cd135c01edb980c1 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 09:38:37 +0700 Subject: [PATCH 25/34] refactor(ics24-host): make 07-tendermint-0 a constant in tests --- ibc-core/ics24-host/types/src/path.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index 003e4997d..8ca0158bd 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1169,7 +1169,7 @@ fn parse_upgrades(components: &[&str]) -> Option { #[cfg(test)] mod tests { use super::*; - + const DUMMY_CLIENT_ID: &str = "07-tendermint-0"; #[rstest::rstest] #[case(NEXT_CLIENT_SEQUENCE, Path::NextClientSequence(NextClientSequencePath))] #[case( @@ -1182,12 +1182,11 @@ mod tests { )] #[case( "clients/07-tendermint-0/clientState", - Path::ClientState(ClientStatePath("07-tendermint-0".into())) - )] + Path::ClientState(ClientStatePath(DUMMY_CLIENT_ID.into())))] #[case( "clients/07-tendermint-0/consensusStates/15-31", Path::ClientConsensusState(ClientConsensusStatePath { - client_id: "07-tendermint-0".into(), + client_id: DUMMY_CLIENT_ID.into(), revision_number: 15, revision_height: 31, }) @@ -1195,7 +1194,7 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedTime", Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: "07-tendermint-0".into(), + client_id: DUMMY_CLIENT_ID.into(), revision_number: 15, revision_height: 31, }) @@ -1203,7 +1202,7 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedHeight", Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: "07-tendermint-0".into(), + client_id: DUMMY_CLIENT_ID.into(), revision_number: 15, revision_height: 31, }) @@ -1289,7 +1288,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientState(ClientStatePath(ClientId::from( - "07-tendermint-0" + DUMMY_CLIENT_ID )))) ); @@ -1299,7 +1298,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientConsensusState(ClientConsensusStatePath { - client_id: "07-tendermint-0".into(), + client_id: DUMMY_CLIENT_ID.into(), revision_number: 15, revision_height: 31, })) @@ -1314,7 +1313,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: "07-tendermint-0".into(), + client_id: DUMMY_CLIENT_ID.into(), revision_number: 15, revision_height: 31, })) @@ -1326,7 +1325,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: "07-tendermint-0".into(), + client_id: DUMMY_CLIENT_ID.into(), revision_number: 15, revision_height: 31, })) From a206527d17065b3d93d89b1bff2e308bee0fd55e Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 09:40:04 +0700 Subject: [PATCH 26/34] chore: remove commented out impl Default --- .../types/src/trust_threshold.rs | 6 ------ ibc-core/ics03-connection/types/src/version.rs | 9 --------- .../types/src/identifiers/connection_id.rs | 6 ------ ibc-core/ics24-host/types/src/path.rs | 18 +++++++++--------- 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs b/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs index edc430fa0..07f2bbb70 100644 --- a/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs +++ b/ibc-clients/ics07-tendermint/types/src/trust_threshold.rs @@ -134,12 +134,6 @@ impl TryFrom for TrustThreshold { } } -// impl Default for TrustThreshold { -// fn default() -> Self { -// Self::ONE_THIRD -// } -// } - impl Display for TrustThreshold { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { write!(f, "{}/{}", self.numerator, self.denominator) diff --git a/ibc-core/ics03-connection/types/src/version.rs b/ibc-core/ics03-connection/types/src/version.rs index 886be1318..e1f8c4f3e 100644 --- a/ibc-core/ics03-connection/types/src/version.rs +++ b/ibc-core/ics03-connection/types/src/version.rs @@ -96,15 +96,6 @@ impl From for RawVersion { } } -// impl Default for Version { -// fn default() -> Self { -// Version { -// identifier: "1".to_string(), -// features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], -// } -// } -// } - impl Display for Version { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!( diff --git a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs index 30b6cde9f..883c41138 100644 --- a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs @@ -78,12 +78,6 @@ impl FromStr for ConnectionId { } } -// impl Default for ConnectionId { -// fn default() -> Self { -// Self::new(0) -// } -// } - /// Equality check against string literal (satisfies &ConnectionId == &str). /// ``` /// use core::str::FromStr; diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index 8ca0158bd..5374333e1 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1169,7 +1169,7 @@ fn parse_upgrades(components: &[&str]) -> Option { #[cfg(test)] mod tests { use super::*; - const DUMMY_CLIENT_ID: &str = "07-tendermint-0"; + const DEFAULT_CLIENT_ID: &str = "07-tendermint-0"; #[rstest::rstest] #[case(NEXT_CLIENT_SEQUENCE, Path::NextClientSequence(NextClientSequencePath))] #[case( @@ -1182,11 +1182,11 @@ mod tests { )] #[case( "clients/07-tendermint-0/clientState", - Path::ClientState(ClientStatePath(DUMMY_CLIENT_ID.into())))] + Path::ClientState(ClientStatePath(DEFAULT_CLIENT_ID.into())))] #[case( "clients/07-tendermint-0/consensusStates/15-31", Path::ClientConsensusState(ClientConsensusStatePath { - client_id: DUMMY_CLIENT_ID.into(), + client_id: DEFAULT_CLIENT_ID.into(), revision_number: 15, revision_height: 31, }) @@ -1194,7 +1194,7 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedTime", Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: DUMMY_CLIENT_ID.into(), + client_id: DEFAULT_CLIENT_ID.into(), revision_number: 15, revision_height: 31, }) @@ -1202,7 +1202,7 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedHeight", Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: DUMMY_CLIENT_ID.into(), + client_id: DEFAULT_CLIENT_ID.into(), revision_number: 15, revision_height: 31, }) @@ -1288,7 +1288,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientState(ClientStatePath(ClientId::from( - DUMMY_CLIENT_ID + DEFAULT_CLIENT_ID )))) ); @@ -1298,7 +1298,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientConsensusState(ClientConsensusStatePath { - client_id: DUMMY_CLIENT_ID.into(), + client_id: DEFAULT_CLIENT_ID.into(), revision_number: 15, revision_height: 31, })) @@ -1313,7 +1313,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: DUMMY_CLIENT_ID.into(), + client_id: DEFAULT_CLIENT_ID.into(), revision_number: 15, revision_height: 31, })) @@ -1325,7 +1325,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: DUMMY_CLIENT_ID.into(), + client_id: DEFAULT_CLIENT_ID.into(), revision_number: 15, revision_height: 31, })) From 596eccb0f7148ae2ce732e8fce653ba112e8a8d8 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 11:13:08 +0700 Subject: [PATCH 27/34] add dummy ClientId --- ibc-core/ics24-host/types/src/path.rs | 29 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ibc-core/ics24-host/types/src/path.rs b/ibc-core/ics24-host/types/src/path.rs index 5374333e1..fe8acc647 100644 --- a/ibc-core/ics24-host/types/src/path.rs +++ b/ibc-core/ics24-host/types/src/path.rs @@ -1169,7 +1169,13 @@ fn parse_upgrades(components: &[&str]) -> Option { #[cfg(test)] mod tests { use super::*; - const DEFAULT_CLIENT_ID: &str = "07-tendermint-0"; + const DEFAULT_CLIENT_ID_STR: &str = "07-tendermint-0"; + impl ClientId { + pub fn new_dummy() -> Self { + ClientId::from_str(DEFAULT_CLIENT_ID_STR) + .expect("should not fail since we use a valid client id") + } + } #[rstest::rstest] #[case(NEXT_CLIENT_SEQUENCE, Path::NextClientSequence(NextClientSequencePath))] #[case( @@ -1182,11 +1188,12 @@ mod tests { )] #[case( "clients/07-tendermint-0/clientState", - Path::ClientState(ClientStatePath(DEFAULT_CLIENT_ID.into())))] + Path::ClientState(ClientStatePath(ClientId::new_dummy())) + )] #[case( "clients/07-tendermint-0/consensusStates/15-31", Path::ClientConsensusState(ClientConsensusStatePath { - client_id: DEFAULT_CLIENT_ID.into(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, }) @@ -1194,7 +1201,7 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedTime", Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: DEFAULT_CLIENT_ID.into(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, }) @@ -1202,14 +1209,14 @@ mod tests { #[case( "clients/07-tendermint-0/consensusStates/15-31/processedHeight", Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: DEFAULT_CLIENT_ID.into(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, }) )] #[case( "clients/07-tendermint-0/connections", - Path::ClientConnection(ClientConnectionPath("07-tendermint-0".into())) + Path::ClientConnection(ClientConnectionPath(ClientId::new_dummy())) )] #[case( "connections/connection-0", @@ -1287,9 +1294,7 @@ mod tests { assert_eq!( parse_client_paths(&components), - Some(Path::ClientState(ClientStatePath(ClientId::from( - DEFAULT_CLIENT_ID - )))) + Some(Path::ClientState(ClientStatePath(ClientId::new_dummy()))) ); let path = "clients/07-tendermint-0/consensusStates/15-31"; @@ -1298,7 +1303,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientConsensusState(ClientConsensusStatePath { - client_id: DEFAULT_CLIENT_ID.into(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, })) @@ -1313,7 +1318,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateTime(ClientUpdateTimePath { - client_id: DEFAULT_CLIENT_ID.into(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, })) @@ -1325,7 +1330,7 @@ mod tests { assert_eq!( parse_client_paths(&components), Some(Path::ClientUpdateHeight(ClientUpdateHeightPath { - client_id: DEFAULT_CLIENT_ID.into(), + client_id: ClientId::new_dummy(), revision_number: 15, revision_height: 31, })) From 6aba54f852f111cdff7f1ccfba3a7f1e071140e8 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 11:13:35 +0700 Subject: [PATCH 28/34] refactor(ics24-host): remove From<&str> to avoid panic on host --- .../ics03-connection/types/src/connection.rs | 9 +++++++-- .../types/src/identifiers/client_id.rs | 6 ------ .../testapp/ibc/clients/mock/misbehaviour.rs | 7 +++---- ibc-testkit/src/testapp/ibc/core/types.rs | 2 +- .../tests/core/ics02_client/update_client.rs | 10 +++++----- .../core/ics04_channel/acknowledgement.rs | 11 +++++++---- .../tests/core/ics04_channel/recv_packet.rs | 13 +++++++++---- .../tests/core/ics04_channel/send_packet.rs | 8 +++++--- .../tests/core/ics04_channel/timeout.rs | 19 +++++++++++++------ .../core/ics04_channel/timeout_on_close.rs | 12 ++++++++---- 10 files changed, 58 insertions(+), 39 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index bc5172275..8225763a4 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -1,6 +1,7 @@ //! Defines the types that define a connection use core::fmt::{Display, Error as FmtError, Formatter}; +use core::str::FromStr; use core::time::Duration; use core::u64; @@ -210,8 +211,12 @@ impl TryFrom for ConnectionEnd { if state == State::Uninitialized { return ConnectionEnd::new( State::Uninitialized, - "07-tendermint-0".into(), - Counterparty::new("07-tendermint-0".into(), None, CommitmentPrefix::empty()), + ClientId::from_str("07-tendermint-0").expect("should not fail"), + Counterparty::new( + ClientId::from_str("07-tendermint-0").expect("should not fail"), + None, + CommitmentPrefix::empty(), + ), Vec::new(), ZERO_DURATION, ); diff --git a/ibc-core/ics24-host/types/src/identifiers/client_id.rs b/ibc-core/ics24-host/types/src/identifiers/client_id.rs index 25304adb3..ecbfe1cca 100644 --- a/ibc-core/ics24-host/types/src/identifiers/client_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/client_id.rs @@ -76,12 +76,6 @@ impl FromStr for ClientId { } } -impl From<&str> for ClientId { - fn from(s: &str) -> Self { - Self::from_str(s).expect("Invalid client id") - } -} - /// Equality check against string literal (satisfies &ClientId == &str). /// ``` /// use core::str::FromStr; diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index 04a5a10a5..969514aa9 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -1,11 +1,10 @@ +use crate::testapp::ibc::clients::mock::header::MockHeader; +use crate::testapp::ibc::clients::mock::proto::Misbehaviour as RawMisbehaviour; use ibc::core::client::types::error::ClientError; use ibc::core::host::types::identifiers::ClientId; use ibc::core::primitives::prelude::*; use ibc::primitives::proto::{Any, Protobuf}; -use crate::testapp::ibc::clients::mock::header::MockHeader; -use crate::testapp::ibc::clients::mock::proto::Misbehaviour as RawMisbehaviour; - pub const MOCK_MISBEHAVIOUR_TYPE_URL: &str = "/ibc.mock.Misbehavior"; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -23,7 +22,7 @@ impl TryFrom for Misbehaviour { fn try_from(raw: RawMisbehaviour) -> Result { Ok(Self { - client_id: "07-tendermint-0".into(), + client_id: ClientId::new("07-tendermint", 0).expect("no error"), header1: raw .header1 .ok_or(ClientError::MissingRawMisbehaviour)? diff --git a/ibc-testkit/src/testapp/ibc/core/types.rs b/ibc-testkit/src/testapp/ibc/core/types.rs index 535f39613..7793931ad 100644 --- a/ibc-testkit/src/testapp/ibc/core/types.rs +++ b/ibc-testkit/src/testapp/ibc/core/types.rs @@ -125,7 +125,7 @@ pub struct MockContext { pub struct MockClientConfig { #[builder(default = ChainId::new("mockZ-1").expect("no error"))] client_chain_id: ChainId, - #[builder(default = "07-tendermint-0".into())] + #[builder(default = ClientId::new("07-tendermint", 0).expect("no error"))] client_id: ClientId, #[builder(default = mock_client_type())] client_type: ClientType, diff --git a/ibc-testkit/tests/core/ics02_client/update_client.rs b/ibc-testkit/tests/core/ics02_client/update_client.rs index 5957c9cdf..78eb53006 100644 --- a/ibc-testkit/tests/core/ics02_client/update_client.rs +++ b/ibc-testkit/tests/core/ics02_client/update_client.rs @@ -43,7 +43,7 @@ struct Fixture { #[fixture] fn fixture() -> Fixture { - let client_id = ClientId::from("07-tendermint-0"); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let ctx = MockContext::default().with_client_config( MockClientConfig::builder() @@ -82,7 +82,7 @@ fn test_update_client_ok(fixture: Fixture) { mut router, } = fixture; - let client_id = ClientId::from("07-tendermint-0"); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let signer = dummy_account_id(); let timestamp = Timestamp::now(); @@ -114,7 +114,7 @@ fn test_update_client_ok(fixture: Fixture) { // client's height and ensures that `ConsensusState` is stored at the correct // path (header height). fn test_update_client_with_prev_header() { - let client_id = ClientId::from("07-tendermint-0"); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let chain_id_b = ChainId::new("mockgaiaA-0").unwrap(); let latest_height = Height::new(0, 42).unwrap(); let height_1 = Height::new(0, 43).unwrap(); @@ -780,7 +780,7 @@ fn test_update_client_events(fixture: Fixture) { mut router, } = fixture; - let client_id = ClientId::from("07-tendermint-0"); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let signer = dummy_account_id(); let timestamp = Timestamp::now(); @@ -841,7 +841,7 @@ fn test_misbehaviour_client_ok(fixture: Fixture) { mut router, } = fixture; - let client_id = ClientId::from("07-tendermint-0"); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let msg_envelope = msg_update_client(&client_id); let res = validate(&ctx, &router, msg_envelope.clone()); diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index f7ff3f88a..37bcd6643 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -12,7 +12,7 @@ use ibc::core::connection::types::{ use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::handler::types::msgs::MsgEnvelope; -use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::dummy_raw_msg_acknowledgement; @@ -34,6 +34,8 @@ struct Fixture { #[fixture] fn fixture() -> Fixture { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let client_height = Height::new(0, 2).unwrap(); let ctx = MockContext::default().with_client_config( MockClientConfig::builder() @@ -70,9 +72,9 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - "07-tendermint-0".into(), + default_client_id.clone(), ConnectionCounterparty::new( - "07-tendermint-0".into(), + default_client_id.clone(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -146,6 +148,7 @@ fn ack_success_no_packet_commitment(fixture: Fixture) { #[rstest] fn ack_success_happy_path(fixture: Fixture) { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); let Fixture { ctx, router, @@ -176,7 +179,7 @@ fn ack_success_happy_path(fixture: Fixture) { ); ctx.get_client_execution_context() .store_update_meta( - "07-tendermint-0".into(), + default_client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 4).unwrap(), diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index b6cedfacc..47b508d60 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -12,7 +12,7 @@ use ibc::core::connection::types::{ use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::handler::types::msgs::MsgEnvelope; -use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::{dummy_msg_recv_packet, dummy_raw_msg_recv_packet}; @@ -31,10 +31,13 @@ pub struct Fixture { pub msg: MsgRecvPacket, pub conn_end_on_b: ConnectionEnd, pub chan_end_on_b: ChannelEnd, + pub default_client_id: ClientId, } #[fixture] fn fixture() -> Fixture { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let context = MockContext::default(); let router = MockRouter::new_with_transfer(); @@ -59,9 +62,9 @@ fn fixture() -> Fixture { let conn_end_on_b = ConnectionEnd::new( ConnectionState::Open, - "07-tendermint-0".into(), + default_client_id.clone(), ConnectionCounterparty::new( - "07-tendermint-0".into(), + default_client_id.clone(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -78,6 +81,7 @@ fn fixture() -> Fixture { msg, conn_end_on_b, chan_end_on_b, + default_client_id, } } @@ -110,6 +114,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { chan_end_on_b, client_height, host_height, + default_client_id, .. } = fixture; @@ -142,7 +147,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { context .get_client_execution_context() .store_update_meta( - "07-tendermint-0".into(), + default_client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 66194da47..53b492f94 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -12,7 +12,7 @@ use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; -use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::dummy_raw_packet; use ibc_testkit::testapp::ibc::core::types::{MockClientConfig, MockContext}; @@ -20,6 +20,8 @@ use test_log::test; #[test] fn send_packet_processing() { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + struct Test { name: String, ctx: MockContext, @@ -40,9 +42,9 @@ fn send_packet_processing() { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - "07-tendermint-0".into(), + default_client_id.clone(), ConnectionCounterparty::new( - "07-tendermint-0".into(), + default_client_id.clone(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 7c3e7c281..117e70214 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -12,7 +12,7 @@ use ibc::core::connection::types::{ use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; use ibc::core::handler::types::msgs::MsgEnvelope; -use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::dummy_raw_msg_timeout; @@ -29,10 +29,13 @@ struct Fixture { conn_end_on_a: ConnectionEnd, chan_end_on_a_ordered: ChannelEnd, chan_end_on_a_unordered: ChannelEnd, + default_client_id: ClientId, } #[fixture] fn fixture() -> Fixture { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let client_height = Height::new(0, 2).unwrap(); let ctx = MockContext::default().with_client_config( MockClientConfig::builder() @@ -77,9 +80,9 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - "07-tendermint-0".into(), + default_client_id.clone(), ConnectionCounterparty::new( - "07-tendermint-0".into(), + default_client_id.clone(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -97,6 +100,7 @@ fn fixture() -> Fixture { conn_end_on_a, chan_end_on_a_ordered, chan_end_on_a_unordered, + default_client_id, } } @@ -170,6 +174,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { chan_end_on_a_unordered, conn_end_on_a, client_height, + default_client_id, .. } = fixture; @@ -205,7 +210,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { ); ctx.store_update_meta( - "07-tendermint-0".into(), + default_client_id, client_height, Timestamp::from_nanoseconds(5).unwrap(), Height::new(0, 4).unwrap(), @@ -261,6 +266,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { conn_end_on_a, packet_commitment, client_height, + default_client_id, .. } = fixture; @@ -287,7 +293,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { ctx.get_client_execution_context() .store_update_meta( - "07-tendermint-0".into(), + default_client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), @@ -311,6 +317,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { conn_end_on_a, packet_commitment, client_height, + default_client_id, .. } = fixture; @@ -332,7 +339,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { ); ctx.store_update_meta( - "07-tendermint-0".into(), + default_client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 4).unwrap(), diff --git a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs index 266fab3d2..17489a81a 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -11,7 +11,7 @@ use ibc::core::connection::types::{ }; use ibc::core::entrypoint::validate; use ibc::core::handler::types::msgs::MsgEnvelope; -use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; +use ibc::core::host::types::identifiers::{ChannelId, ClientId, ConnectionId, PortId}; use ibc::core::host::ExecutionContext; use ibc::core::primitives::*; use ibc_testkit::fixtures::core::channel::dummy_raw_msg_timeout_on_close; @@ -30,6 +30,8 @@ pub struct Fixture { #[fixture] fn fixture() -> Fixture { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let client_height = Height::new(0, 2).unwrap(); let context = MockContext::default().with_client_config( MockClientConfig::builder() @@ -64,9 +66,9 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - "07-tendermint-0".into(), + default_client_id.clone(), ConnectionCounterparty::new( - "07-tendermint-0".into(), + default_client_id.clone(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -131,6 +133,8 @@ fn timeout_on_close_success_no_packet_commitment(fixture: Fixture) { #[rstest] fn timeout_on_close_success_happy_path(fixture: Fixture) { + let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let Fixture { context, router, @@ -153,7 +157,7 @@ fn timeout_on_close_success_happy_path(fixture: Fixture) { context .get_client_execution_context() .store_update_meta( - "07-tendermint-0".into(), + default_client_id, Height::new(0, 2).unwrap(), Timestamp::from_nanoseconds(5000).unwrap(), Height::new(0, 5).unwrap(), From 9f4bd71c74e52ca32df24d31ea6fee60a8a6e93b Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 11:37:53 +0700 Subject: [PATCH 29/34] remove get_compatible_versions --- .../architecture/adr-005-handlers-redesign.md | 29 ++++++++++++------- .../ics03-connection/types/src/version.rs | 11 ++----- ibc-core/ics24-host/src/context.rs | 8 ++--- .../fixtures/core/connection/conn_open_ack.rs | 4 +-- .../core/connection/conn_open_init.rs | 4 +-- .../fixtures/core/connection/conn_open_try.rs | 2 +- .../core/ics04_channel/acknowledgement.rs | 4 +-- .../core/ics04_channel/chan_close_confirm.rs | 6 ++-- .../core/ics04_channel/chan_close_init.rs | 6 ++-- .../tests/core/ics04_channel/chan_open_ack.rs | 4 +-- .../core/ics04_channel/chan_open_confirm.rs | 4 +-- .../core/ics04_channel/chan_open_init.rs | 4 +-- .../tests/core/ics04_channel/chan_open_try.rs | 4 +-- .../tests/core/ics04_channel/recv_packet.rs | 4 +-- .../tests/core/ics04_channel/send_packet.rs | 4 +-- .../tests/core/ics04_channel/timeout.rs | 4 +-- .../core/ics04_channel/timeout_on_close.rs | 4 +-- 17 files changed, 53 insertions(+), 53 deletions(-) diff --git a/docs/architecture/adr-005-handlers-redesign.md b/docs/architecture/adr-005-handlers-redesign.md index a4c25890a..6a1f2ecb1 100644 --- a/docs/architecture/adr-005-handlers-redesign.md +++ b/docs/architecture/adr-005-handlers-redesign.md @@ -1,10 +1,12 @@ # ADR 005: Handlers validation and execution separation ## Status + Accepted ## Changelog -* 9/9/2022: initial proposal + +- 9/9/2022: initial proposal ## Context @@ -15,9 +17,9 @@ Our current `deliver()` entrypoint can then be split into 2 entrypoints: `valida This ADR will only concern itself with the external-facing API. The following are out of scope for this ADR: -+ Exposing an `async` API -+ Enabling light clients to define and require the host to implement a set of traits +- Exposing an `async` API +- Enabling light clients to define and require the host to implement a set of traits ## Decision @@ -26,7 +28,8 @@ Below is a diagram of how the main components of this ADR fit together. ![Main components](./assets/adr05.jpg) ### Validation vs Execution -Each handler can be split into validation and execution. *Validation* is the set of statements which can make the transaction fail. It comprises all the "checks". Execution is the set of statements which mutate the state. In the IBC standard handlers, validation occurs before execution. Note that execution can fail in practice, if say a write operation fails. + +Each handler can be split into validation and execution. _Validation_ is the set of statements which can make the transaction fail. It comprises all the "checks". Execution is the set of statements which mutate the state. In the IBC standard handlers, validation occurs before execution. Note that execution can fail in practice, if say a write operation fails. As an example, consider the [`UpdateClient` handler](https://github.com/cosmos/ibc/blob/main/spec/core/ics-002-client-semantics/README.md#update). @@ -54,6 +57,7 @@ function updateClient( ``` ### `ValidationContext` and `ExecutionContext` + Below, we define the `ValidationContext` and `ExecutionContext`. ```rust @@ -78,7 +82,7 @@ trait ExecutionContext { } ``` -A useful way to understand how these traits work together is in seeing how they *could* be used to implement `deliver()`. +A useful way to understand how these traits work together is in seeing how they _could_ be used to implement `deliver()`. ```rust fn deliver(val_ctx: &V, exec_ctx: &mut E, message: Any) -> Result<(), Error> { @@ -87,6 +91,7 @@ fn deliver(val_ctx: &V, exec_ctx: &mu exec_ctx.execute(message) } ``` + Note however that we will not implement `deliver()` this way for efficiency reasons (see [discussion](https://github.com/informalsystems/ibc-rs/issues/2582#issuecomment-1229988512)). ### Host based API @@ -209,18 +214,20 @@ See appendix C for an example of how we intend this to be used. ## Consequences ### Positive -+ Architectures that run "validation" separately from "execution" will now be able to use the handlers + +- Architectures that run "validation" separately from "execution" will now be able to use the handlers ### Negative -+ Still no async support -+ Light clients still cannot specify new requirements on the host `Context` + +- Still no async support +- Light clients still cannot specify new requirements on the host `Context` ### Neutral ## References -* [Issue #2582: ADR for redesigning the modules' API](https://github.com/informalsystems/ibc-rs/issues/2582) -* [ICS24 spec](https://github.com/cosmos/ibc/blob/1b73c158dcd3b08c6af3917618dce259e30bc21b/spec/core/ics-024-host-requirements/README.md) +- [Issue #2582: ADR for redesigning the modules' API](https://github.com/informalsystems/ibc-rs/issues/2582) +- [ICS24 spec](https://github.com/cosmos/ibc/blob/1b73c158dcd3b08c6af3917618dce259e30bc21b/spec/core/ics-024-host-requirements/README.md) ## Appendices @@ -296,7 +303,7 @@ trait ValidationContext { /// Function required by ICS 03. Returns the list of all possible versions that the connection /// handshake protocol supports. fn get_compatible_versions(&self) -> Vec { - get_compatible_versions() + Version::compatibles() } /// Function required by ICS 03. Returns one version out of the supplied list of versions, which the diff --git a/ibc-core/ics03-connection/types/src/version.rs b/ibc-core/ics03-connection/types/src/version.rs index e1f8c4f3e..278a411bd 100644 --- a/ibc-core/ics03-connection/types/src/version.rs +++ b/ibc-core/ics03-connection/types/src/version.rs @@ -107,11 +107,6 @@ impl Display for Version { } } -/// Returns the lists of supported versions -pub fn get_compatible_versions() -> Vec { - Version::compatibles() -} - /// Iterates over the descending ordered set of compatible IBC versions and /// selects the first version with a version identifier that is supported by the /// counterparty. The returned version contains a feature set with the @@ -187,7 +182,7 @@ mod tests { use ibc_proto::ibc::core::connection::v1::Version as RawVersion; use crate::error::ConnectionError; - use crate::version::{get_compatible_versions, pick_version, Version}; + use crate::version::{pick_version, Version}; fn get_dummy_features() -> Vec { vec!["ORDER_RANDOM".to_string(), "ORDER_UNORDERED".to_string()] @@ -353,8 +348,8 @@ mod tests { let tests: Vec = vec![ Test { name: "Compatible versions".to_string(), - supported: get_compatible_versions(), - counterparty: get_compatible_versions(), + supported: Version::compatibles(), + counterparty: Version::compatibles(), picked: Ok(Version { identifier: "1".to_string(), features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], diff --git a/ibc-core/ics24-host/src/context.rs b/ibc-core/ics24-host/src/context.rs index 9335fce60..7b19bf9a4 100644 --- a/ibc-core/ics24-host/src/context.rs +++ b/ibc-core/ics24-host/src/context.rs @@ -6,9 +6,7 @@ use ibc_core_channel_types::packet::Receipt; use ibc_core_client_context::prelude::*; use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentPrefix; -use ibc_core_connection_types::version::{ - get_compatible_versions, pick_version, Version as ConnectionVersion, -}; +use ibc_core_connection_types::version::{pick_version, Version as ConnectionVersion}; use ibc_core_connection_types::ConnectionEnd; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::IbcEvent; @@ -78,7 +76,7 @@ pub trait ValidationContext { /// Function required by ICS-03. Returns the list of all possible versions that the connection /// handshake protocol supports. fn get_compatible_versions(&self) -> Vec { - get_compatible_versions() + ConnectionVersion::compatibles() } /// Function required by ICS-03. Returns one version out of the supplied list of versions, which the @@ -88,7 +86,7 @@ pub trait ValidationContext { counterparty_candidate_versions: &[ConnectionVersion], ) -> Result { let version = pick_version( - &self.get_compatible_versions(), + &self. Version::compatibles(), counterparty_candidate_versions, )?; Ok(version) diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs index cb4656cc8..5b695a800 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs @@ -2,7 +2,7 @@ use ibc::core::client::types::proto::v1::Height as RawHeight; use ibc::core::client::types::Height; use ibc::core::connection::types::msgs::MsgConnectionOpenAck; use ibc::core::connection::types::proto::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::host::types::identifiers::ConnectionId; use ibc::core::primitives::prelude::*; @@ -38,7 +38,7 @@ pub fn dummy_raw_msg_conn_open_ack( }), client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), proof_client: dummy_proof(), - version: Some(get_compatible_versions()[0].clone().into()), + version: Some(Version::compatibles()[0].clone().into()), signer: dummy_bech32_account(), host_consensus_state_proof: vec![], } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs index d13b1936e..26e78988b 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs @@ -2,7 +2,7 @@ use ibc::core::connection::types::msgs::MsgConnectionOpenInit; use ibc::core::connection::types::proto::v1::{ MsgConnectionOpenInit as RawMsgConnectionOpenInit, Version as RawVersion, }; -use ibc::core::connection::types::version::{get_compatible_versions, Version}; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::Counterparty; use ibc::core::host::types::identifiers::ClientId; use ibc::core::primitives::prelude::*; @@ -73,7 +73,7 @@ pub fn dummy_raw_msg_conn_open_init() -> RawMsgConnectionOpenInit { RawMsgConnectionOpenInit { client_id: "07-tendermint-0".to_string(), counterparty: Some(dummy_raw_counterparty_conn(None)), - version: Some(get_compatible_versions()[0].clone().into()), + version: Some(Version::compatibles()[0].clone().into()), delay_period: 0, signer: dummy_bech32_account(), } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs index 3b2630e37..36da440e3 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs @@ -2,7 +2,7 @@ use ibc::core::client::types::proto::v1::Height as RawHeight; use ibc::core::client::types::Height; use ibc::core::connection::types::msgs::MsgConnectionOpenTry; use ibc::core::connection::types::proto::v1::MsgConnectionOpenTry as RawMsgConnectionOpenTry; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; use ibc::core::primitives::prelude::*; diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index 37bcd6643..9c117e120 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -5,7 +5,7 @@ use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -78,7 +78,7 @@ fn fixture() -> Fixture { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs index b430b8c00..7f8d4e622 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs @@ -1,7 +1,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State as ChannelState}; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelCloseConfirm}; use ibc::core::channel::types::Version; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -28,7 +28,7 @@ fn test_chan_close_confirm_validate() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -87,7 +87,7 @@ fn test_chan_close_confirm_execute() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs index c1ca85865..4d314e3d2 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs @@ -1,7 +1,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State as ChannelState}; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelCloseInit}; use ibc::core::channel::types::Version; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -26,7 +26,7 @@ fn test_chan_close_init_validate() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -86,7 +86,7 @@ fn test_chan_close_init_execute() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs index 6a584e2ca..426907037 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs @@ -2,7 +2,7 @@ use ibc::apps::transfer::types::MODULE_ID_STR; use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State}; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenAck}; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -46,7 +46,7 @@ fn fixture() -> Fixture { ConnectionState::Open, client_id_on_a.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs index a29cd244c..28768e4a1 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs @@ -2,7 +2,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State} use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenConfirm}; use ibc::core::channel::types::Version; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -43,7 +43,7 @@ fn fixture() -> Fixture { ConnectionState::Open, client_id_on_b.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs index 60bc54a4e..575a0a12d 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs @@ -1,7 +1,7 @@ use ibc::clients::tendermint::types::client_type as tm_client_type; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenInit}; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ConnectionEnd, State as ConnectionState}; use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; @@ -40,7 +40,7 @@ fn fixture() -> Fixture { ConnectionState::Init, msg_conn_init.client_id_on_a.clone(), msg_conn_init.counterparty.clone(), - get_compatible_versions(), + Version::compatibles(), msg_conn_init.delay_period, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs index 35d8a55a7..203bd788c 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs @@ -1,6 +1,6 @@ use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenTry}; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -39,7 +39,7 @@ fn fixture() -> Fixture { ConnectionState::Open, client_id_on_b.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index 47b508d60..8d6fb34f0 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -5,7 +5,7 @@ use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -68,7 +68,7 @@ fn fixture() -> Fixture { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 53b492f94..0b69135cb 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -7,7 +7,7 @@ use ibc::core::channel::types::packet::Packet; use ibc::core::channel::types::Version; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -48,7 +48,7 @@ fn send_packet_processing() { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 117e70214..4d50294d7 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -5,7 +5,7 @@ use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -86,7 +86,7 @@ fn fixture() -> Fixture { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs index 17489a81a..f78ad2327 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -5,7 +5,7 @@ use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::get_compatible_versions; +use ibc::core::connection::types::version::Version; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -72,7 +72,7 @@ fn fixture() -> Fixture { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - get_compatible_versions(), + Version::compatibles(), ZERO_DURATION, ) .unwrap(); From 91dedf1a8559cca0ba87faf3183f2c50fd19731f Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 11:43:52 +0700 Subject: [PATCH 30/34] fix syntax error when import Version --- docs/architecture/adr-005-handlers-redesign.md | 2 +- ibc-core/ics24-host/src/context.rs | 2 +- ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs | 4 ++-- ibc-testkit/src/fixtures/core/connection/conn_open_init.rs | 6 +++--- ibc-testkit/src/fixtures/core/connection/conn_open_try.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/acknowledgement.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs | 6 +++--- ibc-testkit/tests/core/ics04_channel/chan_close_init.rs | 6 +++--- ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/chan_open_init.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/chan_open_try.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/recv_packet.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/send_packet.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/timeout.rs | 4 ++-- ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs | 4 ++-- 16 files changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/architecture/adr-005-handlers-redesign.md b/docs/architecture/adr-005-handlers-redesign.md index 6a1f2ecb1..30a04ef3b 100644 --- a/docs/architecture/adr-005-handlers-redesign.md +++ b/docs/architecture/adr-005-handlers-redesign.md @@ -303,7 +303,7 @@ trait ValidationContext { /// Function required by ICS 03. Returns the list of all possible versions that the connection /// handshake protocol supports. fn get_compatible_versions(&self) -> Vec { - Version::compatibles() + ConnectionVersion::compatibles() } /// Function required by ICS 03. Returns one version out of the supplied list of versions, which the diff --git a/ibc-core/ics24-host/src/context.rs b/ibc-core/ics24-host/src/context.rs index 7b19bf9a4..b390d6b83 100644 --- a/ibc-core/ics24-host/src/context.rs +++ b/ibc-core/ics24-host/src/context.rs @@ -86,7 +86,7 @@ pub trait ValidationContext { counterparty_candidate_versions: &[ConnectionVersion], ) -> Result { let version = pick_version( - &self. Version::compatibles(), + &self.get_compatible_versions(), counterparty_candidate_versions, )?; Ok(version) diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs index 5b695a800..863e79343 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs @@ -2,7 +2,7 @@ use ibc::core::client::types::proto::v1::Height as RawHeight; use ibc::core::client::types::Height; use ibc::core::connection::types::msgs::MsgConnectionOpenAck; use ibc::core::connection::types::proto::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::host::types::identifiers::ConnectionId; use ibc::core::primitives::prelude::*; @@ -38,7 +38,7 @@ pub fn dummy_raw_msg_conn_open_ack( }), client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), proof_client: dummy_proof(), - version: Some(Version::compatibles()[0].clone().into()), + version: Some(ConnectionVersion::compatibles()[0].clone().into()), signer: dummy_bech32_account(), host_consensus_state_proof: vec![], } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs index 26e78988b..8720c1895 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs @@ -2,7 +2,7 @@ use ibc::core::connection::types::msgs::MsgConnectionOpenInit; use ibc::core::connection::types::proto::v1::{ MsgConnectionOpenInit as RawMsgConnectionOpenInit, Version as RawVersion, }; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::Counterparty; use ibc::core::host::types::identifiers::ClientId; use ibc::core::primitives::prelude::*; @@ -57,7 +57,7 @@ pub fn msg_conn_open_with_version( identifier: Option<&str>, ) -> MsgConnectionOpenInit { let version = match identifier { - Some(v) => Version::try_from(RawVersion { + Some(v) => ConnectionVersion::try_from(RawVersion { identifier: v.to_string(), features: vec![], }) @@ -73,7 +73,7 @@ pub fn dummy_raw_msg_conn_open_init() -> RawMsgConnectionOpenInit { RawMsgConnectionOpenInit { client_id: "07-tendermint-0".to_string(), counterparty: Some(dummy_raw_counterparty_conn(None)), - version: Some(Version::compatibles()[0].clone().into()), + version: Some(ConnectionVersion::compatibles()[0].clone().into()), delay_period: 0, signer: dummy_bech32_account(), } diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs index 36da440e3..f415b5e70 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs @@ -2,7 +2,7 @@ use ibc::core::client::types::proto::v1::Height as RawHeight; use ibc::core::client::types::Height; use ibc::core::connection::types::msgs::MsgConnectionOpenTry; use ibc::core::connection::types::proto::v1::MsgConnectionOpenTry as RawMsgConnectionOpenTry; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::host::types::identifiers::{ClientId, ConnectionId}; use ibc::core::primitives::prelude::*; @@ -45,7 +45,7 @@ pub fn dummy_raw_msg_conn_open_try( client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), counterparty: Some(dummy_raw_counterparty_conn(Some(0))), delay_period: 0, - counterparty_versions: get_compatible_versions() + counterparty_versions: ConnectionVersion::compatibles() .iter() .map(|v| v.clone().into()) .collect(), diff --git a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs index 9c117e120..7ac747dc5 100644 --- a/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs +++ b/ibc-testkit/tests/core/ics04_channel/acknowledgement.rs @@ -5,7 +5,7 @@ use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -78,7 +78,7 @@ fn fixture() -> Fixture { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs index 7f8d4e622..14b358702 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_confirm.rs @@ -1,7 +1,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State as ChannelState}; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelCloseConfirm}; use ibc::core::channel::types::Version; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -28,7 +28,7 @@ fn test_chan_close_confirm_validate() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -87,7 +87,7 @@ fn test_chan_close_confirm_execute() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs index 4d314e3d2..00ee8cdab 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_close_init.rs @@ -1,7 +1,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State as ChannelState}; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelCloseInit}; use ibc::core::channel::types::Version; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -26,7 +26,7 @@ fn test_chan_close_init_validate() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); @@ -86,7 +86,7 @@ fn test_chan_close_init_execute() { ConnectionState::Open, client_id.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs index 426907037..8c3140910 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs @@ -2,7 +2,7 @@ use ibc::apps::transfer::types::MODULE_ID_STR; use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State}; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenAck}; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -46,7 +46,7 @@ fn fixture() -> Fixture { ConnectionState::Open, client_id_on_a.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs index 28768e4a1..c97338f2e 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_confirm.rs @@ -2,7 +2,7 @@ use ibc::core::channel::types::channel::{ChannelEnd, Counterparty, Order, State} use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenConfirm}; use ibc::core::channel::types::Version; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -43,7 +43,7 @@ fn fixture() -> Fixture { ConnectionState::Open, client_id_on_b.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs index 575a0a12d..a76f34d03 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_init.rs @@ -1,7 +1,7 @@ use ibc::clients::tendermint::types::client_type as tm_client_type; use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenInit}; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ConnectionEnd, State as ConnectionState}; use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::events::{IbcEvent, MessageEvent}; @@ -40,7 +40,7 @@ fn fixture() -> Fixture { ConnectionState::Init, msg_conn_init.client_id_on_a.clone(), msg_conn_init.counterparty.clone(), - Version::compatibles(), + ConnectionVersion::compatibles(), msg_conn_init.delay_period, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs b/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs index 203bd788c..e9b121dba 100644 --- a/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs +++ b/ibc-testkit/tests/core/ics04_channel/chan_open_try.rs @@ -1,6 +1,6 @@ use ibc::core::channel::types::msgs::{ChannelMsg, MsgChannelOpenTry}; use ibc::core::client::types::Height; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -39,7 +39,7 @@ fn fixture() -> Fixture { ConnectionState::Open, client_id_on_b.clone(), ConnectionCounterparty::try_from(dummy_raw_counterparty_conn(Some(0))).unwrap(), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index 8d6fb34f0..b221f937e 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -5,7 +5,7 @@ use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -68,7 +68,7 @@ fn fixture() -> Fixture { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/send_packet.rs b/ibc-testkit/tests/core/ics04_channel/send_packet.rs index 0b69135cb..acd58417a 100644 --- a/ibc-testkit/tests/core/ics04_channel/send_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/send_packet.rs @@ -7,7 +7,7 @@ use ibc::core::channel::types::packet::Packet; use ibc::core::channel::types::Version; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -48,7 +48,7 @@ fn send_packet_processing() { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 4d50294d7..773efe82b 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -5,7 +5,7 @@ use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -86,7 +86,7 @@ fn fixture() -> Fixture { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); diff --git a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs index f78ad2327..39a4c306a 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout_on_close.rs @@ -5,7 +5,7 @@ use ibc::core::channel::types::Version; use ibc::core::client::context::ClientExecutionContext; use ibc::core::client::types::Height; use ibc::core::commitment_types::commitment::CommitmentPrefix; -use ibc::core::connection::types::version::Version; +use ibc::core::connection::types::version::Version as ConnectionVersion; use ibc::core::connection::types::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, }; @@ -72,7 +72,7 @@ fn fixture() -> Fixture { Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), - Version::compatibles(), + ConnectionVersion::compatibles(), ZERO_DURATION, ) .unwrap(); From c7e86e8fef89effb68a62fa80501252d59e22a33 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 15:25:56 +0700 Subject: [PATCH 31/34] chore: run cargo fmt --- ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index 969514aa9..15ea17a40 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -1,10 +1,11 @@ -use crate::testapp::ibc::clients::mock::header::MockHeader; -use crate::testapp::ibc::clients::mock::proto::Misbehaviour as RawMisbehaviour; use ibc::core::client::types::error::ClientError; use ibc::core::host::types::identifiers::ClientId; use ibc::core::primitives::prelude::*; use ibc::primitives::proto::{Any, Protobuf}; +use crate::testapp::ibc::clients::mock::header::MockHeader; +use crate::testapp::ibc::clients::mock::proto::Misbehaviour as RawMisbehaviour; + pub const MOCK_MISBEHAVIOUR_TYPE_URL: &str = "/ibc.mock.Misbehavior"; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] From 4fd5dca17b69530305e57d2b7fe1e2e20b70a791 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Tue, 12 Mar 2024 23:25:07 +0700 Subject: [PATCH 32/34] revert markdown format --- .../architecture/adr-005-handlers-redesign.md | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/docs/architecture/adr-005-handlers-redesign.md b/docs/architecture/adr-005-handlers-redesign.md index 30a04ef3b..855a2b668 100644 --- a/docs/architecture/adr-005-handlers-redesign.md +++ b/docs/architecture/adr-005-handlers-redesign.md @@ -1,12 +1,10 @@ # ADR 005: Handlers validation and execution separation ## Status - Accepted ## Changelog - -- 9/9/2022: initial proposal +* 9/9/2022: initial proposal ## Context @@ -17,9 +15,9 @@ Our current `deliver()` entrypoint can then be split into 2 entrypoints: `valida This ADR will only concern itself with the external-facing API. The following are out of scope for this ADR: ++ Exposing an `async` API ++ Enabling light clients to define and require the host to implement a set of traits -- Exposing an `async` API -- Enabling light clients to define and require the host to implement a set of traits ## Decision @@ -28,8 +26,7 @@ Below is a diagram of how the main components of this ADR fit together. ![Main components](./assets/adr05.jpg) ### Validation vs Execution - -Each handler can be split into validation and execution. _Validation_ is the set of statements which can make the transaction fail. It comprises all the "checks". Execution is the set of statements which mutate the state. In the IBC standard handlers, validation occurs before execution. Note that execution can fail in practice, if say a write operation fails. +Each handler can be split into validation and execution. *Validation* is the set of statements which can make the transaction fail. It comprises all the "checks". Execution is the set of statements which mutate the state. In the IBC standard handlers, validation occurs before execution. Note that execution can fail in practice, if say a write operation fails. As an example, consider the [`UpdateClient` handler](https://github.com/cosmos/ibc/blob/main/spec/core/ics-002-client-semantics/README.md#update). @@ -57,7 +54,6 @@ function updateClient( ``` ### `ValidationContext` and `ExecutionContext` - Below, we define the `ValidationContext` and `ExecutionContext`. ```rust @@ -82,7 +78,7 @@ trait ExecutionContext { } ``` -A useful way to understand how these traits work together is in seeing how they _could_ be used to implement `deliver()`. +A useful way to understand how these traits work together is in seeing how they *could* be used to implement `deliver()`. ```rust fn deliver(val_ctx: &V, exec_ctx: &mut E, message: Any) -> Result<(), Error> { @@ -91,7 +87,6 @@ fn deliver(val_ctx: &V, exec_ctx: &mu exec_ctx.execute(message) } ``` - Note however that we will not implement `deliver()` this way for efficiency reasons (see [discussion](https://github.com/informalsystems/ibc-rs/issues/2582#issuecomment-1229988512)). ### Host based API @@ -214,20 +209,18 @@ See appendix C for an example of how we intend this to be used. ## Consequences ### Positive - -- Architectures that run "validation" separately from "execution" will now be able to use the handlers ++ Architectures that run "validation" separately from "execution" will now be able to use the handlers ### Negative - -- Still no async support -- Light clients still cannot specify new requirements on the host `Context` ++ Still no async support ++ Light clients still cannot specify new requirements on the host `Context` ### Neutral ## References -- [Issue #2582: ADR for redesigning the modules' API](https://github.com/informalsystems/ibc-rs/issues/2582) -- [ICS24 spec](https://github.com/cosmos/ibc/blob/1b73c158dcd3b08c6af3917618dce259e30bc21b/spec/core/ics-024-host-requirements/README.md) +* [Issue #2582: ADR for redesigning the modules' API](https://github.com/informalsystems/ibc-rs/issues/2582) +* [ICS24 spec](https://github.com/cosmos/ibc/blob/1b73c158dcd3b08c6af3917618dce259e30bc21b/spec/core/ics-024-host-requirements/README.md) ## Appendices From fdf2a7c4818dbaa8e36970cf971e8ce0d01eb29a Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Wed, 13 Mar 2024 00:09:15 +0700 Subject: [PATCH 33/34] various refactor --- .../ics03-connection/types/src/version.rs | 3 ++- .../core/connection/conn_open_init.rs | 2 +- .../fixtures/core/connection/conn_open_try.rs | 2 +- .../src/fixtures/core/connection/mod.rs | 2 +- ibc-testkit/src/testapp/ibc/core/types.rs | 2 +- .../tests/core/ics04_channel/recv_packet.rs | 14 ++++++------ .../tests/core/ics04_channel/timeout.rs | 22 +++++++++---------- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/version.rs b/ibc-core/ics03-connection/types/src/version.rs index 278a411bd..2979e2622 100644 --- a/ibc-core/ics03-connection/types/src/version.rs +++ b/ibc-core/ics03-connection/types/src/version.rs @@ -58,6 +58,7 @@ impl Version { } Ok(()) } + /// Returns the lists of supported versions pub fn compatibles() -> Vec { vec![Self { @@ -293,7 +294,7 @@ mod tests { name: "Compatible versions".to_string(), versions: vec![Version { identifier: "1".to_string(), - features: vec!["ORDER_ORDERED".to_string(), "ORDER_UNORDERED".to_string()], + features: get_dummy_features(), } .into()], want_pass: true, diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs index 8720c1895..07036f4fc 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_init.rs @@ -71,7 +71,7 @@ pub fn msg_conn_open_with_version( /// Returns a dummy `RawMsgConnectionOpenInit`, for testing purposes only! pub fn dummy_raw_msg_conn_open_init() -> RawMsgConnectionOpenInit { RawMsgConnectionOpenInit { - client_id: "07-tendermint-0".to_string(), + client_id: "07-tendermint-0".into(), counterparty: Some(dummy_raw_counterparty_conn(None)), version: Some(ConnectionVersion::compatibles()[0].clone().into()), delay_period: 0, diff --git a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs index f415b5e70..d3f9f60ea 100644 --- a/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs +++ b/ibc-testkit/src/fixtures/core/connection/conn_open_try.rs @@ -40,7 +40,7 @@ pub fn dummy_raw_msg_conn_open_try( #[allow(deprecated)] RawMsgConnectionOpenTry { - client_id: "07-tendermint-0".to_string(), + client_id: "07-tendermint-0".into(), previous_connection_id: ConnectionId::zero().to_string(), client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()), counterparty: Some(dummy_raw_counterparty_conn(Some(0))), diff --git a/ibc-testkit/src/fixtures/core/connection/mod.rs b/ibc-testkit/src/fixtures/core/connection/mod.rs index 329d06632..5b8388147 100644 --- a/ibc-testkit/src/fixtures/core/connection/mod.rs +++ b/ibc-testkit/src/fixtures/core/connection/mod.rs @@ -42,7 +42,7 @@ pub fn dummy_raw_counterparty_conn(conn_id: Option) -> RawCounterparty { None => "".to_string(), }; RawCounterparty { - client_id: "07-tendermint-0".to_string(), + client_id: "07-tendermint-0".into(), connection_id, prefix: Some(MerklePrefix { key_prefix: b"ibc".to_vec(), diff --git a/ibc-testkit/src/testapp/ibc/core/types.rs b/ibc-testkit/src/testapp/ibc/core/types.rs index 1cd6b306d..7e365c49c 100644 --- a/ibc-testkit/src/testapp/ibc/core/types.rs +++ b/ibc-testkit/src/testapp/ibc/core/types.rs @@ -125,7 +125,7 @@ pub struct MockContext { pub struct MockClientConfig { #[builder(default = ChainId::new("mockZ-1").expect("no error"))] client_chain_id: ChainId, - #[builder(default = ClientId::new("07-tendermint", 0).expect("no error"))] + #[builder(default = ClientId::new("07-tendermint", 0).expect("no error"))] client_id: ClientId, #[builder(default = mock_client_type())] client_type: ClientType, diff --git a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs index b221f937e..a11a90837 100644 --- a/ibc-testkit/tests/core/ics04_channel/recv_packet.rs +++ b/ibc-testkit/tests/core/ics04_channel/recv_packet.rs @@ -31,12 +31,12 @@ pub struct Fixture { pub msg: MsgRecvPacket, pub conn_end_on_b: ConnectionEnd, pub chan_end_on_b: ChannelEnd, - pub default_client_id: ClientId, + pub client_id: ClientId, } #[fixture] fn fixture() -> Fixture { - let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let context = MockContext::default(); @@ -62,9 +62,9 @@ fn fixture() -> Fixture { let conn_end_on_b = ConnectionEnd::new( ConnectionState::Open, - default_client_id.clone(), + client_id.clone(), ConnectionCounterparty::new( - default_client_id.clone(), + client_id.clone(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -81,7 +81,7 @@ fn fixture() -> Fixture { msg, conn_end_on_b, chan_end_on_b, - default_client_id, + client_id, } } @@ -114,7 +114,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { chan_end_on_b, client_height, host_height, - default_client_id, + client_id, .. } = fixture; @@ -147,7 +147,7 @@ fn recv_packet_validate_happy_path(fixture: Fixture) { context .get_client_execution_context() .store_update_meta( - default_client_id, + client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), diff --git a/ibc-testkit/tests/core/ics04_channel/timeout.rs b/ibc-testkit/tests/core/ics04_channel/timeout.rs index 773efe82b..05036636a 100644 --- a/ibc-testkit/tests/core/ics04_channel/timeout.rs +++ b/ibc-testkit/tests/core/ics04_channel/timeout.rs @@ -29,12 +29,12 @@ struct Fixture { conn_end_on_a: ConnectionEnd, chan_end_on_a_ordered: ChannelEnd, chan_end_on_a_unordered: ChannelEnd, - default_client_id: ClientId, + client_id: ClientId, } #[fixture] fn fixture() -> Fixture { - let default_client_id = ClientId::new("07-tendermint", 0).expect("no error"); + let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let client_height = Height::new(0, 2).unwrap(); let ctx = MockContext::default().with_client_config( @@ -80,9 +80,9 @@ fn fixture() -> Fixture { let conn_end_on_a = ConnectionEnd::new( ConnectionState::Open, - default_client_id.clone(), + client_id.clone(), ConnectionCounterparty::new( - default_client_id.clone(), + client_id.clone(), Some(ConnectionId::zero()), CommitmentPrefix::empty(), ), @@ -100,7 +100,7 @@ fn fixture() -> Fixture { conn_end_on_a, chan_end_on_a_ordered, chan_end_on_a_unordered, - default_client_id, + client_id, } } @@ -174,7 +174,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { chan_end_on_a_unordered, conn_end_on_a, client_height, - default_client_id, + client_id, .. } = fixture; @@ -210,7 +210,7 @@ fn timeout_fail_proof_timeout_not_reached(fixture: Fixture) { ); ctx.store_update_meta( - default_client_id, + client_id, client_height, Timestamp::from_nanoseconds(5).unwrap(), Height::new(0, 4).unwrap(), @@ -266,7 +266,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { conn_end_on_a, packet_commitment, client_height, - default_client_id, + client_id, .. } = fixture; @@ -293,7 +293,7 @@ fn timeout_unordered_channel_validate(fixture: Fixture) { ctx.get_client_execution_context() .store_update_meta( - default_client_id, + client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 5).unwrap(), @@ -317,7 +317,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { conn_end_on_a, packet_commitment, client_height, - default_client_id, + client_id, .. } = fixture; @@ -339,7 +339,7 @@ fn timeout_ordered_channel_validate(fixture: Fixture) { ); ctx.store_update_meta( - default_client_id, + client_id, client_height, Timestamp::from_nanoseconds(1000).unwrap(), Height::new(0, 4).unwrap(), From 46910f3adb24aacef97e5c75759552ef30849902 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Wed, 13 Mar 2024 00:10:44 +0700 Subject: [PATCH 34/34] chore: update unclog --- .../improvements/1074-refactor-default-implemetation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md b/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md index 1a7e66073..fcf1cafe6 100644 --- a/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md +++ b/.changelog/unreleased/improvements/1074-refactor-default-implemetation.md @@ -1,2 +1,2 @@ -- [types] Refactor Default implementations with concrete names - ([\#1074](https://github.com/cosmos/ibc-rs/issues/1074)) \ No newline at end of file +- [types] Refactor `Default` implementations with concrete names + ([\#1074](https://github.com/cosmos/ibc-rs/issues/1074))