1use anyhow::{bail, Result as AnyResult};
2use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage};
3use cosmwasm_std::{
4 Addr, Api, Binary, BlockInfo, CustomQuery, Empty, Querier, QuerierResult, Storage,
5};
6use cosmwasm_std::{BankMsg, OwnedDeps};
7use cw_multi_test::{
8 App, AppResponse, BankKeeper, BasicAppBuilder, CosmosRouter, Module, WasmKeeper,
9};
10use schemars::JsonSchema;
11use serde::de::DeserializeOwned;
12use terp_sdk::{TerpMsgWrapper, TerpQuery};
13use std::fmt::Debug;
14use std::marker::PhantomData;
15use std::ops::{Deref, DerefMut};
16
17pub struct TerpModule {}
18
19pub type TerpDeps = OwnedDeps<MockStorage, MockApi, MockQuerier, TerpQuery>;
20
21pub fn mock_deps() -> TerpDeps {
22 OwnedDeps {
23 storage: MockStorage::default(),
24 api: MockApi::default(),
25 querier: MockQuerier::default(),
26 custom_query_type: PhantomData,
27 }
28}
29
30impl TerpModule {}
31
32impl Module for TerpModule {
33 type ExecT = TerpMsgWrapper;
34 type QueryT = Empty;
35 type SudoT = Empty;
36
37 fn execute<ExecC, QueryC>(
38 &self,
39 api: &dyn Api,
40 storage: &mut dyn Storage,
41 router: &dyn CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
42 block: &BlockInfo,
43 sender: Addr,
44 msg: TerpMsgWrapper,
45 ) -> AnyResult<AppResponse>
46 where
47 ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
48 QueryC: CustomQuery + DeserializeOwned + 'static,
49 {
50 let TerpMsgWrapper {
51 route: _,
52 msg_data,
53 version: _,
54 } = msg;
55
56 match msg_data {
57 terp_sdk::TerpMsg::FundCommunityPool { amount } => {
58 let msg = BankMsg::Send {
59 to_address: "community_pool".to_owned(),
60 amount,
61 }
62 .into();
63 router.execute(api, storage, block, sender, msg)?;
64 Ok(AppResponse::default())
65 }
66 }
80 }
81 fn sudo<ExecC, QueryC>(
82 &self,
83 _api: &dyn Api,
84 _storage: &mut dyn Storage,
85 _router: &dyn CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
86 _block: &BlockInfo,
87 _msg: Self::SudoT,
88 ) -> AnyResult<AppResponse>
89 where
90 ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
91 QueryC: CustomQuery + DeserializeOwned + 'static,
92 {
93 bail!("sudo not implemented")
94 }
95
96 fn query(
97 &self,
98 _api: &dyn Api,
99 _storage: &dyn Storage,
100 _querier: &dyn Querier,
101 _block: &BlockInfo,
102 request: Empty,
103 ) -> anyhow::Result<Binary> {
104 bail!("custom query not implemented {:?}", request)
105 }
106}
107
108pub type TerpBasicApp =
109 App<BankKeeper, MockApi, MockStorage, TerpModule, WasmKeeper<TerpMsgWrapper, Empty>>;
110
111pub struct TerpApp(TerpBasicApp);
112
113impl Deref for TerpApp {
114 type Target = TerpBasicApp;
115
116 fn deref(&self) -> &Self::Target {
117 &self.0
118 }
119}
120
121impl DerefMut for TerpApp {
122 fn deref_mut(&mut self) -> &mut Self::Target {
123 &mut self.0
124 }
125}
126
127impl Querier for TerpApp {
128 fn raw_query(&self, bin_request: &[u8]) -> QuerierResult {
129 self.0.raw_query(bin_request)
130 }
131}
132
133impl TerpApp {
134 pub fn new() -> Self {
135 Self(
136 BasicAppBuilder::<TerpMsgWrapper, Empty>::new_custom()
137 .with_custom(TerpModule {})
138 .build(|_, _, _| {}),
139 )
140 }
141}
142
143impl Default for TerpApp {
144 fn default() -> Self {
145 Self::new()
146 }
147}