pepsi/
integration_tests.rs

1#[cfg(test)]
2mod tests {
3    use crate::helpers::CwTemplateContract;
4    use crate::msg::InstantiateMsg;
5    use cosmwasm_std::{Addr, Coin, Empty, Uint128};
6    use cw_multi_test::{App, AppBuilder, Contract, ContractWrapper, Executor};
7
8    pub fn contract_template() -> Box<dyn Contract<Empty>> {
9        let contract = ContractWrapper::new(
10            crate::contract::execute,
11            crate::contract::instantiate,
12            crate::contract::query,
13        );
14        Box::new(contract)
15    }
16
17    const USER: &str = "USER";
18    const ADMIN: &str = "ADMIN";
19    const NATIVE_DENOM: &str = "denom";
20
21    fn mock_app() -> App {
22        AppBuilder::new().build(|router, _, storage| {
23            router
24                .bank
25                .init_balance(
26                    storage,
27                    &Addr::unchecked(USER),
28                    vec![Coin {
29                        denom: NATIVE_DENOM.to_string(),
30                        amount: Uint128::new(1),
31                    }],
32                )
33                .unwrap();
34        })
35    }
36
37    fn proper_instantiate() -> (App, CwTemplateContract) {
38        let mut app = mock_app();
39        let cw_template_id = app.store_code(contract_template());
40
41        let msg = InstantiateMsg { count: 1i32 };
42        let cw_template_contract_addr = app
43            .instantiate_contract(
44                cw_template_id,
45                Addr::unchecked(ADMIN),
46                &msg,
47                &[],
48                "test",
49                None,
50            )
51            .unwrap();
52
53        let cw_template_contract = CwTemplateContract(cw_template_contract_addr);
54
55        (app, cw_template_contract)
56    }
57
58    mod count {
59        use super::*;
60        use crate::msg::ExecuteMsg;
61
62        #[test]
63        fn count() {
64            let (mut app, cw_template_contract) = proper_instantiate();
65
66            let msg = ExecuteMsg::Increment {};
67            let cosmos_msg = cw_template_contract.call(msg).unwrap();
68            app.execute(Addr::unchecked(USER), cosmos_msg).unwrap();
69        }
70    }
71}