Skip to content

Commit 66cb692

Browse files
committed
test: Custom and generic interface with duplicated execs
1 parent 6d24765 commit 66cb692

7 files changed

Lines changed: 133 additions & 27 deletions

File tree

‎examples/contracts/generic_contract/src/contract.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct GenericContract<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, Migrate
2727
#[contract]
2828
#[messages(cw1 as Cw1: custom(msg, query))]
2929
#[messages(generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
30-
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg,SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
30+
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg,SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
3131
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
3232
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
3333
GenericContract<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>

‎examples/contracts/generic_contract/src/custom_and_generic.rs‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use sylvia::types::{ExecCtx, QueryCtx, SvCustomMsg, SvCustomQuery};
88
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
99
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
1010
CustomAndGeneric<
11+
SvCustomMsg,
12+
SvCustomMsg,
1113
SvCustomMsg,
1214
SvCustomMsg,
1315
SvCustomMsg,
@@ -27,10 +29,21 @@ impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
2729
type Error = StdError;
2830

2931
#[msg(exec)]
30-
fn custom_generic_execute(
32+
fn custom_generic_execute_one(
3133
&self,
3234
_ctx: ExecCtx<SvCustomQuery>,
33-
_msgs: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
35+
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
36+
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
37+
) -> StdResult<Response<SvCustomMsg>> {
38+
Ok(Response::new())
39+
}
40+
41+
#[msg(exec)]
42+
fn custom_generic_execute_two(
43+
&self,
44+
_ctx: ExecCtx<SvCustomQuery>,
45+
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
46+
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
3447
) -> StdResult<Response<SvCustomMsg>> {
3548
Ok(Response::new())
3649
}
@@ -77,7 +90,14 @@ mod tests {
7790
.call(owner)
7891
.unwrap();
7992

80-
contract.custom_generic_execute(vec![]).call(owner).unwrap();
93+
contract
94+
.custom_generic_execute_one(vec![], vec![])
95+
.call(owner)
96+
.unwrap();
97+
contract
98+
.custom_generic_execute_two(vec![], vec![])
99+
.call(owner)
100+
.unwrap();
81101
contract.custom_generic_query(SvCustomMsg {}).unwrap();
82102
}
83103
}

‎examples/contracts/generic_iface_on_contract/src/contract.rs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct NonGenericContract;
1010
#[cfg_attr(not(feature = "library"), entry_points)]
1111
#[contract]
1212
#[messages(generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
13-
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
13+
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
1414
#[messages(cw1 as Cw1: custom(msg, query))]
1515
/// Required if interface returns generic `Response`
1616
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
@@ -93,7 +93,18 @@ mod tests {
9393
.unwrap();
9494
contract
9595
.custom_and_generic_proxy()
96-
.custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})])
96+
.custom_generic_execute_one(
97+
vec![CosmosMsg::Custom(SvCustomMsg {})],
98+
vec![CosmosMsg::Custom(SvCustomMsg {})],
99+
)
100+
.call(owner)
101+
.unwrap();
102+
contract
103+
.custom_and_generic_proxy()
104+
.custom_generic_execute_two(
105+
vec![CosmosMsg::Custom(SvCustomMsg {})],
106+
vec![CosmosMsg::Custom(SvCustomMsg {})],
107+
)
97108
.call(owner)
98109
.unwrap();
99110
}

‎examples/contracts/generic_iface_on_contract/src/custom_and_generic.rs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use sylvia::types::{ExecCtx, QueryCtx, SvCustomMsg, SvCustomQuery};
88
#[sv::custom(msg=sylvia::types::SvCustomMsg, query=SvCustomQuery)]
99
impl
1010
CustomAndGeneric<
11+
SvCustomMsg,
12+
SvCustomMsg,
1113
SvCustomMsg,
1214
SvCustomMsg,
1315
SvCustomMsg,
@@ -18,10 +20,21 @@ impl
1820
type Error = StdError;
1921

2022
#[msg(exec)]
21-
fn custom_generic_execute(
23+
fn custom_generic_execute_one(
24+
&self,
25+
_ctx: ExecCtx<SvCustomQuery>,
26+
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
27+
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
28+
) -> StdResult<Response<SvCustomMsg>> {
29+
Ok(Response::new())
30+
}
31+
32+
#[msg(exec)]
33+
fn custom_generic_execute_two(
2234
&self,
2335
_ctx: ExecCtx<SvCustomQuery>,
24-
_msgs: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
36+
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
37+
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
2538
) -> StdResult<Response<SvCustomMsg>> {
2639
Ok(Response::new())
2740
}

‎examples/contracts/generics_forwarded/src/contract.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct GenericsForwardedContract<
3434
#[contract]
3535
#[messages(generic<Exec1T, Exec2T, Exec3T, QueryT, SvCustomMsg> as Generic: custom(msg, query))]
3636
#[messages(cw1 as Cw1: custom(msg, query))]
37-
#[messages(custom_and_generic<Exec1T, QueryT, SvCustomMsg, CustomMsgT, CustomQueryT> as CustomAndGeneric)]
37+
#[messages(custom_and_generic<Exec1T, Exec2T, Exec3T, QueryT, SvCustomMsg, CustomMsgT, CustomQueryT> as CustomAndGeneric)]
3838
#[sv::custom(msg=CustomMsgT, query=CustomQueryT)]
3939
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, CustomMsgT, CustomQueryT, FieldT>
4040
GenericsForwardedContract<

‎examples/contracts/generics_forwarded/src/custom_and_generic.rs‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx, SvCustomMsg};
88
#[messages(custom_and_generic as CustomAndGeneric)]
99
#[sv::custom(msg=CustomMsgT, query=CustomQueryT)]
1010
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, CustomMsgT, CustomQueryT, FieldT>
11-
CustomAndGeneric<Exec1T, QueryT, SvCustomMsg, CustomMsgT, CustomQueryT>
11+
CustomAndGeneric<Exec1T, Exec2T, Exec3T, QueryT, SvCustomMsg, CustomMsgT, CustomQueryT>
1212
for crate::contract::GenericsForwardedContract<
1313
InstantiateT,
1414
Exec1T,
@@ -34,10 +34,21 @@ where
3434
type Error = StdError;
3535

3636
#[msg(exec)]
37-
fn custom_generic_execute(
37+
fn custom_generic_execute_one(
3838
&self,
3939
_ctx: ExecCtx<CustomQueryT>,
40-
_msgs: Vec<CosmosMsg<Exec1T>>,
40+
_msgs1: Vec<CosmosMsg<Exec1T>>,
41+
_msgs2: Vec<CosmosMsg<Exec2T>>,
42+
) -> StdResult<Response<CustomMsgT>> {
43+
Ok(Response::new())
44+
}
45+
46+
#[msg(exec)]
47+
fn custom_generic_execute_two(
48+
&self,
49+
_ctx: ExecCtx<CustomQueryT>,
50+
_msgs2: Vec<CosmosMsg<Exec2T>>,
51+
_msgs1: Vec<CosmosMsg<Exec3T>>,
4152
) -> StdResult<Response<CustomMsgT>> {
4253
Ok(Response::new())
4354
}
@@ -84,7 +95,14 @@ mod tests {
8495
.call(owner)
8596
.unwrap();
8697

87-
contract.custom_generic_execute(vec![]).call(owner).unwrap();
98+
contract
99+
.custom_generic_execute_one(vec![], vec![])
100+
.call(owner)
101+
.unwrap();
102+
contract
103+
.custom_generic_execute_two(vec![], vec![])
104+
.call(owner)
105+
.unwrap();
88106
contract.custom_generic_query(SvCustomMsg {}).unwrap();
89107
}
90108
}

‎examples/interfaces/custom-and-generic/src/lib.rs‎

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use sylvia::{interface, schemars};
77

88
#[interface]
99
#[sv::custom(msg=CustomMsgT, query=CustomQueryT)]
10-
pub trait CustomAndGeneric<ExecT, QueryT, RetT, CustomMsgT, CustomQueryT>
10+
pub trait CustomAndGeneric<Exec1T, Exec2T, Exec3T, QueryT, RetT, CustomMsgT, CustomQueryT>
1111
where
12-
for<'msg_de> ExecT: CustomMsg + Deserialize<'msg_de>,
12+
for<'msg_de> Exec1T: CustomMsg + Deserialize<'msg_de>,
13+
Exec2T: sylvia::types::CustomMsg,
14+
Exec3T: sylvia::types::CustomMsg,
1315
QueryT: sylvia::types::CustomMsg,
1416
RetT: CustomMsg + DeserializeOwned,
1517
CustomMsgT: CustomMsg + DeserializeOwned,
@@ -18,10 +20,19 @@ where
1820
type Error: From<StdError>;
1921

2022
#[msg(exec)]
21-
fn custom_generic_execute(
23+
fn custom_generic_execute_one(
2224
&self,
2325
ctx: ExecCtx<CustomQueryT>,
24-
msgs: Vec<CosmosMsg<ExecT>>,
26+
msgs1: Vec<CosmosMsg<Exec1T>>,
27+
msgs2: Vec<CosmosMsg<Exec2T>>,
28+
) -> Result<Response<CustomMsgT>, Self::Error>;
29+
30+
#[msg(exec)]
31+
fn custom_generic_execute_two(
32+
&self,
33+
ctx: ExecCtx<CustomQueryT>,
34+
msgs1: Vec<CosmosMsg<Exec2T>>,
35+
msgs2: Vec<CosmosMsg<Exec3T>>,
2536
) -> Result<Response<CustomMsgT>, Self::Error>;
2637

2738
#[msg(query)]
@@ -46,8 +57,14 @@ mod tests {
4657

4758
// Direct message construction
4859
let _ = super::sv::QueryMsg::<_, Empty>::custom_generic_query(SvCustomMsg {});
49-
let _ = super::sv::ExecMsg::custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})]);
50-
let _ = super::sv::ExecMsg::custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})]);
60+
let _ = super::sv::ExecMsg::<_, _, SvCustomMsg>::custom_generic_execute_one(
61+
vec![CosmosMsg::Custom(SvCustomMsg {})],
62+
vec![CosmosMsg::Custom(SvCustomMsg {})],
63+
);
64+
let _ = super::sv::ExecMsg::<SvCustomMsg, _, _>::custom_generic_execute_two(
65+
vec![CosmosMsg::Custom(SvCustomMsg {})],
66+
vec![CosmosMsg::Custom(SvCustomMsg {})],
67+
);
5168

5269
// Querier
5370
let deps = mock_dependencies();
@@ -59,13 +76,40 @@ mod tests {
5976
let _: Result<SvCustomMsg, _> = querier.custom_generic_query(SvCustomMsg {});
6077

6178
// Construct messages with Interface extension
62-
let _ =
63-
<super::sv::Api<SvCustomMsg, _, SvCustomMsg, SvCustomMsg, SvCustomQuery> as InterfaceApi>::Query::custom_generic_query(
64-
SvCustomMsg {},
65-
);
66-
let _=
67-
<super::sv::Api<_, SvCustomMsg,SvCustomMsg, cosmwasm_std::Empty, SvCustomQuery> as InterfaceApi>::Exec::custom_generic_execute(
68-
vec![ CosmosMsg::Custom(SvCustomMsg{}),
69-
]);
79+
let _ = <super::sv::Api<
80+
SvCustomMsg,
81+
SvCustomMsg,
82+
SvCustomMsg,
83+
_,
84+
SvCustomMsg,
85+
SvCustomMsg,
86+
SvCustomQuery,
87+
> as InterfaceApi>::Query::custom_generic_query(SvCustomMsg {});
88+
89+
let _ = <super::sv::Api<
90+
_,
91+
_,
92+
SvCustomMsg,
93+
SvCustomMsg,
94+
SvCustomMsg,
95+
cosmwasm_std::Empty,
96+
SvCustomQuery,
97+
> as InterfaceApi>::Exec::custom_generic_execute_one(
98+
vec![CosmosMsg::Custom(SvCustomMsg {})],
99+
vec![CosmosMsg::Custom(SvCustomMsg {})],
100+
);
101+
102+
let _ = <super::sv::Api<
103+
SvCustomMsg,
104+
_,
105+
_,
106+
SvCustomMsg,
107+
SvCustomMsg,
108+
cosmwasm_std::Empty,
109+
SvCustomQuery,
110+
> as InterfaceApi>::Exec::custom_generic_execute_two(
111+
vec![CosmosMsg::Custom(SvCustomMsg {})],
112+
vec![CosmosMsg::Custom(SvCustomMsg {})],
113+
);
70114
}
71115
}

0 commit comments

Comments
 (0)