Repository: CosmWasm/sylvia
Pull request #321 (2024-03-05 13:09:27)

feat: BoundQuerier improve

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/CosmWasm/sylvia/pull/321?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 85.44%. Comparing base [(`0e6a870`)](https://app.codecov.io/gh/CosmWasm/sylvia/commit/0e6a8708d75e28bdd66642c3795e911355498082?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm) to head [(`0e6a870`)](https://app.codecov.io/gh/CosmWasm/sylvia/pull/321?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm).

> :exclamation: Current head 0e6a870 differs from pull request most recent head 8a414ea. Consider uploading reports for the commit 8a414ea to get more accurate results


<details><summary>Additional details and impacted files</summary>


```diff
@@                         Coverage Diff                          @@
##           feat/remove_contract_module_support     #321   +/-   ##
====================================================================
  Coverage                                85.44%   85.44%           
====================================================================
  Files                                       37       37           
  Lines                                     2694     2694           
====================================================================
  Hits                                      2302     2302           
  Misses                                     392      392           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/CosmWasm/sylvia/pull/321?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm).


Patch:
diff --git a/examples/interfaces/custom-and-generic/src/lib.rs b/examples/interfaces/custom-and-generic/src/lib.rs
index fb20955..f80e16e 100644
--- a/examples/interfaces/custom-and-generic/src/lib.rs
+++ b/examples/interfaces/custom-and-generic/src/lib.rs
@@ -105,18 +105,21 @@ mod tests {
 
         let querier = sylvia::types::BoundQuerier::<
             _,
-            std::marker::PhantomData<(
-                Empty,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-            )>,
+            &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 = (),
+                QueryC = (),
+            >,
         >::borrowed(&contract, &querier_wrapper);
 
         let _: Result<SvCustomMsg, _> =
diff --git a/examples/interfaces/generic/src/lib.rs b/examples/interfaces/generic/src/lib.rs
index 95aeebd..9624672 100644
--- a/examples/interfaces/generic/src/lib.rs
+++ b/examples/interfaces/generic/src/lib.rs
@@ -102,18 +102,19 @@ mod tests {
 
         let querier = sylvia::types::BoundQuerier::<
             Empty,
-            std::marker::PhantomData<(
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-                SvCustomMsg,
-            )>,
+            &dyn super::Generic<
+                Exec1T = SvCustomMsg,
+                Exec2T = SvCustomMsg,
+                Exec3T = SvCustomMsg,
+                Query1T = SvCustomMsg,
+                Query2T = SvCustomMsg,
+                Query3T = SvCustomMsg,
+                Sudo1T = SvCustomMsg,
+                Sudo2T = SvCustomMsg,
+                Sudo3T = SvCustomMsg,
+                RetT = SvCustomMsg,
+                Error = (),
+            >,
         >::borrowed(&contract, &querier_wrapper);
         let _: Result<SvCustomMsg, _> =
             super::sv::Querier::generic_query_one(&querier, SvCustomMsg {}, SvCustomMsg {});
diff --git a/sylvia-derive/src/associated_types.rs b/sylvia-derive/src/associated_types.rs
index 7225fe7..bcee857 100644
--- a/sylvia-derive/src/associated_types.rs
+++ b/sylvia-derive/src/associated_types.rs
@@ -24,6 +24,10 @@ impl<'a> AssociatedTypes<'a> {
         Self(associated_types)
     }
 
+    pub fn all_names(&self) -> impl Iterator<Item = &Ident> {
+        self.0.iter().map(|associated| &associated.ident)
+    }
+
     pub fn without_error(&self) -> impl Iterator<Item = &TraitItemType> {
         self.0
             .iter()
@@ -62,7 +66,7 @@ impl<'a> AssociatedTypes<'a> {
         }
     }
 
-    pub fn as_names(&self) -> impl Iterator<Item = &Ident> {
+    pub fn as_filtered_names(&self) -> impl Iterator<Item = &Ident> {
         self.filtered().map(|associated| &associated.ident)
     }
 
diff --git a/sylvia-derive/src/input.rs b/sylvia-derive/src/input.rs
index 6488fb6..8f66eb7 100644
--- a/sylvia-derive/src/input.rs
+++ b/sylvia-derive/src/input.rs
@@ -62,7 +62,7 @@ impl<'a> TraitInput<'a> {
             custom,
         } = self;
         let messages = self.emit_messages();
-        let associated_names: Vec<_> = associated_types.as_names().collect();
+        let associated_names: Vec<_> = associated_types.as_filtered_names().collect();
 
         let query_variants =
             MsgVariants::new(item.as_variants(), MsgType::Query, &associated_names, &None);
diff --git a/sylvia-derive/src/querier.rs b/sylvia-derive/src/querier.rs
index 9920ade..3e1f61d 100644
--- a/sylvia-derive/src/querier.rs
+++ b/sylvia-derive/src/querier.rs
@@ -44,6 +44,8 @@ where
             .map(ItemType::as_name)
             .collect();
 
+        let all_generics: Vec<_> = associated_types.all_names().collect();
+
         let assoc_types: Vec<_> = associated_types
             .without_special()
             .map(ItemType::as_name)
@@ -70,7 +72,7 @@ where
                 #(#methods_declaration)*
             }
 
-            impl <'a, C: #sylvia ::cw_std::CustomQuery, #(#generics,)*> Querier for #sylvia ::types::BoundQuerier<'a, C, std::marker::PhantomData< (#(#generics,)*) > > #where_clause {
+            impl <'a, C: #sylvia ::cw_std::CustomQuery, #(#all_generics,)*> Querier for #sylvia ::types::BoundQuerier<'a, C, &dyn #interface_name <#( #all_generics = #all_generics,)*> > #where_clause {
                 #(type #generics = #generics;)*
 
                 #(#methods_trait_impl)*


Test patch:
diff --git a/sylvia/tests/querier.rs b/sylvia/tests/querier.rs
index 17d1dd5..3440a68 100644
--- a/sylvia/tests/querier.rs
+++ b/sylvia/tests/querier.rs
@@ -114,11 +114,11 @@ impl CounterContract<'_> {
 
 #[cfg(test)]
 mod tests {
-    use crate::counter::sv::test_utils::CounterProxy;
     use cosmwasm_std::testing::mock_dependencies;
     use cosmwasm_std::{Addr, Empty, QuerierWrapper};
     use sylvia::multitest::App;
 
+    use crate::counter::sv::test_utils::CounterProxy;
     use crate::sv::multitest_utils::CodeId;
 
     #[test]