Repository: CosmWasm/cosmwasm
Pull request #930 (2021-06-01 06:52:46)

Create limit constants for all IBC results


Patch:
diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs
index 5db73c269..2199f5d95 100644
--- a/packages/vm/src/calls.rs
+++ b/packages/vm/src/calls.rs
@@ -4,6 +4,10 @@ use std::fmt;
 use wasmer::Val;
 
 use cosmwasm_std::{ContractResult, Env, MessageInfo, QueryResponse, Reply, Response};
+#[cfg(feature = "stargate")]
+use cosmwasm_std::{
+    IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcPacket, IbcReceiveResponse,
+};
 
 use crate::backend::{BackendApi, Querier, Storage};
 use crate::conversion::ref_to_u32;
@@ -23,6 +27,24 @@ const RESULT_LIMIT_SUDO: usize = 100_000;
 const RESULT_LIMIT_REPLY: usize = 100_000;
 /// Max length (in bytes) of the result data from a query call.
 const RESULT_LIMIT_QUERY: usize = 100_000;
+/// Max length (in bytes) of the result data from a ibc_channel_open call.
+#[cfg(feature = "stargate")]
+const RESULT_LIMIT_IBC_CHANNEL_OPEN: usize = 100_000;
+/// Max length (in bytes) of the result data from a ibc_channel_connect call.
+#[cfg(feature = "stargate")]
+const RESULT_LIMIT_IBC_CHANNEL_CONNECT: usize = 100_000;
+/// Max length (in bytes) of the result data from a ibc_channel_close call.
+#[cfg(feature = "stargate")]
+const RESULT_LIMIT_IBC_CHANNEL_CLOSE: usize = 100_000;
+/// Max length (in bytes) of the result data from a ibc_packet_receive call.
+#[cfg(feature = "stargate")]
+const RESULT_LIMIT_IBC_PACKET_RECEIVE: usize = 100_000;
+/// Max length (in bytes) of the result data from a ibc_packet_ack call.
+#[cfg(feature = "stargate")]
+const RESULT_LIMIT_IBC_PACKET_ACK: usize = 100_000;
+/// Max length (in bytes) of the result data from a ibc_packet_timeout call.
+#[cfg(feature = "stargate")]
+const RESULT_LIMIT_IBC_PACKET_TIMEOUT: usize = 100_000;
 
 pub fn call_instantiate<A, S, Q, U>(
     instance: &mut Instance<A, S, Q>,
@@ -137,6 +159,119 @@ where
     Ok(result)
 }
 
+#[cfg(feature = "stargate")]
+pub fn call_ibc_channel_open<A, S, Q>(
+    instance: &mut Instance<A, S, Q>,
+    env: &Env,
+    channel: &IbcChannel,
+) -> VmResult<ContractResult<()>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+{
+    let env = to_vec(env)?;
+    let channel = to_vec(channel)?;
+    let data = call_ibc_channel_open_raw(instance, &env, &channel)?;
+    let result: ContractResult<()> = from_slice(&data)?;
+    Ok(result)
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_channel_connect<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: &Env,
+    channel: &IbcChannel,
+) -> VmResult<ContractResult<IbcBasicResponse<U>>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
+{
+    let env = to_vec(env)?;
+    let channel = to_vec(channel)?;
+    let data = call_ibc_channel_connect_raw(instance, &env, &channel)?;
+    let result = from_slice(&data)?;
+    Ok(result)
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_channel_close<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: &Env,
+    channel: &IbcChannel,
+) -> VmResult<ContractResult<IbcBasicResponse<U>>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
+{
+    let env = to_vec(env)?;
+    let channel = to_vec(channel)?;
+    let data = call_ibc_channel_close_raw(instance, &env, &channel)?;
+    let result = from_slice(&data)?;
+    Ok(result)
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_packet_receive<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: &Env,
+    packet: &IbcPacket,
+) -> VmResult<ContractResult<IbcReceiveResponse<U>>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
+{
+    let env = to_vec(env)?;
+    let packet = to_vec(packet)?;
+    let data = call_ibc_packet_receive_raw(instance, &env, &packet)?;
+    let result = from_slice(&data)?;
+    Ok(result)
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_packet_ack<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: &Env,
+    ack: &IbcAcknowledgement,
+) -> VmResult<ContractResult<IbcBasicResponse<U>>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
+{
+    let env = to_vec(env)?;
+    let ack = to_vec(ack)?;
+    let data = call_ibc_packet_ack_raw(instance, &env, &ack)?;
+    let result = from_slice(&data)?;
+    Ok(result)
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_packet_timeout<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: &Env,
+    packet: &IbcPacket,
+) -> VmResult<ContractResult<IbcBasicResponse<U>>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
+{
+    let env = to_vec(env)?;
+    let packet = to_vec(packet)?;
+    let data = call_ibc_packet_timeout_raw(instance, &env, &packet)?;
+    let result = from_slice(&data)?;
+    Ok(result)
+}
+
 /// Calls Wasm export "instantiate" and returns raw data from the contract.
 /// The result is length limited to prevent abuse but otherwise unchecked.
 pub fn call_instantiate_raw<A, S, Q>(
@@ -240,6 +375,126 @@ where
     call_raw(instance, "query", &[env, msg], RESULT_LIMIT_QUERY)
 }
 
+#[cfg(feature = "stargate")]
+pub fn call_ibc_channel_open_raw<A, S, Q>(
+    instance: &mut Instance<A, S, Q>,
+    env: &[u8],
+    channel: &[u8],
+) -> VmResult<Vec<u8>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+{
+    instance.set_storage_readonly(false);
+    call_raw(
+        instance,
+        "ibc_channel_open",
+        &[env, channel],
+        RESULT_LIMIT_IBC_CHANNEL_OPEN,
+    )
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_channel_connect_raw<A, S, Q>(
+    instance: &mut Instance<A, S, Q>,
+    env: &[u8],
+    channel: &[u8],
+) -> VmResult<Vec<u8>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+{
+    instance.set_storage_readonly(false);
+    call_raw(
+        instance,
+        "ibc_channel_connect",
+        &[env, channel],
+        RESULT_LIMIT_IBC_CHANNEL_CONNECT,
+    )
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_channel_close_raw<A, S, Q>(
+    instance: &mut Instance<A, S, Q>,
+    env: &[u8],
+    channel: &[u8],
+) -> VmResult<Vec<u8>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+{
+    instance.set_storage_readonly(false);
+    call_raw(
+        instance,
+        "ibc_channel_close",
+        &[env, channel],
+        RESULT_LIMIT_IBC_CHANNEL_CLOSE,
+    )
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_packet_receive_raw<A, S, Q>(
+    instance: &mut Instance<A, S, Q>,
+    env: &[u8],
+    packet: &[u8],
+) -> VmResult<Vec<u8>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+{
+    instance.set_storage_readonly(false);
+    call_raw(
+        instance,
+        "ibc_packet_receive",
+        &[env, packet],
+        RESULT_LIMIT_IBC_PACKET_RECEIVE,
+    )
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_packet_ack_raw<A, S, Q>(
+    instance: &mut Instance<A, S, Q>,
+    env: &[u8],
+    ack: &[u8],
+) -> VmResult<Vec<u8>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+{
+    instance.set_storage_readonly(false);
+    call_raw(
+        instance,
+        "ibc_packet_ack",
+        &[env, ack],
+        RESULT_LIMIT_IBC_PACKET_ACK,
+    )
+}
+
+#[cfg(feature = "stargate")]
+pub fn call_ibc_packet_timeout_raw<A, S, Q>(
+    instance: &mut Instance<A, S, Q>,
+    env: &[u8],
+    packet: &[u8],
+) -> VmResult<Vec<u8>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+{
+    instance.set_storage_readonly(false);
+    call_raw(
+        instance,
+        "ibc_packet_timeout",
+        &[env, packet],
+        RESULT_LIMIT_IBC_PACKET_TIMEOUT,
+    )
+}
+
 /// Calls a function with the given arguments.
 /// The exported function must return exactly one result (an offset to the result Region).
 pub(crate) fn call_raw<A, S, Q>(
@@ -348,4 +603,107 @@ mod tests {
         let query_response = contract_result.unwrap();
         assert_eq!(query_response.as_slice(), b"{\"verifier\":\"verifies\"}");
     }
+
+    #[cfg(feature = "stargate")]
+    mod ibc {
+        use super::*;
+        use crate::calls::{call_instantiate, call_reply};
+        use crate::testing::{
+            mock_env, mock_info, mock_instance, MockApi, MockQuerier, MockStorage,
+        };
+        use cosmwasm_std::testing::{mock_ibc_channel, mock_ibc_packet_ack};
+        use cosmwasm_std::{attr, Empty, Event, IbcOrder, Reply, SubcallResponse};
+        static CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
+        const IBC_VERSION: &str = "ibc-reflect-v1";
+        fn setup(
+            instance: &mut Instance<MockApi, MockStorage, MockQuerier>,
+            channel_id: &str,
+            account: &str,
+        ) {
+            // init
+            let info = mock_info("creator", &[]);
+            let msg = br#"{"reflect_code_id":77}"#;
+            call_instantiate::<_, _, _, Empty>(instance, &mock_env(), &info, msg)
+                .unwrap()
+                .unwrap();
+            // first we try to open with a valid handshake
+            let mut handshake_open = mock_ibc_channel(channel_id, IbcOrder::Ordered, IBC_VERSION);
+            handshake_open.counterparty_version = None;
+            call_ibc_channel_open(instance, &mock_env(), &handshake_open)
+                .unwrap()
+                .unwrap();
+            // then we connect (with counter-party version set)
+            let handshake_connect = mock_ibc_channel(channel_id, IbcOrder::Ordered, IBC_VERSION);
+            let res: IbcBasicResponse = call_ibc_channel_connect::<_, _, _, Empty>(
+                instance,
+                &mock_env(),
+                &handshake_connect,
+            )
+            .unwrap()
+            .unwrap();
+            assert_eq!(1, res.submessages.len());
+            let id = res.submessages[0].id;
+            let event = Event {
+                kind: "message".into(),
+                attributes: vec![attr("contract_address", &account)],
+            };
+            // which creates a reflect account. here we get the callback
+            let response = Reply {
+                id,
+                result: ContractResult::Ok(SubcallResponse {
+                    events: vec![event],
+                    data: None,
+                }),
+            };
+            call_reply::<_, _, _, Empty>(instance, &mock_env(), &response).unwrap();
+        }
+        const CHANNEL_ID: &str = "channel-123";
+        const ACCOUNT: &str = "account-456";
+        #[test]
+        fn call_ibc_channel_open_and_connect_works() {
+            let mut instance = mock_instance(&CONTRACT, &[]);
+            setup(&mut instance, CHANNEL_ID, ACCOUNT);
+        }
+        #[test]
+        fn call_ibc_channel_close_works() {
+            let mut instance = mock_instance(&CONTRACT, &[]);
+            setup(&mut instance, CHANNEL_ID, ACCOUNT);
+            let handshake_close = mock_ibc_channel(CHANNEL_ID, IbcOrder::Ordered, IBC_VERSION);
+            call_ibc_channel_close::<_, _, _, Empty>(&mut instance, &mock_env(), &handshake_close)
+                .unwrap()
+                .unwrap();
+        }
+        #[test]
+        fn call_ibc_packet_ack_works() {
+            let mut instance = mock_instance(&CONTRACT, &[]);
+            setup(&mut instance, CHANNEL_ID, ACCOUNT);
+            let packet = mock_ibc_packet_ack(CHANNEL_ID, br#"{}"#).unwrap();
+            let ack = IbcAcknowledgement {
+                acknowledgement: br#"{}"#.into(),
+                original_packet: packet,
+            };
+            call_ibc_packet_ack::<_, _, _, Empty>(&mut instance, &mock_env(), &ack)
+                .unwrap()
+                .unwrap();
+        }
+        #[test]
+        fn call_ibc_packet_timeout_works() {
+            let mut instance = mock_instance(&CONTRACT, &[]);
+            setup(&mut instance, CHANNEL_ID, ACCOUNT);
+            let packet = mock_ibc_packet_ack(CHANNEL_ID, br#"{}"#).unwrap();
+            call_ibc_packet_timeout::<_, _, _, Empty>(&mut instance, &mock_env(), &packet)
+                .unwrap()
+                .unwrap();
+        }
+        #[test]
+        fn call_ibc_packet_receive_works() {
+            let mut instance = mock_instance(&CONTRACT, &[]);
+            setup(&mut instance, CHANNEL_ID, ACCOUNT);
+            let who_am_i = br#"{"who_am_i":{}}"#;
+            let packet = mock_ibc_packet_ack(CHANNEL_ID, who_am_i).unwrap();
+            call_ibc_packet_receive::<_, _, _, Empty>(&mut instance, &mock_env(), &packet)
+                .unwrap()
+                .unwrap();
+        }
+    }
 }
diff --git a/packages/vm/src/ibc_calls.rs b/packages/vm/src/ibc_calls.rs
deleted file mode 100644
index 3c1cf1d21..000000000
--- a/packages/vm/src/ibc_calls.rs
+++ /dev/null
@@ -1,349 +0,0 @@
-#![cfg(feature = "stargate")]
-
-use cosmwasm_std::{
-    ContractResult, Env, IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcPacket,
-    IbcReceiveResponse,
-};
-use schemars::JsonSchema;
-use serde::de::DeserializeOwned;
-use std::fmt;
-
-use crate::backend::{BackendApi, Querier, Storage};
-use crate::calls::call_raw;
-use crate::errors::VmResult;
-use crate::instance::Instance;
-use crate::serde::{from_slice, to_vec};
-
-const MAX_LENGTH_IBC: usize = 100_000;
-
-pub fn call_ibc_channel_open<A, S, Q>(
-    instance: &mut Instance<A, S, Q>,
-    env: &Env,
-    channel: &IbcChannel,
-) -> VmResult<ContractResult<()>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-{
-    let env = to_vec(env)?;
-    let channel = to_vec(channel)?;
-    let data = call_ibc_channel_open_raw(instance, &env, &channel)?;
-    let result: ContractResult<()> = from_slice(&data)?;
-    Ok(result)
-}
-
-pub fn call_ibc_channel_connect<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: &Env,
-    channel: &IbcChannel,
-) -> VmResult<ContractResult<IbcBasicResponse<U>>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
-{
-    let env = to_vec(env)?;
-    let channel = to_vec(channel)?;
-    let data = call_ibc_channel_connect_raw(instance, &env, &channel)?;
-    let result = from_slice(&data)?;
-    Ok(result)
-}
-
-pub fn call_ibc_channel_close<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: &Env,
-    channel: &IbcChannel,
-) -> VmResult<ContractResult<IbcBasicResponse<U>>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
-{
-    let env = to_vec(env)?;
-    let channel = to_vec(channel)?;
-    let data = call_ibc_channel_close_raw(instance, &env, &channel)?;
-    let result = from_slice(&data)?;
-    Ok(result)
-}
-
-pub fn call_ibc_packet_receive<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: &Env,
-    packet: &IbcPacket,
-) -> VmResult<ContractResult<IbcReceiveResponse<U>>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
-{
-    let env = to_vec(env)?;
-    let packet = to_vec(packet)?;
-    let data = call_ibc_packet_receive_raw(instance, &env, &packet)?;
-    let result = from_slice(&data)?;
-    Ok(result)
-}
-
-pub fn call_ibc_packet_ack<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: &Env,
-    ack: &IbcAcknowledgement,
-) -> VmResult<ContractResult<IbcBasicResponse<U>>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
-{
-    let env = to_vec(env)?;
-    let ack = to_vec(ack)?;
-    let data = call_ibc_packet_ack_raw(instance, &env, &ack)?;
-    let result = from_slice(&data)?;
-    Ok(result)
-}
-
-pub fn call_ibc_packet_timeout<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: &Env,
-    packet: &IbcPacket,
-) -> VmResult<ContractResult<IbcBasicResponse<U>>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + fmt::Debug + JsonSchema + PartialEq,
-{
-    let env = to_vec(env)?;
-    let packet = to_vec(packet)?;
-    let data = call_ibc_packet_timeout_raw(instance, &env, &packet)?;
-    let result = from_slice(&data)?;
-    Ok(result)
-}
-
-pub fn call_ibc_channel_open_raw<A, S, Q>(
-    instance: &mut Instance<A, S, Q>,
-    env: &[u8],
-    channel: &[u8],
-) -> VmResult<Vec<u8>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-{
-    instance.set_storage_readonly(false);
-    call_raw(
-        instance,
-        "ibc_channel_open",
-        &[env, channel],
-        MAX_LENGTH_IBC,
-    )
-}
-
-pub fn call_ibc_channel_connect_raw<A, S, Q>(
-    instance: &mut Instance<A, S, Q>,
-    env: &[u8],
-    channel: &[u8],
-) -> VmResult<Vec<u8>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-{
-    instance.set_storage_readonly(false);
-    call_raw(
-        instance,
-        "ibc_channel_connect",
-        &[env, channel],
-        MAX_LENGTH_IBC,
-    )
-}
-
-pub fn call_ibc_channel_close_raw<A, S, Q>(
-    instance: &mut Instance<A, S, Q>,
-    env: &[u8],
-    channel: &[u8],
-) -> VmResult<Vec<u8>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-{
-    instance.set_storage_readonly(false);
-    call_raw(
-        instance,
-        "ibc_channel_close",
-        &[env, channel],
-        MAX_LENGTH_IBC,
-    )
-}
-
-pub fn call_ibc_packet_receive_raw<A, S, Q>(
-    instance: &mut Instance<A, S, Q>,
-    env: &[u8],
-    packet: &[u8],
-) -> VmResult<Vec<u8>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-{
-    instance.set_storage_readonly(false);
-    call_raw(
-        instance,
-        "ibc_packet_receive",
-        &[env, packet],
-        MAX_LENGTH_IBC,
-    )
-}
-
-pub fn call_ibc_packet_ack_raw<A, S, Q>(
-    instance: &mut Instance<A, S, Q>,
-    env: &[u8],
-    ack: &[u8],
-) -> VmResult<Vec<u8>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-{
-    instance.set_storage_readonly(false);
-    call_raw(instance, "ibc_packet_ack", &[env, ack], MAX_LENGTH_IBC)
-}
-
-pub fn call_ibc_packet_timeout_raw<A, S, Q>(
-    instance: &mut Instance<A, S, Q>,
-    env: &[u8],
-    packet: &[u8],
-) -> VmResult<Vec<u8>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-{
-    instance.set_storage_readonly(false);
-    call_raw(
-        instance,
-        "ibc_packet_timeout",
-        &[env, packet],
-        MAX_LENGTH_IBC,
-    )
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-    use crate::calls::{call_instantiate, call_reply};
-    use crate::testing::{mock_env, mock_info, mock_instance, MockApi, MockQuerier, MockStorage};
-    use cosmwasm_std::testing::{mock_ibc_channel, mock_ibc_packet_ack};
-    use cosmwasm_std::{attr, Empty, Event, IbcOrder, Reply, SubcallResponse};
-
-    static CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
-    const IBC_VERSION: &str = "ibc-reflect-v1";
-
-    fn setup(
-        instance: &mut Instance<MockApi, MockStorage, MockQuerier>,
-        channel_id: &str,
-        account: &str,
-    ) {
-        // init
-        let info = mock_info("creator", &[]);
-        let msg = br#"{"reflect_code_id":77}"#;
-        call_instantiate::<_, _, _, Empty>(instance, &mock_env(), &info, msg)
-            .unwrap()
-            .unwrap();
-
-        // first we try to open with a valid handshake
-        let mut handshake_open = mock_ibc_channel(channel_id, IbcOrder::Ordered, IBC_VERSION);
-        handshake_open.counterparty_version = None;
-        call_ibc_channel_open(instance, &mock_env(), &handshake_open)
-            .unwrap()
-            .unwrap();
-
-        // then we connect (with counter-party version set)
-        let handshake_connect = mock_ibc_channel(channel_id, IbcOrder::Ordered, IBC_VERSION);
-        let res: IbcBasicResponse =
-            call_ibc_channel_connect::<_, _, _, Empty>(instance, &mock_env(), &handshake_connect)
-                .unwrap()
-                .unwrap();
-        assert_eq!(1, res.submessages.len());
-        let id = res.submessages[0].id;
-
-        let event = Event {
-            kind: "message".into(),
-            attributes: vec![attr("contract_address", &account)],
-        };
-        // which creates a reflect account. here we get the callback
-        let response = Reply {
-            id,
-            result: ContractResult::Ok(SubcallResponse {
-                events: vec![event],
-                data: None,
-            }),
-        };
-        call_reply::<_, _, _, Empty>(instance, &mock_env(), &response).unwrap();
-    }
-
-    const CHANNEL_ID: &str = "channel-123";
-    const ACCOUNT: &str = "account-456";
-
-    #[test]
-    fn call_ibc_channel_open_and_connect_works() {
-        let mut instance = mock_instance(&CONTRACT, &[]);
-
-        setup(&mut instance, CHANNEL_ID, ACCOUNT);
-    }
-
-    #[test]
-    fn call_ibc_channel_close_works() {
-        let mut instance = mock_instance(&CONTRACT, &[]);
-        setup(&mut instance, CHANNEL_ID, ACCOUNT);
-
-        let handshake_close = mock_ibc_channel(CHANNEL_ID, IbcOrder::Ordered, IBC_VERSION);
-        call_ibc_channel_close::<_, _, _, Empty>(&mut instance, &mock_env(), &handshake_close)
-            .unwrap()
-            .unwrap();
-    }
-
-    #[test]
-    fn call_ibc_packet_ack_works() {
-        let mut instance = mock_instance(&CONTRACT, &[]);
-        setup(&mut instance, CHANNEL_ID, ACCOUNT);
-
-        let packet = mock_ibc_packet_ack(CHANNEL_ID, br#"{}"#).unwrap();
-        let ack = IbcAcknowledgement {
-            acknowledgement: br#"{}"#.into(),
-            original_packet: packet,
-        };
-        call_ibc_packet_ack::<_, _, _, Empty>(&mut instance, &mock_env(), &ack)
-            .unwrap()
-            .unwrap();
-    }
-
-    #[test]
-    fn call_ibc_packet_timeout_works() {
-        let mut instance = mock_instance(&CONTRACT, &[]);
-        setup(&mut instance, CHANNEL_ID, ACCOUNT);
-
-        let packet = mock_ibc_packet_ack(CHANNEL_ID, br#"{}"#).unwrap();
-        call_ibc_packet_timeout::<_, _, _, Empty>(&mut instance, &mock_env(), &packet)
-            .unwrap()
-            .unwrap();
-    }
-
-    #[test]
-    fn call_ibc_packet_receive_works() {
-        let mut instance = mock_instance(&CONTRACT, &[]);
-
-        setup(&mut instance, CHANNEL_ID, ACCOUNT);
-
-        let who_am_i = br#"{"who_am_i":{}}"#;
-        let packet = mock_ibc_packet_ack(CHANNEL_ID, who_am_i).unwrap();
-
-        call_ibc_packet_receive::<_, _, _, Empty>(&mut instance, &mock_env(), &packet)
-            .unwrap()
-            .unwrap();
-    }
-}
diff --git a/packages/vm/src/lib.rs b/packages/vm/src/lib.rs
index 3f72cb8ab..ef65dff6c 100644
--- a/packages/vm/src/lib.rs
+++ b/packages/vm/src/lib.rs
@@ -9,8 +9,6 @@ mod conversion;
 mod environment;
 mod errors;
 mod features;
-#[cfg(feature = "stargate")]
-mod ibc_calls;
 mod imports;
 mod instance;
 mod limited;
@@ -33,20 +31,19 @@ pub use crate::calls::{
     call_migrate_raw, call_query, call_query_raw, call_reply, call_reply_raw, call_sudo,
     call_sudo_raw,
 };
-pub use crate::checksum::Checksum;
-
-pub use crate::errors::{
-    CommunicationError, CommunicationResult, RegionValidationError, RegionValidationResult,
-    VmError, VmResult,
-};
-pub use crate::features::features_from_csv;
 #[cfg(feature = "stargate")]
-pub use crate::ibc_calls::{
+pub use crate::calls::{
     call_ibc_channel_close, call_ibc_channel_close_raw, call_ibc_channel_connect,
     call_ibc_channel_connect_raw, call_ibc_channel_open, call_ibc_channel_open_raw,
     call_ibc_packet_ack, call_ibc_packet_ack_raw, call_ibc_packet_receive,
     call_ibc_packet_receive_raw, call_ibc_packet_timeout, call_ibc_packet_timeout_raw,
 };
+pub use crate::checksum::Checksum;
+pub use crate::errors::{
+    CommunicationError, CommunicationResult, RegionValidationError, RegionValidationResult,
+    VmError, VmResult,
+};
+pub use crate::features::features_from_csv;
 pub use crate::instance::{GasReport, Instance, InstanceOptions};
 pub use crate::serde::{from_slice, to_vec};
 pub use crate::size::Size;


Test patch:
diff --git a/packages/vm/src/testing/calls.rs b/packages/vm/src/testing/calls.rs
index 37c8bfaf3..443afbf76 100644
--- a/packages/vm/src/testing/calls.rs
+++ b/packages/vm/src/testing/calls.rs
@@ -6,10 +6,19 @@ use serde::{de::DeserializeOwned, Serialize};
 use std::fmt;
 
 use cosmwasm_std::{ContractResult, Env, MessageInfo, QueryResponse, Reply, Response};
+#[cfg(feature = "stargate")]
+use cosmwasm_std::{
+    IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcPacket, IbcReceiveResponse,
+};
 
 use crate::calls::{
     call_execute, call_instantiate, call_migrate, call_query, call_reply, call_sudo,
 };
+#[cfg(feature = "stargate")]
+use crate::calls::{
+    call_ibc_channel_close, call_ibc_channel_connect, call_ibc_channel_open, call_ibc_packet_ack,
+    call_ibc_packet_receive, call_ibc_packet_timeout,
+};
 use crate::instance::Instance;
 use crate::serde::to_vec;
 use crate::{BackendApi, Querier, Storage};
@@ -126,3 +135,110 @@ where
     let serialized_msg = to_vec(&msg).expect("Testing error: Could not seralize request message");
     call_query(instance, &env, &serialized_msg).expect("VM error")
 }
+
+// ibc_channel_open mimicks the call signature of the smart contracts.
+// thus it moves env and channel rather than take them as reference.
+// this is inefficient here, but only used in test code
+#[cfg(feature = "stargate")]
+pub fn ibc_channel_open<A, S, Q>(
+    instance: &mut Instance<A, S, Q>,
+    env: Env,
+    channel: IbcChannel,
+) -> ContractResult<()>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+{
+    call_ibc_channel_open(instance, &env, &channel).expect("VM error")
+}
+
+// ibc_channel_connect mimicks the call signature of the smart contracts.
+// thus it moves env and channel rather than take them as reference.
+// this is inefficient here, but only used in test code
+#[cfg(feature = "stargate")]
+pub fn ibc_channel_connect<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: Env,
+    channel: IbcChannel,
+) -> ContractResult<IbcBasicResponse<U>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
+{
+    call_ibc_channel_connect(instance, &env, &channel).expect("VM error")
+}
+
+// ibc_channel_close mimicks the call signature of the smart contracts.
+// thus it moves env and channel rather than take them as reference.
+// this is inefficient here, but only used in test code
+#[cfg(feature = "stargate")]
+pub fn ibc_channel_close<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: Env,
+    channel: IbcChannel,
+) -> ContractResult<IbcBasicResponse<U>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
+{
+    call_ibc_channel_close(instance, &env, &channel).expect("VM error")
+}
+
+// ibc_packet_receive mimicks the call signature of the smart contracts.
+// thus it moves env and packet rather than take them as reference.
+// this is inefficient here, but only used in test code
+#[cfg(feature = "stargate")]
+pub fn ibc_packet_receive<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: Env,
+    packet: IbcPacket,
+) -> ContractResult<IbcReceiveResponse<U>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
+{
+    call_ibc_packet_receive(instance, &env, &packet).expect("VM error")
+}
+
+// ibc_packet_ack mimicks the call signature of the smart contracts.
+// thus it moves env and acknowledgement rather than take them as reference.
+// this is inefficient here, but only used in test code
+#[cfg(feature = "stargate")]
+pub fn ibc_packet_ack<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: Env,
+    ack: IbcAcknowledgement,
+) -> ContractResult<IbcBasicResponse<U>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
+{
+    call_ibc_packet_ack(instance, &env, &ack).expect("VM error")
+}
+
+// ibc_packet_timeout mimicks the call signature of the smart contracts.
+// thus it moves env and packet rather than take them as reference.
+// this is inefficient here, but only used in test code
+#[cfg(feature = "stargate")]
+pub fn ibc_packet_timeout<A, S, Q, U>(
+    instance: &mut Instance<A, S, Q>,
+    env: Env,
+    packet: IbcPacket,
+) -> ContractResult<IbcBasicResponse<U>>
+where
+    A: BackendApi + 'static,
+    S: Storage + 'static,
+    Q: Querier + 'static,
+    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
+{
+    call_ibc_packet_timeout(instance, &env, &packet).expect("VM error")
+}
diff --git a/packages/vm/src/testing/ibc_calls.rs b/packages/vm/src/testing/ibc_calls.rs
deleted file mode 100644
index 6bedbb8a4..000000000
--- a/packages/vm/src/testing/ibc_calls.rs
+++ /dev/null
@@ -1,117 +0,0 @@
-#![cfg(feature = "stargate")]
-use schemars::JsonSchema;
-use serde::de::DeserializeOwned;
-use std::fmt;
-
-use cosmwasm_std::{
-    ContractResult, Env, IbcAcknowledgement, IbcBasicResponse, IbcChannel, IbcPacket,
-    IbcReceiveResponse,
-};
-
-use crate::ibc_calls::{
-    call_ibc_channel_close, call_ibc_channel_connect, call_ibc_channel_open, call_ibc_packet_ack,
-    call_ibc_packet_receive, call_ibc_packet_timeout,
-};
-use crate::instance::Instance;
-use crate::{BackendApi, Querier, Storage};
-
-// ibc_channel_open mimicks the call signature of the smart contracts.
-// thus it moves env and channel rather than take them as reference.
-// this is inefficient here, but only used in test code
-pub fn ibc_channel_open<A, S, Q>(
-    instance: &mut Instance<A, S, Q>,
-    env: Env,
-    channel: IbcChannel,
-) -> ContractResult<()>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-{
-    call_ibc_channel_open(instance, &env, &channel).expect("VM error")
-}
-
-// ibc_channel_connect mimicks the call signature of the smart contracts.
-// thus it moves env and channel rather than take them as reference.
-// this is inefficient here, but only used in test code
-pub fn ibc_channel_connect<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: Env,
-    channel: IbcChannel,
-) -> ContractResult<IbcBasicResponse<U>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
-{
-    call_ibc_channel_connect(instance, &env, &channel).expect("VM error")
-}
-
-// ibc_channel_close mimicks the call signature of the smart contracts.
-// thus it moves env and channel rather than take them as reference.
-// this is inefficient here, but only used in test code
-pub fn ibc_channel_close<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: Env,
-    channel: IbcChannel,
-) -> ContractResult<IbcBasicResponse<U>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
-{
-    call_ibc_channel_close(instance, &env, &channel).expect("VM error")
-}
-
-// ibc_packet_receive mimicks the call signature of the smart contracts.
-// thus it moves env and packet rather than take them as reference.
-// this is inefficient here, but only used in test code
-pub fn ibc_packet_receive<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: Env,
-    packet: IbcPacket,
-) -> ContractResult<IbcReceiveResponse<U>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
-{
-    call_ibc_packet_receive(instance, &env, &packet).expect("VM error")
-}
-
-// ibc_packet_ack mimicks the call signature of the smart contracts.
-// thus it moves env and acknowledgement rather than take them as reference.
-// this is inefficient here, but only used in test code
-pub fn ibc_packet_ack<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: Env,
-    ack: IbcAcknowledgement,
-) -> ContractResult<IbcBasicResponse<U>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
-{
-    call_ibc_packet_ack(instance, &env, &ack).expect("VM error")
-}
-
-// ibc_packet_timeout mimicks the call signature of the smart contracts.
-// thus it moves env and packet rather than take them as reference.
-// this is inefficient here, but only used in test code
-pub fn ibc_packet_timeout<A, S, Q, U>(
-    instance: &mut Instance<A, S, Q>,
-    env: Env,
-    packet: IbcPacket,
-) -> ContractResult<IbcBasicResponse<U>>
-where
-    A: BackendApi + 'static,
-    S: Storage + 'static,
-    Q: Querier + 'static,
-    U: DeserializeOwned + Clone + PartialEq + JsonSchema + fmt::Debug,
-{
-    call_ibc_packet_timeout(instance, &env, &packet).expect("VM error")
-}
diff --git a/packages/vm/src/testing/mod.rs b/packages/vm/src/testing/mod.rs
index 600893747..347258973 100644
--- a/packages/vm/src/testing/mod.rs
+++ b/packages/vm/src/testing/mod.rs
@@ -1,7 +1,6 @@
 // The external interface is `use cosmwasm_vm::testing::X` for all integration testing symbols, no matter where they live internally.
 
 mod calls;
-mod ibc_calls;
 mod instance;
 mod mock;
 mod querier;
@@ -9,7 +8,7 @@ mod storage;
 
 pub use calls::{execute, instantiate, migrate, query, reply, sudo};
 #[cfg(feature = "stargate")]
-pub use ibc_calls::{
+pub use calls::{
     ibc_channel_close, ibc_channel_connect, ibc_channel_open, ibc_packet_ack, ibc_packet_receive,
     ibc_packet_timeout,
 };