apollo_cw_multi_test/
ibc.rs1use cosmwasm_std::{Empty, IbcMsg, IbcQuery};
2
3use crate::{FailingModule, Module};
4
5pub trait Ibc: Module<ExecT = IbcMsg, QueryT = IbcQuery, SudoT = Empty> {}
6
7impl Ibc for FailingModule<IbcMsg, IbcQuery, Empty> {}
8
9#[cfg(test)]
10mod test {
11 use cosmwasm_std::{Addr, Binary, Empty, IbcMsg, IbcQuery};
12
13 use crate::test_helpers::contracts::stargate::{contract, ExecMsg};
14 use crate::{App, AppBuilder, AppResponse, Executor, Module};
15
16 use super::Ibc;
17
18 struct AcceptingModule;
19
20 impl Module for AcceptingModule {
21 type ExecT = IbcMsg;
22 type QueryT = IbcQuery;
23 type SudoT = Empty;
24
25 fn execute<ExecC, QueryC>(
26 &self,
27 _api: &dyn cosmwasm_std::Api,
28 _storage: &mut dyn cosmwasm_std::Storage,
29 _router: &dyn crate::CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
30 _block: &cosmwasm_std::BlockInfo,
31 _sender: cosmwasm_std::Addr,
32 _msg: Self::ExecT,
33 ) -> anyhow::Result<crate::AppResponse>
34 where
35 ExecC: std::fmt::Debug
36 + Clone
37 + PartialEq
38 + schemars::JsonSchema
39 + serde::de::DeserializeOwned
40 + 'static,
41 QueryC: cosmwasm_std::CustomQuery + serde::de::DeserializeOwned + 'static,
42 {
43 Ok(AppResponse::default())
44 }
45
46 fn sudo<ExecC, QueryC>(
47 &self,
48 _api: &dyn cosmwasm_std::Api,
49 _storage: &mut dyn cosmwasm_std::Storage,
50 _router: &dyn crate::CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
51 _block: &cosmwasm_std::BlockInfo,
52 _msg: Self::SudoT,
53 ) -> anyhow::Result<crate::AppResponse>
54 where
55 ExecC: std::fmt::Debug
56 + Clone
57 + PartialEq
58 + schemars::JsonSchema
59 + serde::de::DeserializeOwned
60 + 'static,
61 QueryC: cosmwasm_std::CustomQuery + serde::de::DeserializeOwned + 'static,
62 {
63 Ok(AppResponse::default())
64 }
65
66 fn query(
67 &self,
68 _api: &dyn cosmwasm_std::Api,
69 _storage: &dyn cosmwasm_std::Storage,
70 _querier: &dyn cosmwasm_std::Querier,
71 _block: &cosmwasm_std::BlockInfo,
72 _request: Self::QueryT,
73 ) -> anyhow::Result<cosmwasm_std::Binary> {
74 Ok(Binary::default())
75 }
76 }
77
78 impl Ibc for AcceptingModule {}
79
80 #[test]
81 fn default_ibc() {
82 let app = App::default();
83 let code = app.store_code(contract());
84 let contract = app
85 .instantiate_contract(
86 code,
87 Addr::unchecked("owner"),
88 &Empty {},
89 &[],
90 "contract",
91 None,
92 )
93 .unwrap();
94
95 app.execute_contract(Addr::unchecked("owner"), contract, &ExecMsg::Ibc {}, &[])
96 .unwrap_err();
97 }
98
99 #[test]
100 fn subsituting_ibc() {
101 let app = AppBuilder::new()
102 .with_ibc(AcceptingModule)
103 .build(|_, _, _| ());
104 let code = app.store_code(contract());
105 let contract = app
106 .instantiate_contract(
107 code,
108 Addr::unchecked("owner"),
109 &Empty {},
110 &[],
111 "contract",
112 None,
113 )
114 .unwrap();
115
116 app.execute_contract(Addr::unchecked("owner"), contract, &ExecMsg::Ibc {}, &[])
117 .unwrap();
118 }
119}