-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathlib.rs
More file actions
236 lines (215 loc) · 7.83 KB
/
Copy pathlib.rs
File metadata and controls
236 lines (215 loc) · 7.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
use sylvia::ctx::{ExecCtx, QueryCtx, SudoCtx};
use sylvia::cw_std::{CosmosMsg, Response, StdError};
use sylvia::interface;
use sylvia::types::{CustomMsg, CustomQuery};
#[interface]
pub trait CustomAndGeneric {
type Error: From<StdError>;
type Exec1T: CustomMsg;
type Exec2T: CustomMsg;
type Exec3T: CustomMsg;
type Query1T: CustomMsg;
type Query2T: CustomMsg;
type Query3T: CustomMsg;
type Sudo1T: CustomMsg;
type Sudo2T: CustomMsg;
type Sudo3T: CustomMsg;
type ExecC: CustomMsg;
type QueryC: CustomQuery + 'static;
type RetT: CustomMsg;
#[sv::msg(exec)]
fn custom_generic_execute_one(
&self,
ctx: ExecCtx<Self::QueryC>,
msgs1: Vec<CosmosMsg<Self::Exec1T>>,
msgs2: Vec<CosmosMsg<Self::Exec2T>>,
) -> Result<Response<Self::ExecC>, Self::Error>;
#[sv::msg(exec)]
fn custom_generic_execute_two(
&self,
ctx: ExecCtx<Self::QueryC>,
msgs1: Vec<CosmosMsg<Self::Exec2T>>,
msgs2: Vec<CosmosMsg<Self::Exec3T>>,
) -> Result<Response<Self::ExecC>, Self::Error>;
#[sv::msg(query)]
fn custom_generic_query_one(
&self,
ctx: QueryCtx<Self::QueryC>,
param1: Self::Query1T,
param2: Self::Query2T,
) -> Result<Self::RetT, Self::Error>;
#[sv::msg(query)]
fn custom_generic_query_two(
&self,
ctx: QueryCtx<Self::QueryC>,
param1: Self::Query2T,
param2: Self::Query3T,
) -> Result<Self::RetT, Self::Error>;
#[sv::msg(sudo)]
fn custom_generic_sudo_one(
&self,
ctx: SudoCtx<Self::QueryC>,
msg1: CosmosMsg<Self::Sudo1T>,
msg2: CosmosMsg<Self::Sudo2T>,
) -> Result<Response<Self::ExecC>, Self::Error>;
#[sv::msg(sudo)]
fn custom_generic_sudo_two(
&self,
ctx: SudoCtx<Self::QueryC>,
msg1: CosmosMsg<Self::Sudo2T>,
msg2: CosmosMsg<Self::Sudo3T>,
) -> Result<Response<Self::ExecC>, Self::Error>;
}
#[cfg(test)]
mod tests {
use sylvia::cw_std::testing::mock_dependencies;
use sylvia::cw_std::{Addr, CosmosMsg, Empty, QuerierWrapper};
use crate::sv::Querier;
#[sylvia::cw_schema::cw_serde(crate = "sylvia::cw_schema")]
pub struct SvCustomMsg;
impl sylvia::cw_std::CustomMsg for SvCustomMsg {}
#[sylvia::cw_schema::cw_serde(crate = "sylvia::cw_schema")]
pub struct SvCustomQuery;
impl sylvia::cw_std::CustomQuery for SvCustomQuery {}
#[test]
fn construct_messages() {
let contract = Addr::unchecked("contract");
// Direct message construction
let _ = super::sv::QueryMsg::<_, _, Empty, SvCustomMsg>::custom_generic_query_one(
SvCustomMsg {},
SvCustomMsg {},
);
let _ = super::sv::QueryMsg::<SvCustomMsg, _, Empty, _>::custom_generic_query_two(
SvCustomMsg {},
SvCustomMsg {},
);
let _ = super::sv::ExecMsg::<_, _, SvCustomMsg>::custom_generic_execute_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);
let _ = super::sv::ExecMsg::<SvCustomMsg, _, _>::custom_generic_execute_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);
// Querier
let deps = mock_dependencies();
let querier_wrapper: QuerierWrapper = QuerierWrapper::new(&deps.querier);
let querier = sylvia::types::BoundQuerier::<
_,
dyn super::CustomAndGeneric<
RetT = SvCustomMsg,
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
Error = (),
ExecC = SvCustomMsg,
QueryC = SvCustomQuery,
>,
>::borrowed(&contract, &querier_wrapper);
let _: Result<SvCustomMsg, _> =
super::sv::Querier::custom_generic_query_one(&querier, SvCustomMsg {}, SvCustomMsg {});
let _: Result<SvCustomMsg, _> =
querier.custom_generic_query_one(SvCustomMsg {}, SvCustomMsg {});
let _: Result<SvCustomMsg, _> =
super::sv::Querier::custom_generic_query_two(&querier, SvCustomMsg {}, SvCustomMsg {});
let _: Result<SvCustomMsg, _> =
querier.custom_generic_query_two(SvCustomMsg {}, SvCustomMsg {});
// Construct messages with Interface extension
let _ = <dyn super::CustomAndGeneric<
Error = (),
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
ExecC = SvCustomMsg,
QueryC = SvCustomQuery,
RetT = SvCustomMsg,
> as super::sv::InterfaceMessagesApi>::Query::custom_generic_query_one(
SvCustomMsg {},
SvCustomMsg {},
);
let _ = <dyn super::CustomAndGeneric<
Error = (),
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
ExecC = SvCustomMsg,
QueryC = SvCustomQuery,
RetT = SvCustomMsg,
> as super::sv::InterfaceMessagesApi>::Exec::custom_generic_execute_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);
let _ = <dyn super::CustomAndGeneric<
Error = (),
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
ExecC = SvCustomMsg,
QueryC = SvCustomQuery,
RetT = SvCustomMsg,
> as super::sv::InterfaceMessagesApi>::Exec::custom_generic_execute_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);
let _ = <dyn super::CustomAndGeneric<
Error = (),
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
ExecC = SvCustomMsg,
QueryC = SvCustomQuery,
RetT = SvCustomMsg,
> as super::sv::InterfaceMessagesApi>::Sudo::custom_generic_sudo_one(
CosmosMsg::Custom(SvCustomMsg {}),
CosmosMsg::Custom(SvCustomMsg {}),
);
let _ = <dyn super::CustomAndGeneric<
Error = (),
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
ExecC = SvCustomMsg,
QueryC = SvCustomQuery,
RetT = SvCustomMsg,
> as super::sv::InterfaceMessagesApi>::Sudo::custom_generic_sudo_one(
CosmosMsg::Custom(SvCustomMsg {}),
CosmosMsg::Custom(SvCustomMsg {}),
);
}
}