Skip to content

Commit

Permalink
test: Custom and generic interface with duplicated execs
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Dec 7, 2023
1 parent f4105e4 commit c76dae9
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/contracts/generic_contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct GenericContract<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, Migrate
#[contract]
#[messages(cw1 as Cw1: custom(msg, query))]
#[messages(generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg,SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg,SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
GenericContract<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
Expand Down
26 changes: 23 additions & 3 deletions examples/contracts/generic_contract/src/custom_and_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use sylvia::types::{ExecCtx, QueryCtx, SvCustomMsg, SvCustomQuery};
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
CustomAndGeneric<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
Expand All @@ -27,10 +29,21 @@ impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
type Error = StdError;

#[msg(exec)]
fn custom_generic_execute(
fn custom_generic_execute_one(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msgs: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}

#[msg(exec)]
fn custom_generic_execute_two(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}
Expand Down Expand Up @@ -77,7 +90,14 @@ mod tests {
.call(owner)
.unwrap();

contract.custom_generic_execute(vec![]).call(owner).unwrap();
contract
.custom_generic_execute_one(vec![], vec![])
.call(owner)
.unwrap();
contract
.custom_generic_execute_two(vec![], vec![])
.call(owner)
.unwrap();
contract.custom_generic_query(SvCustomMsg {}).unwrap();
}
}
15 changes: 13 additions & 2 deletions examples/contracts/generic_iface_on_contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct NonGenericContract;
#[cfg_attr(not(feature = "library"), entry_points)]
#[contract]
#[messages(generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
#[messages(cw1 as Cw1: custom(msg, query))]
/// Required if interface returns generic `Response`
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
Expand Down Expand Up @@ -93,7 +93,18 @@ mod tests {
.unwrap();
contract
.custom_and_generic_proxy()
.custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})])
.custom_generic_execute_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
)
.call(owner)
.unwrap();
contract
.custom_and_generic_proxy()
.custom_generic_execute_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
)
.call(owner)
.unwrap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use sylvia::types::{ExecCtx, QueryCtx, SvCustomMsg, SvCustomQuery};
#[sv::custom(msg=sylvia::types::SvCustomMsg, query=SvCustomQuery)]
impl
CustomAndGeneric<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
Expand All @@ -18,10 +20,21 @@ impl
type Error = StdError;

#[msg(exec)]
fn custom_generic_execute(
fn custom_generic_execute_one(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}

#[msg(exec)]
fn custom_generic_execute_two(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msgs: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/generics_forwarded/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct GenericsForwardedContract<
#[contract]
#[messages(generic<Exec1T, Exec2T, Exec3T, QueryT, SvCustomMsg> as Generic: custom(msg, query))]
#[messages(cw1 as Cw1: custom(msg, query))]
#[messages(custom_and_generic<Exec1T, QueryT, SvCustomMsg, CustomMsgT, CustomQueryT> as CustomAndGeneric)]
#[messages(custom_and_generic<Exec1T, Exec2T, Exec3T, QueryT, SvCustomMsg, CustomMsgT, CustomQueryT> as CustomAndGeneric)]
#[sv::custom(msg=CustomMsgT, query=CustomQueryT)]
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, CustomMsgT, CustomQueryT, FieldT>
GenericsForwardedContract<
Expand Down
26 changes: 22 additions & 4 deletions examples/contracts/generics_forwarded/src/custom_and_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx, SvCustomMsg};
#[messages(custom_and_generic as CustomAndGeneric)]
#[sv::custom(msg=CustomMsgT, query=CustomQueryT)]
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, CustomMsgT, CustomQueryT, FieldT>
CustomAndGeneric<Exec1T, QueryT, SvCustomMsg, CustomMsgT, CustomQueryT>
CustomAndGeneric<Exec1T, Exec2T, Exec3T, QueryT, SvCustomMsg, CustomMsgT, CustomQueryT>
for crate::contract::GenericsForwardedContract<
InstantiateT,
Exec1T,
Expand All @@ -34,10 +34,21 @@ where
type Error = StdError;

#[msg(exec)]
fn custom_generic_execute(
fn custom_generic_execute_one(
&self,
_ctx: ExecCtx<CustomQueryT>,
_msgs: Vec<CosmosMsg<Exec1T>>,
_msgs1: Vec<CosmosMsg<Exec1T>>,
_msgs2: Vec<CosmosMsg<Exec2T>>,
) -> StdResult<Response<CustomMsgT>> {
Ok(Response::new())
}

#[msg(exec)]
fn custom_generic_execute_two(
&self,
_ctx: ExecCtx<CustomQueryT>,
_msgs2: Vec<CosmosMsg<Exec2T>>,
_msgs1: Vec<CosmosMsg<Exec3T>>,
) -> StdResult<Response<CustomMsgT>> {
Ok(Response::new())
}
Expand Down Expand Up @@ -84,7 +95,14 @@ mod tests {
.call(owner)
.unwrap();

contract.custom_generic_execute(vec![]).call(owner).unwrap();
contract
.custom_generic_execute_one(vec![], vec![])
.call(owner)
.unwrap();
contract
.custom_generic_execute_two(vec![], vec![])
.call(owner)
.unwrap();
contract.custom_generic_query(SvCustomMsg {}).unwrap();
}
}
72 changes: 58 additions & 14 deletions examples/interfaces/custom-and-generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use sylvia::{interface, schemars};

#[interface]
#[sv::custom(msg=CustomMsgT, query=CustomQueryT)]
pub trait CustomAndGeneric<ExecT, QueryT, RetT, CustomMsgT, CustomQueryT>
pub trait CustomAndGeneric<Exec1T, Exec2T, Exec3T, QueryT, RetT, CustomMsgT, CustomQueryT>
where
for<'msg_de> ExecT: CustomMsg + Deserialize<'msg_de>,
for<'msg_de> Exec1T: CustomMsg + Deserialize<'msg_de>,
Exec2T: sylvia::types::CustomMsg,
Exec3T: sylvia::types::CustomMsg,
QueryT: sylvia::types::CustomMsg,
RetT: CustomMsg + DeserializeOwned,
CustomMsgT: CustomMsg + DeserializeOwned,
Expand All @@ -18,10 +20,19 @@ where
type Error: From<StdError>;

#[msg(exec)]
fn custom_generic_execute(
fn custom_generic_execute_one(
&self,
ctx: ExecCtx<CustomQueryT>,
msgs: Vec<CosmosMsg<ExecT>>,
msgs1: Vec<CosmosMsg<Exec1T>>,
msgs2: Vec<CosmosMsg<Exec2T>>,
) -> Result<Response<CustomMsgT>, Self::Error>;

#[msg(exec)]
fn custom_generic_execute_two(
&self,
ctx: ExecCtx<CustomQueryT>,
msgs1: Vec<CosmosMsg<Exec2T>>,
msgs2: Vec<CosmosMsg<Exec3T>>,
) -> Result<Response<CustomMsgT>, Self::Error>;

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

// Direct message construction
let _ = super::sv::QueryMsg::<_, Empty>::custom_generic_query(SvCustomMsg {});
let _ = super::sv::ExecMsg::custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})]);
let _ = super::sv::ExecMsg::custom_generic_execute(vec![CosmosMsg::Custom(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();
Expand All @@ -59,13 +76,40 @@ mod tests {
let _: Result<SvCustomMsg, _> = querier.custom_generic_query(SvCustomMsg {});

// Construct messages with Interface extension
let _ =
<super::sv::Api<SvCustomMsg, _, SvCustomMsg, SvCustomMsg, SvCustomQuery> as InterfaceApi>::Query::custom_generic_query(
SvCustomMsg {},
);
let _=
<super::sv::Api<_, SvCustomMsg,SvCustomMsg, cosmwasm_std::Empty, SvCustomQuery> as InterfaceApi>::Exec::custom_generic_execute(
vec![ CosmosMsg::Custom(SvCustomMsg{}),
]);
let _ = <super::sv::Api<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
_,
SvCustomMsg,
SvCustomMsg,
SvCustomQuery,
> as InterfaceApi>::Query::custom_generic_query(SvCustomMsg {});

let _ = <super::sv::Api<
_,
_,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
cosmwasm_std::Empty,
SvCustomQuery,
> as InterfaceApi>::Exec::custom_generic_execute_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);

let _ = <super::sv::Api<
SvCustomMsg,
_,
_,
SvCustomMsg,
SvCustomMsg,
cosmwasm_std::Empty,
SvCustomQuery,
> as InterfaceApi>::Exec::custom_generic_execute_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
);
}
}

0 comments on commit c76dae9

Please sign in to comment.