diff --git a/examples/Cargo.lock b/examples/Cargo.lock index aa5aeabc..86f592f9 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -644,6 +644,7 @@ dependencies = [ "cw-multi-test", "cw-storage-plus", "cw-utils", + "cw1", "generic", "serde", "sylvia", diff --git a/examples/contracts/generics_forwarded/Cargo.toml b/examples/contracts/generics_forwarded/Cargo.toml index f7201567..fa453cb0 100644 --- a/examples/contracts/generics_forwarded/Cargo.toml +++ b/examples/contracts/generics_forwarded/Cargo.toml @@ -26,6 +26,7 @@ serde = { workspace = true } sylvia = { path = "../../../sylvia" } generic = { path = "../../interfaces/generic" } custom-and-generic = { path = "../../interfaces/custom-and-generic/" } +cw1 = { path = "../../interfaces/cw1/" } [dev-dependencies] anyhow = { workspace = true } diff --git a/examples/contracts/generics_forwarded/src/contract.rs b/examples/contracts/generics_forwarded/src/contract.rs index 54d7d56c..2cdce7dd 100644 --- a/examples/contracts/generics_forwarded/src/contract.rs +++ b/examples/contracts/generics_forwarded/src/contract.rs @@ -28,6 +28,7 @@ pub struct GenericsForwardedContract< #[contract] #[messages(generic<ExecT, QueryT, SvCustomMsg> as Generic: custom(msg, query))] +#[messages(cw1 as Cw1: custom(msg, query))] #[messages(custom_and_generic<ExecT, QueryT, SvCustomMsg,CustomMsgT, CustomQueryT> as CustomAndGeneric)] #[sv::custom(msg=CustomMsgT, query=CustomQueryT)] impl<InstantiateT, ExecT, QueryT, MigrateT, CustomMsgT, CustomQueryT, FieldT> diff --git a/examples/contracts/generics_forwarded/src/cw1.rs b/examples/contracts/generics_forwarded/src/cw1.rs new file mode 100644 index 00000000..c4cf1a2e --- /dev/null +++ b/examples/contracts/generics_forwarded/src/cw1.rs @@ -0,0 +1,87 @@ +use cosmwasm_schema::schemars::JsonSchema; +use cosmwasm_std::{CosmosMsg, CustomMsg, Response, StdError, StdResult}; +use cw1::{CanExecuteResp, Cw1}; +use serde::de::DeserializeOwned; +use serde::Deserialize; +use sylvia::contract; +use sylvia::types::{CustomQuery, ExecCtx, QueryCtx}; + +#[contract(module = crate::contract)] +#[messages(cw1 as Cw1)] +#[sv::custom(msg=CustomMsgT, query=CustomQueryT)] +impl<InstantiateT, ExecT, QueryT, MigrateT, CustomMsgT, CustomQueryT, FieldT> Cw1 + for crate::contract::GenericsForwardedContract< + InstantiateT, + ExecT, + QueryT, + MigrateT, + CustomMsgT, + CustomQueryT, + FieldT, + > +where + for<'msg_de> InstantiateT: CustomMsg + Deserialize<'msg_de> + 'msg_de, + ExecT: CustomMsg + DeserializeOwned + 'static, + QueryT: CustomMsg + DeserializeOwned + 'static, + MigrateT: CustomMsg + DeserializeOwned + 'static, + CustomMsgT: CustomMsg + DeserializeOwned + 'static, + CustomQueryT: CustomQuery + JsonSchema + 'static, + FieldT: 'static, +{ + type Error = StdError; + + #[msg(exec)] + fn execute(&self, _ctx: ExecCtx, _msgs: Vec<CosmosMsg>) -> StdResult<Response> { + Ok(Response::new()) + } + + #[msg(query)] + fn can_execute( + &self, + _ctx: QueryCtx, + _sender: String, + _msg: CosmosMsg, + ) -> StdResult<CanExecuteResp> { + Ok(CanExecuteResp::default()) + } +} + +#[cfg(test)] +mod tests { + use super::sv::test_utils::Cw1; + use crate::contract::sv::multitest_utils::CodeId; + use cosmwasm_std::{CosmosMsg, Empty}; + use sylvia::{ + multitest::App, + types::{SvCustomMsg, SvCustomQuery}, + }; + + #[test] + fn proxy_methods() { + let app = App::<cw_multi_test::BasicApp<SvCustomMsg, SvCustomQuery>>::custom(|_, _, _| {}); + let code_id = CodeId::< + SvCustomMsg, + sylvia::types::SvCustomMsg, + SvCustomMsg, + SvCustomMsg, + SvCustomMsg, + SvCustomQuery, + String, + _, + >::store_code(&app); + + let owner = "owner"; + + let contract = code_id + .instantiate(SvCustomMsg {}) + .with_label("GenericContract") + .with_admin(owner) + .call(owner) + .unwrap(); + + contract.execute(vec![]).call(owner).unwrap(); + contract + .can_execute("sender".to_owned(), CosmosMsg::Custom(Empty {})) + .unwrap(); + } +} diff --git a/examples/contracts/generics_forwarded/src/lib.rs b/examples/contracts/generics_forwarded/src/lib.rs index c1c631c7..ea8b3738 100644 --- a/examples/contracts/generics_forwarded/src/lib.rs +++ b/examples/contracts/generics_forwarded/src/lib.rs @@ -1,3 +1,4 @@ pub mod contract; pub mod custom_and_generic; +pub mod cw1; pub mod generic; diff --git a/sylvia-derive/src/multitest.rs b/sylvia-derive/src/multitest.rs index 2f22dd5c..0807739f 100644 --- a/sylvia-derive/src/multitest.rs +++ b/sylvia-derive/src/multitest.rs @@ -381,18 +381,25 @@ impl<'a> MultitestHelpers<'a> { .unique() .collect(); + let trait_generics: Vec<_> = exec_generics + .iter() + .chain(query_generics.iter()) + .chain(custom_generics.iter()) + .unique() + .collect(); + #[cfg(not(tarpaulin_include))] { quote! { pub mod test_utils { use super::*; - pub trait #trait_name<MtApp, #(#exec_generics,)* #(#query_generics,)* #(#custom_generics,)* > #trait_where_clause { + pub trait #trait_name<MtApp, #(#trait_generics,)* > #trait_where_clause { #(#query_methods_declarations)* #(#exec_methods_declarations)* } - impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, #(#exec_generics,)* #(#query_generics,)* #(#custom_generics,)*> #trait_name< #mt_app , #(#exec_generics,)* #(#query_generics,)* #(#custom_generics,)* > for #module sv::trait_utils:: #proxy_name<'_, #mt_app > + impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, #(#trait_generics,)* > #trait_name< #mt_app , #(#trait_generics,)* > for #module sv::trait_utils:: #proxy_name<'_, #mt_app > where CustomT: #sylvia ::cw_multi_test::Module, WasmT: #sylvia ::cw_multi_test::Wasm<CustomT::ExecT, CustomT::QueryT>, @@ -420,7 +427,7 @@ impl<'a> MultitestHelpers<'a> { #(#exec_methods)* } - impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, #(#contract_generics,)* > #trait_name< #mt_app , #(#exec_generics,)* #(#query_generics,)* #(#custom_generics,)* > for #contract_module sv::multitest_utils:: #contract_proxy <'_, #mt_app, #(#contract_generics,)* > + impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, #(#contract_generics,)* > #trait_name< #mt_app , #(#trait_generics,)* > for #contract_module sv::multitest_utils:: #contract_proxy <'_, #mt_app, #(#contract_generics,)* > where CustomT: #sylvia ::cw_multi_test::Module, WasmT: #sylvia ::cw_multi_test::Wasm<CustomT::ExecT, CustomT::QueryT>,