Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign channel types for ibc_channel_open #1008

Merged
merged 7 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/ibc-reflect-send/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn ibc_channel_open(_deps: DepsMut, _env: Env, msg: IbcChannelOpenMsg) -> St
}
// TODO: do we need to check counterparty version as well?
// This flow needs to be well documented
if let Some(counter_version) = channel.counterparty_version {
if let Some(counter_version) = msg.counterparty_version {
if counter_version.as_str() != IBC_VERSION {
return Err(StdError::generic_err(format!(
"Counterparty version must be `{}`",
Expand Down Expand Up @@ -281,7 +281,7 @@ mod tests {
fn connect(mut deps: DepsMut, channel_id: &str) {
// open packet has no counterparty version, connect does
let mut handshake_open = mock_ibc_channel_open(channel_id, IbcOrder::Ordered, IBC_VERSION);
handshake_open.channel.counterparty_version = None;
handshake_open.counterparty_version = None;
// first we try to open with a valid handshake
ibc_channel_open(deps.branch(), mock_env(), handshake_open).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion contracts/ibc-reflect-send/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn setup() -> Instance<MockApi, MockStorage, MockQuerier> {
fn connect(deps: &mut Instance<MockApi, MockStorage, MockQuerier>, channel_id: &str) {
// open packet has no counterparty version, connect does
let mut handshake_open = mock_ibc_channel_open(channel_id, IbcOrder::Ordered, IBC_VERSION);
handshake_open.channel.counterparty_version = None;
handshake_open.counterparty_version = None;
// first we try to open with a valid handshake
ibc_channel_open(deps, mock_env(), handshake_open).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions contracts/ibc-reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub fn ibc_channel_open(_deps: DepsMut, _env: Env, msg: IbcChannelOpenMsg) -> St
}
// TODO: do we need to check counterparty version as well?
// This flow needs to be well documented
if let Some(counter_version) = channel.counterparty_version {
if let Some(counter_version) = msg.counterparty_version {
if counter_version.as_str() != IBC_VERSION {
return Err(StdError::generic_err(format!(
"Counterparty version must be `{}`",
Expand Down Expand Up @@ -406,7 +406,7 @@ mod tests {
// open packet has no counterparty versin, connect does
// TODO: validate this with alpe
let mut handshake_open = mock_ibc_channel_open(channel_id, IbcOrder::Ordered, IBC_VERSION);
handshake_open.channel.counterparty_version = None;
handshake_open.counterparty_version = None;
// first we try to open with a valid handshake
ibc_channel_open(deps.branch(), mock_env(), handshake_open).unwrap();

Expand Down Expand Up @@ -463,7 +463,7 @@ mod tests {

// first we try to open with a valid handshake
let mut handshake_open = mock_ibc_channel_open(channel_id, IbcOrder::Ordered, IBC_VERSION);
handshake_open.channel.counterparty_version = None;
handshake_open.counterparty_version = None;
ibc_channel_open(deps.as_mut(), mock_env(), handshake_open).unwrap();

// then we connect (with counter-party version set)
Expand Down
4 changes: 2 additions & 2 deletions contracts/ibc-reflect/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn connect<T: Into<String>>(
let account: String = account.into();
// first we try to open with a valid handshake
let mut handshake_open = mock_ibc_channel_open(channel_id, IbcOrder::Ordered, IBC_VERSION);
handshake_open.channel.counterparty_version = None;
handshake_open.counterparty_version = None;
uint marked this conversation as resolved.
Show resolved Hide resolved
ibc_channel_open(deps, mock_env(), handshake_open).unwrap();

// then we connect (with counter-party version set)
Expand Down Expand Up @@ -137,7 +137,7 @@ fn proper_handshake_flow() {

// first we try to open with a valid handshake
let mut handshake_open = mock_ibc_channel_open(channel_id, IbcOrder::Ordered, IBC_VERSION);
handshake_open.channel.counterparty_version = None;
handshake_open.counterparty_version = None;
ibc_channel_open(&mut deps, mock_env(), handshake_open).unwrap();

// then we connect (with counter-party version set)
Expand Down
14 changes: 11 additions & 3 deletions packages/std/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ pub struct IbcChannel {
pub counterparty_endpoint: IbcEndpoint,
pub order: IbcOrder,
pub version: String,
/// CounterpartyVersion can be None when not known this context, yet
pub counterparty_version: Option<String>,
/// The connection upon which this channel was created. If this is a multi-hop
/// channel, we only expose the first hop.
pub connection_id: String,
Expand Down Expand Up @@ -215,11 +213,21 @@ impl IbcAcknowledgement {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct IbcChannelOpenMsg {
pub channel: IbcChannel,
/// CounterpartyVersion can be None when not known this context, yet
pub counterparty_version: Option<String>,
uint marked this conversation as resolved.
Show resolved Hide resolved
}

impl IbcChannelOpenMsg {
uint marked this conversation as resolved.
Show resolved Hide resolved
pub fn new(channel: IbcChannel) -> Self {
Self { channel }
Self {
channel,
counterparty_version: None,
}
}

pub fn counterparty_version(mut self, counterparty_version: impl Into<String>) -> Self {
uint marked this conversation as resolved.
Show resolved Hide resolved
self.counterparty_version = Some(counterparty_version.into());
self
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ fn mock_ibc_channel(my_channel_id: &str, order: IbcOrder, version: &str) -> IbcC
},
order,
version: version.to_string(),
counterparty_version: Some(version.to_string()),
connection_id: "connection-2".to_string(),
}
}
Expand All @@ -248,6 +247,7 @@ pub fn mock_ibc_channel_open(
version: &str,
) -> IbcChannelOpenMsg {
IbcChannelOpenMsg::new(mock_ibc_channel(my_channel_id, order, version))
.counterparty_version(version)
uint marked this conversation as resolved.
Show resolved Hide resolved
}

#[cfg(feature = "stargate")]
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ mod tests {
// first we try to open with a valid handshake
let mut handshake_open =
mock_ibc_channel_open(channel_id, IbcOrder::Ordered, IBC_VERSION);
handshake_open.channel.counterparty_version = None;
handshake_open.counterparty_version = None;
call_ibc_channel_open(instance, &mock_env(), &handshake_open)
.unwrap()
.unwrap();
Expand Down