Skip to content

Commit

Permalink
fix(ucs01): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen committed May 23, 2024
1 parent 56d67ec commit 1f9cc63
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 199 deletions.
204 changes: 107 additions & 97 deletions cosmwasm/ucs01-relay/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,25 +263,23 @@ mod tests {
let protocol_version = Ucs01Protocol::VERSION;
let counterparty_port_id = "port-2";
let counterparty_channel_id = "channel-2";
assert_eq!(
enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into()
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into()
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id
),
None
enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into(),
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into(),
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id,
),
Ok(())
);
None,
)
.unwrap();
}

#[test]
Expand All @@ -292,25 +290,23 @@ mod tests {
let protocol_version = Ics20Protocol::VERSION;
let counterparty_port_id = "port-2";
let counterparty_channel_id = "channel-2";
assert_eq!(
enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into()
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into()
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id
),
None
enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into(),
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into(),
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id,
),
Ok(())
);
None,
)
.unwrap()
}

#[test]
Expand All @@ -321,28 +317,31 @@ mod tests {
let protocol_version = "ucs01-0999";
let counterparty_port_id = "port-2";
let counterparty_channel_id = "channel-2";
assert_eq!(
enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into()
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into()
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id
),
None
match enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into(),
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into(),
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id,
),
None,
) {
Err(ContractError::UnknownProtocol {
channel_id: channel_id.into(),
protocol_version: protocol_version.into()
})
);
channel_id: unknown_channel_id,
protocol_version: unknown_protocol_version,
}) => {
assert_eq!(unknown_channel_id, channel_id);
assert_eq!(unknown_protocol_version, protocol_version);
}
_ => panic!(),
}
}

#[test]
Expand All @@ -354,28 +353,31 @@ mod tests {
let counterparty_port_id = "port-2";
let counterparty_channel_id = "channel-2";
let counterparty_protocol_version = "ucs01-0999";
assert_eq!(
enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into()
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into()
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id
),
Some(counterparty_protocol_version)
match enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into(),
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into(),
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id,
),
Some(counterparty_protocol_version),
) {
Err(ContractError::UnknownProtocol {
channel_id: channel_id.into(),
protocol_version: counterparty_protocol_version.into()
})
);
channel_id: unknown_channel_id,
protocol_version: unknown_protocol_version,
}) => {
assert_eq!(unknown_channel_id, channel_id);
assert_eq!(unknown_protocol_version, counterparty_protocol_version);
}
_ => panic!(),
}
}

#[test]
Expand All @@ -387,28 +389,36 @@ mod tests {
let counterparty_port_id = "port-2";
let counterparty_channel_id = "channel-2";
let counterparty_protocol_version = Ics20Protocol::VERSION;
assert_eq!(
enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into()
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into()
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id
),
Some(counterparty_protocol_version)
let mismatch = enforce_order_and_version(
&IbcChannel::new(
IbcEndpoint {
port_id: port_id.into(),
channel_id: channel_id.into(),
},
IbcEndpoint {
port_id: counterparty_port_id.into(),
channel_id: counterparty_channel_id.into(),
},
cosmwasm_std::IbcOrder::Unordered,
protocol_version,
connection_id,
),
Err(ContractError::ProtocolMismatch {
channel_id: channel_id.into(),
protocol_version: protocol_version.into(),
counterparty_protocol_version: counterparty_protocol_version.into()
})
Some(counterparty_protocol_version),
);
match mismatch {
Err(ContractError::ProtocolMismatch {
channel_id: mismatch_channel_id,
protocol_version: mismatch_protocol_version,
counterparty_protocol_version: mismatch_counterparty_protocol_version,
}) => {
assert_eq!(mismatch_channel_id, channel_id);
assert_eq!(mismatch_protocol_version, protocol_version);
assert_eq!(
mismatch_counterparty_protocol_version,
counterparty_protocol_version
);
}
_ => panic!(),
}
}
}
Loading

0 comments on commit 1f9cc63

Please sign in to comment.