Skip to content

Commit cd2addd

Browse files
committed
refactor: add Connection::zero()
1 parent 37ce288 commit cd2addd

File tree

14 files changed

+44
-39
lines changed

14 files changed

+44
-39
lines changed

ibc-core/ics03-connection/types/src/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ mod tests {
323323

324324
let client_type = ClientType::from_str("07-tendermint")
325325
.expect("never fails because it's a valid client type");
326-
let conn_id_on_a = ConnectionId::new(0);
326+
let conn_id_on_a = ConnectionId::zero();
327327
let client_id_on_a = client_type.build_client_id(0);
328328
let conn_id_on_b = ConnectionId::new(1);
329329
let client_id_on_b = client_type.build_client_id(1);

ibc-core/ics04-channel/types/src/events/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ mod tests {
11331133

11341134
let port_id = PortId::transfer();
11351135
let channel_id = ChannelId::zero();
1136-
let connection_id = ConnectionId::new(0);
1136+
let connection_id = ConnectionId::zero();
11371137
let counterparty_port_id = PortId::transfer();
11381138
let counterparty_channel_id = ChannelId::new(1);
11391139
let version = Version::new("ics20-1".to_string());

ibc-core/ics24-host/types/src/identifiers/connection_id.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ impl ConnectionId {
5656
pub fn as_bytes(&self) -> &[u8] {
5757
self.0.as_bytes()
5858
}
59+
60+
/// Return ConnectionId with identifier 0
61+
pub fn zero() -> Self {
62+
Self::new(0)
63+
}
5964
}
6065

6166
/// This implementation provides a `to_string` method.

ibc-core/ics24-host/types/src/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ mod tests {
12141214
)]
12151215
#[case(
12161216
"connections/connection-0",
1217-
Path::Connection(ConnectionPath(ConnectionId::new(0)))
1217+
Path::Connection(ConnectionPath(ConnectionId::zero()))
12181218
)]
12191219
#[case("ports/transfer", Path::Ports(PortPath(PortId::transfer())))]
12201220
#[case(
@@ -1340,7 +1340,7 @@ mod tests {
13401340

13411341
assert_eq!(
13421342
parse_connections(&components),
1343-
Some(Path::Connection(ConnectionPath(ConnectionId::new(0)))),
1343+
Some(Path::Connection(ConnectionPath(ConnectionId::zero()))),
13441344
);
13451345
}
13461346

ibc-testkit/src/fixtures/core/channel/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn dummy_raw_channel_end(state: i32, channel_id: Option<u64>) -> RawChannel
4646
state,
4747
ordering: 2,
4848
counterparty: Some(dummy_raw_counterparty_chan(channel_id)),
49-
connection_hops: vec![ConnectionId::new(0).to_string()],
49+
connection_hops: vec![ConnectionId::zero().to_string()],
5050
version: "".to_string(), // The version is not validated.
5151
}
5252
}

ibc-testkit/src/fixtures/core/channel/packet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ mod tests {
267267
let ibc_event = IbcEvent::SendPacket(SendPacket::new(
268268
packet,
269269
Order::Unordered,
270-
ConnectionId::new(0),
270+
ConnectionId::zero(),
271271
));
272272
let _ = tendermint::abci::Event::try_from(ibc_event);
273273
}

ibc-testkit/src/fixtures/core/connection/conn_open_ack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn dummy_raw_msg_conn_open_ack(
2424
) -> RawMsgConnectionOpenAck {
2525
let client_state_height = Height::new(0, consensus_height).expect("invalid height");
2626
RawMsgConnectionOpenAck {
27-
connection_id: ConnectionId::new(0).to_string(),
27+
connection_id: ConnectionId::zero().to_string(),
2828
counterparty_connection_id: ConnectionId::new(1).to_string(),
2929
proof_try: dummy_proof(),
3030
proof_height: Some(RawHeight {

ibc-testkit/src/fixtures/core/connection/conn_open_try.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn dummy_raw_msg_conn_open_try(
4141
#[allow(deprecated)]
4242
RawMsgConnectionOpenTry {
4343
client_id: ClientId::from("07-tendermint-0").to_string(),
44-
previous_connection_id: ConnectionId::new(0).to_string(),
44+
previous_connection_id: ConnectionId::zero().to_string(),
4545
client_state: Some(MockClientState::new(MockHeader::new(client_state_height)).into()),
4646
counterparty: Some(dummy_raw_counterparty_conn(Some(0))),
4747
delay_period: 0,

ibc-testkit/tests/core/ics04_channel/acknowledgement.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn fixture() -> Fixture {
6060
State::Open,
6161
Order::Unordered,
6262
Counterparty::new(packet.port_id_on_b, Some(packet.chan_id_on_b)),
63-
vec![ConnectionId::new(0)],
63+
vec![ConnectionId::zero()],
6464
Version::new("ics20-1".to_string()),
6565
)
6666
.unwrap();
@@ -73,7 +73,7 @@ fn fixture() -> Fixture {
7373
ClientId::from("07-tendermint-0"),
7474
ConnectionCounterparty::new(
7575
ClientId::from("07-tendermint-0"),
76-
Some(ConnectionId::new(0)),
76+
Some(ConnectionId::zero()),
7777
CommitmentPrefix::empty(),
7878
),
7979
get_compatible_versions(),
@@ -132,7 +132,7 @@ fn ack_success_no_packet_commitment(fixture: Fixture) {
132132
ChannelId::zero(),
133133
chan_end_on_a_unordered,
134134
)
135-
.with_connection(ConnectionId::new(0), conn_end_on_a);
135+
.with_connection(ConnectionId::zero(), conn_end_on_a);
136136

137137
let msg_envelope = MsgEnvelope::from(PacketMsg::from(msg));
138138

@@ -167,7 +167,7 @@ fn ack_success_happy_path(fixture: Fixture) {
167167
ChannelId::zero(),
168168
chan_end_on_a_unordered,
169169
)
170-
.with_connection(ConnectionId::new(0), conn_end_on_a)
170+
.with_connection(ConnectionId::zero(), conn_end_on_a)
171171
.with_packet_commitment(
172172
msg.packet.port_id_on_a.clone(),
173173
msg.packet.chan_id_on_a.clone(),
@@ -210,7 +210,7 @@ fn ack_unordered_chan_execute(fixture: Fixture) {
210210
ChannelId::zero(),
211211
chan_end_on_a_unordered,
212212
)
213-
.with_connection(ConnectionId::new(0), conn_end_on_a)
213+
.with_connection(ConnectionId::zero(), conn_end_on_a)
214214
.with_packet_commitment(
215215
msg.packet.port_id_on_a.clone(),
216216
msg.packet.chan_id_on_a.clone(),
@@ -247,7 +247,7 @@ fn ack_ordered_chan_execute(fixture: Fixture) {
247247
} = fixture;
248248
let mut ctx = ctx
249249
.with_channel(PortId::transfer(), ChannelId::zero(), chan_end_on_a_ordered)
250-
.with_connection(ConnectionId::new(0), conn_end_on_a)
250+
.with_connection(ConnectionId::zero(), conn_end_on_a)
251251
.with_packet_commitment(
252252
msg.packet.port_id_on_a.clone(),
253253
msg.packet.chan_id_on_a.clone(),

ibc-testkit/tests/core/ics04_channel/chan_open_init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn fixture() -> Fixture {
5252
.latest_height(client_height)
5353
.build(),
5454
)
55-
.with_connection(ConnectionId::new(0), conn_end_on_a);
55+
.with_connection(ConnectionId::zero(), conn_end_on_a);
5656

5757
Fixture { ctx, router, msg }
5858
}

0 commit comments

Comments
 (0)