Repository: CosmWasm/sylvia
Pull request #173 (2023-06-09 16:46:11)

Custom msg trait support

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/CosmWasm/sylvia/pull/173?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm) Report
> Merging [#173](https://app.codecov.io/gh/CosmWasm/sylvia/pull/173?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm) (6b6c7d7) into [generate_custom_responses](https://app.codecov.io/gh/CosmWasm/sylvia/commit/0e1f3eb52ceeac4895afe4778c401061ac0069e8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm) (0e1f3eb) will **increase** coverage by `0.26%`.
> The diff coverage is `100.00%`.

```diff
@@                      Coverage Diff                      @@
##           generate_custom_responses     #173      +/-   ##
=============================================================
+ Coverage                      81.64%   81.91%   +0.26%     
=============================================================
  Files                             36       36              
  Lines                           1776     1780       +4     
=============================================================
+ Hits                            1450     1458       +8     
+ Misses                           326      322       -4     
```


| [Impacted Files](https://app.codecov.io/gh/CosmWasm/sylvia/pull/173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm) | Coverage Δ | |
|---|---|---|
| [sylvia-derive/src/strip\_input.rs](https://app.codecov.io/gh/CosmWasm/sylvia/pull/173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm#diff-c3lsdmlhLWRlcml2ZS9zcmMvc3RyaXBfaW5wdXQucnM=) | `91.42% <100.00%> (+1.10%)` | :arrow_up: |
| [sylvia/tests/custom\_msg.rs](https://app.codecov.io/gh/CosmWasm/sylvia/pull/173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm#diff-c3lsdmlhL3Rlc3RzL2N1c3RvbV9tc2cucnM=) | `100.00% <100.00%> (+36.36%)` | :arrow_up: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm)


Patch:
diff --git a/sylvia-derive/src/strip_input.rs b/sylvia-derive/src/strip_input.rs
index 6cfc626..4fd4b77 100644
--- a/sylvia-derive/src/strip_input.rs
+++ b/sylvia-derive/src/strip_input.rs
@@ -1,6 +1,9 @@
 use syn::fold::{self, Fold};
 use syn::punctuated::Punctuated;
-use syn::{FnArg, ImplItemMethod, ItemImpl, PatType, Receiver, Signature, Token, TraitItemMethod};
+use syn::{
+    FnArg, ImplItemMethod, ItemImpl, ItemTrait, PatType, Receiver, Signature, Token,
+    TraitItemMethod,
+};
 
 use crate::parser::sylvia_attribute;
 
@@ -55,6 +58,16 @@ impl Fold for StripInput {
         fold::fold_impl_item_method(self, ImplItemMethod { attrs, sig, ..i })
     }
 
+    fn fold_item_trait(&mut self, i: ItemTrait) -> ItemTrait {
+        let attrs = i
+            .attrs
+            .into_iter()
+            .filter(|attr| sylvia_attribute(attr).is_none())
+            .collect();
+
+        fold::fold_item_trait(self, ItemTrait { attrs, ..i })
+    }
+
     fn fold_item_impl(&mut self, i: ItemImpl) -> ItemImpl {
         let attrs = i
             .attrs


Test patch:
diff --git a/sylvia/tests/custom_msg.rs b/sylvia/tests/custom_msg.rs
index d991438..3eb2a4b 100644
--- a/sylvia/tests/custom_msg.rs
+++ b/sylvia/tests/custom_msg.rs
@@ -21,14 +21,13 @@ pub struct SomeResponse;
 
 mod some_interface {
     use cosmwasm_std::{Response, StdError, StdResult};
-    use sylvia::{
-        interface,
-        types::{ExecCtx, QueryCtx},
-    };
+    use sylvia::types::{ExecCtx, QueryCtx};
+    use sylvia::{contract, interface};
 
-    use crate::SomeResponse;
+    use crate::{MyMsg, SomeResponse};
 
     #[interface]
+    #[sv::custom(msg=MyMsg, query=MyQuery)]
     pub trait SomeInterface {
         type Error: From<StdError>;
 
@@ -38,25 +37,28 @@ mod some_interface {
 
         #[cfg(not(tarpaulin_include))]
         #[msg(exec)]
-        fn interface_exec(&self, ctx: ExecCtx) -> StdResult<Response>;
+        fn interface_exec(&self, ctx: ExecCtx) -> StdResult<Response<MyMsg>>;
     }
 
+    #[contract(module=super)]
+    #[sv::custom(msg=MyMsg, query=MyQuery)]
     impl SomeInterface for crate::MyContract {
         type Error = StdError;
 
+        #[msg(query)]
         fn interface_query(&self, _ctx: QueryCtx) -> StdResult<SomeResponse> {
             Ok(SomeResponse)
         }
 
-        fn interface_exec(&self, _ctx: ExecCtx) -> StdResult<Response> {
+        #[msg(exec)]
+        fn interface_exec(&self, _ctx: ExecCtx) -> StdResult<Response<MyMsg>> {
             Ok(Response::default())
         }
     }
 }
 
 #[contract]
-// Uncomment once into_response is called in dispatch
-// #[messages(some_interface as SomeInterface)]
+#[messages(some_interface as SomeInterface)]
 #[sv::custom(msg=MyMsg, query=MyQuery)]
 impl MyContract {
     #[allow(clippy::new_without_default)]
@@ -91,6 +93,7 @@ mod tests {
     use crate::MyContract;
     use sylvia::multitest::App;
 
+    use crate::some_interface::test_utils::SomeInterface;
     use crate::MyMsg;
 
     #[test]
@@ -109,5 +112,13 @@ mod tests {
 
         contract.some_exec().call(owner).unwrap();
         contract.some_query().unwrap();
+
+        // Interface messsages
+        contract.some_interface_proxy().interface_query().unwrap();
+        contract
+            .some_interface_proxy()
+            .interface_exec()
+            .call(owner)
+            .unwrap();
     }
 }