Repository: CosmWasm/sylvia
Pull request #332 (2024-03-26 13:10:21)

docs: Enable all features in docs.rs and add multitest docs comments

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/CosmWasm/sylvia/pull/332?dropdown=coverage&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.25%. Comparing base [(`b7052b5`)](https://app.codecov.io/gh/CosmWasm/sylvia/commit/b7052b50a23fcb310a5c637cdc3d1b1e24a24c23?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm) to head [(`a7495d4`)](https://app.codecov.io/gh/CosmWasm/sylvia/pull/332?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CosmWasm).


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


```diff
@@           Coverage Diff           @@
##             main     #332   +/-   ##
=======================================
  Coverage   85.25%   85.25%           
=======================================
  Files          37       37           
  Lines        2700     2700           
=======================================
  Hits         2302     2302           
  Misses        398      398           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/CosmWasm/sylvia/pull/332?dropdown=coverage&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/Cargo.lock b/Cargo.lock
index 98cbb8b..dbbb61f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -75,9 +75,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
 
 [[package]]
 name = "bytes"
-version = "1.5.0"
+version = "1.6.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
+checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
 
 [[package]]
 name = "cfg-if"
@@ -469,9 +469,9 @@ dependencies = [
 
 [[package]]
 name = "indexmap"
-version = "2.2.5"
+version = "2.2.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4"
+checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
 dependencies = [
  "equivalent",
  "hashbrown 0.14.3",
@@ -497,9 +497,9 @@ dependencies = [
 
 [[package]]
 name = "itoa"
-version = "1.0.10"
+version = "1.0.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
+checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
 
 [[package]]
 name = "k256"
@@ -639,7 +639,7 @@ dependencies = [
  "itertools 0.11.0",
  "proc-macro2",
  "quote",
- "syn 2.0.53",
+ "syn 2.0.55",
 ]
 
 [[package]]
@@ -770,7 +770,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.53",
+ "syn 2.0.55",
 ]
 
 [[package]]
@@ -786,9 +786,9 @@ dependencies = [
 
 [[package]]
 name = "serde_json"
-version = "1.0.114"
+version = "1.0.115"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0"
+checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd"
 dependencies = [
  "itoa",
  "ryu",
@@ -877,7 +877,9 @@ version = "0.9.3"
 dependencies = [
  "convert_case",
  "cosmwasm-schema",
+ "cw-multi-test",
  "cw-storage-plus",
+ "cw-utils",
  "itertools 0.12.1",
  "proc-macro-crate",
  "proc-macro-error",
@@ -887,7 +889,7 @@ dependencies = [
  "serde",
  "sylvia",
  "sylvia-runtime-macros",
- "syn 2.0.53",
+ "syn 2.0.55",
  "thiserror",
 ]
 
@@ -915,9 +917,9 @@ dependencies = [
 
 [[package]]
 name = "syn"
-version = "2.0.53"
+version = "2.0.55"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032"
+checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -941,7 +943,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.53",
+ "syn 2.0.55",
 ]
 
 [[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 72eaefd..f901b81 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,3 +8,7 @@ version = "0.9.3"
 
 [workspace.dependencies]
 sylvia-derive = { version = "0.9.3", path = "sylvia-derive" }
+
+[workspace.metadata.docs.rs]
+all-features = true
+rustdoc-args = ["--generate-link-to-definition"]
diff --git a/sylvia-derive/Cargo.toml b/sylvia-derive/Cargo.toml
index b2df65d..7bbebec 100644
--- a/sylvia-derive/Cargo.toml
+++ b/sylvia-derive/Cargo.toml
@@ -33,9 +33,23 @@ itertools = "0.12.0"
 
 [dev-dependencies]
 sylvia-runtime-macros = "0.6.0"
-sylvia = { path = "../sylvia" }
+sylvia = { path = "../sylvia", features = [
+    "mt",
+    "stargate",
+    "iterator",
+    "cosmwasm_1_1",
+    "cosmwasm_1_2",
+    "cosmwasm_1_3",
+    "cosmwasm_1_4",
+] }
 serde = { version = "1.0", default-features = false, features = ["derive"] }
 cosmwasm-schema = "1.5"
 schemars = "0.8"
 cw-storage-plus = "1.2.0"
 thiserror = "1.0.58"
+cw-multi-test = "0.20.0"
+cw-utils = "1.0.2"
+
+[package.metadata.docs.rs]
+all-features = true
+rustdoc-args = ["--generate-link-to-definition"]
diff --git a/sylvia-derive/src/lib.rs b/sylvia-derive/src/lib.rs
index 44bd513..f51d5a2 100644
--- a/sylvia-derive/src/lib.rs
+++ b/sylvia-derive/src/lib.rs
@@ -256,7 +256,7 @@ fn interface_impl(_attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
 /// ## Example usage
 /// ```rust
 /// # use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, ReplyCtx, SudoCtx};
-/// # use sylvia::cw_std::{Response, StdError};
+/// # use sylvia::cw_std::{Response, StdError, Reply};
 /// # use cw_storage_plus::Item;
 /// # use thiserror::Error;
 /// #
@@ -302,7 +302,7 @@ fn interface_impl(_attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
 ///     }
 ///
 ///     #[sv::msg(reply)]
-///     fn reply(&self, ctx: ReplyCtx) -> Result<Response, ContractError> {
+///     fn reply(&self, ctx: ReplyCtx, reply: Reply) -> Result<Response, ContractError> {
 /// #        Ok(Response::new())
 ///     }
 ///
@@ -685,17 +685,25 @@ fn contract_impl(attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
 /// ```rust
 /// # use sylvia::types::InstantiateCtx;
 /// # use sylvia::cw_std::{Response, StdResult};
+/// # use sylvia::cw_schema::cw_serde;
 /// # use cw_storage_plus::Item;
 /// # use std::marker::PhantomData;
 /// #
+/// # #[cw_serde]
+/// # pub struct SvCustomMsg;
+/// # impl sylvia::cw_std::CustomMsg for SvCustomMsg {}
+/// #
 /// pub struct SvContract<InstantiateT, DataT> {
 ///     data: Item<'static, DataT>,
 ///     _phantom: PhantomData<InstantiateT>,
 /// }
 ///
-/// ##[sylvia::entry_points(generics<u32, u32>)]
+/// ##[sylvia::entry_points(generics<SvCustomMsg, SvCustomMsg>)]
 /// ##[sylvia::contract]
-/// impl<InstantiateT, DataT> SvContract<InstantiateT, DataT> {
+/// impl<InstantiateT, DataT> SvContract<InstantiateT, DataT>
+///     where InstantiateT: sylvia::types::CustomMsg + 'static,
+///         DataT: 'static
+/// {
 ///     pub const fn new() -> Self {
 ///         Self {
 ///             data: Item::new("data"),
diff --git a/sylvia/Cargo.toml b/sylvia/Cargo.toml
index b0da561..1825a5a 100644
--- a/sylvia/Cargo.toml
+++ b/sylvia/Cargo.toml
@@ -20,9 +20,18 @@ cosmwasm_1_2 = [
     "cw-multi-test?/cosmwasm_1_2",
     "dep:cw-utils",
     "sylvia-derive/cosmwasm_1_2",
+    "cosmwasm_1_1",
+]
+cosmwasm_1_3 = [
+    "cosmwasm-std/cosmwasm_1_3",
+    "cw-multi-test?/cosmwasm_1_3",
+    "cosmwasm_1_2",
+]
+cosmwasm_1_4 = [
+    "cosmwasm-std/cosmwasm_1_4",
+    "cw-multi-test?/cosmwasm_1_4",
+    "cosmwasm_1_3",
 ]
-cosmwasm_1_3 = ["cosmwasm-std/cosmwasm_1_3", "cw-multi-test?/cosmwasm_1_3"]
-cosmwasm_1_4 = ["cosmwasm-std/cosmwasm_1_4", "cw-multi-test?/cosmwasm_1_4"]
 
 [dependencies]
 sylvia-derive = { workspace = true }
@@ -44,3 +53,7 @@ cw-multi-test = "0.20.0"
 cw-storage-plus = "1.2.0"
 cw-utils = "1.0.2"
 thiserror = "1.0.50"
+
+[package.metadata.docs.rs]
+all-features = true
+rustdoc-args = ["--generate-link-to-definition"]
diff --git a/sylvia/src/lib.rs b/sylvia/src/lib.rs
index 52e2344..dff12ea 100644
--- a/sylvia/src/lib.rs
+++ b/sylvia/src/lib.rs
@@ -3,17 +3,22 @@
 //! Most of implementation lies in `sylvia-derive` crate which is reexported here
 
 pub mod into_response;
+#[cfg_attr(docsrs, doc(cfg(feature = "mt")))]
 #[cfg(feature = "mt")]
 pub mod multitest;
 pub mod types;
 pub mod utils;
 
+#[cfg_attr(docsrs, doc(cfg(feature = "mt")))]
 #[cfg(feature = "mt")]
 pub use anyhow;
+#[cfg_attr(docsrs, doc(cfg(feature = "mt")))]
 #[cfg(feature = "mt")]
 pub use cw_multi_test;
+#[cfg_attr(docsrs, doc(cfg(feature = "cosmwasm_1_2")))]
 #[cfg(feature = "cosmwasm_1_2")]
 pub use cw_utils;
+#[cfg_attr(docsrs, doc(cfg(feature = "mt")))]
 #[cfg(feature = "mt")]
 pub use derivative;
 pub use sylvia_derive::{contract, entry_points, interface};


Test patch:
diff --git a/sylvia/src/multitest.rs b/sylvia/src/multitest.rs
index 4d0cff5..e302702 100644
--- a/sylvia/src/multitest.rs
+++ b/sylvia/src/multitest.rs
@@ -1,3 +1,55 @@
+//! This module provides utilities to work with `cw_multi_test` crate.
+//!
+//! Example usage:
+//! ```rust
+//! # use sylvia::cw_std::{Response, StdResult};
+//! # use sylvia::types::{ExecCtx, InstantiateCtx, QueryCtx};
+//! pub struct SvContract;
+//!
+//! ##[sylvia::contract]
+//! impl SvContract {
+//! #    pub const fn new() -> Self { Self }
+//! #
+//!     #[sv::msg(instantiate)]
+//!     pub fn instantiate(&self, ctx: InstantiateCtx) -> StdResult<Response> {
+//! #        Ok(Response::new())
+//!     }
+//!
+//!     #[sv::msg(exec)]
+//!     pub fn execute(&self, ctx: ExecCtx, param: u32) -> StdResult<Response> {
+//! #        Ok(Response::new())
+//!     }
+//!
+//!     #[sv::msg(query)]
+//!     pub fn query(&self, ctx: QueryCtx) -> StdResult<Response> {
+//! #        Ok(Response::new())
+//!     }
+//! }
+//!
+//! #[cfg(test)]
+//! mod tests {
+//! #   use super::*;
+//!     #[test]
+//!     fn example_test() {
+//!         let app = sylvia::multitest::App::default();
+//!         let code_id = sv::mt::CodeId::store_code(&app);
+//!         let owner = "owner";
+//!
+//!         let contract = code_id
+//!             .instantiate()
+//!             .with_label("MyContract") // optional
+//!             .with_admin(owner) // optional
+//!             .call(owner)
+//!             .unwrap();
+//!
+//!         contract.execute(42).call(owner).unwrap();
+//!         contract.query().unwrap();
+//!     }
+//! }
+//!
+//! # fn main() {}
+//! ```
+
 use std::cell::{Ref, RefCell, RefMut};
 use std::fmt::{Debug, Display};
 use std::marker::PhantomData;
@@ -18,6 +70,7 @@ use serde::Serialize;
 
 use crate::types::{CustomMsg, CustomQuery};
 
+/// Proxy to interact with a smart contract initialized on the [App].
 #[derive(Derivative)]
 #[derivative(Debug)]
 pub struct Proxy<'a, MtApp, Contract> {
@@ -45,6 +98,7 @@ impl<'app, MtApp, Contract> From<(cosmwasm_std::Addr, &'app App<MtApp>)>
     }
 }
 
+/// Wrapper around `cw_multi_test::App` to provide additional functionalities.
 pub struct App<MtApp> {
     app: RefCell<MtApp>,
 }
@@ -92,10 +146,12 @@ impl<MtApp> App<MtApp> {
         }
     }
 
+    /// Immutable borrow on the underlying `cw_multi_test::App`.
     pub fn app(&self) -> Ref<'_, MtApp> {
         Ref::map(self.app.borrow(), |app| app)
     }
 
+    /// Mutable borrow on the underlying `cw_multi_test::App`.
     pub fn app_mut(&self) -> RefMut<'_, MtApp> {
         RefMut::map(self.app.borrow_mut(), |app| app)
     }
@@ -116,24 +172,28 @@ where
     IbcT: Ibc,
     GovT: Gov,
 {
+    /// Returns the info of the current block on the chain.
     pub fn block_info(&self) -> BlockInfo {
         self.app.borrow().block_info()
     }
 
+    /// Sets the info of the current block on the chain.
     pub fn set_block(&self, block: BlockInfo) {
         self.app.borrow_mut().set_block(block)
     }
 
+    /// Updates the info of the current block on the chain.
     pub fn update_block<F: Fn(&mut BlockInfo)>(&self, action: F) {
         self.app.borrow_mut().update_block(action)
     }
 
+    /// Returns [CodeInfoResponse] for the given `code_id`.
     #[cfg(feature = "cosmwasm_1_2")]
     pub fn code_info(&self, code_id: u64) -> StdResult<CodeInfoResponse> {
         self.querier().query_wasm_code_info(code_id)
     }
 
-    /// Initialize a new `cosmwasm_std::QuerierWrapper` used to call e.g. `query_wasm_smart` or
+    /// Initialize a new [QuerierWrapper] used to call e.g. `query_wasm_smart` or
     /// `query_all_balances`.
     /// A counterpart to `cw_multi_test::App::wrap` method.
     pub fn querier(&self) -> QuerierWrapper<'_, CustomT::QueryT> {
@@ -175,6 +235,8 @@ where
     }
 }
 
+/// Intermiediate proxy to set additional information
+/// before sending an execute message.
 #[must_use]
 pub struct ExecProxy<'a, 'app, Error, Msg, MtApp, ExecC>
 where
@@ -204,10 +266,13 @@ where
             phantom: PhantomData,
         }
     }
+
+    /// Sets the funds to be sent with the execute message.
     pub fn with_funds(self, funds: &'a [Coin]) -> Self {
         Self { funds, ..self }
     }
 
+    /// Sends the execute message to the contract.
     #[track_caller]
     pub fn call(self, sender: &'a str) -> Result<cw_multi_test::AppResponse, Error> {
         (*self.app)
@@ -222,6 +287,8 @@ where
     }
 }
 
+/// Intermiediate proxy to set additional information
+/// before sending an migrate message.
 #[must_use]
 pub struct MigrateProxy<'a, 'app, Error, Msg, MtApp, ExecC>
 where
@@ -250,6 +317,7 @@ where
         }
     }
 
+    /// Sends the migrate message to the contract.
     #[track_caller]
     pub fn call(self, sender: &str, new_code_id: u64) -> Result<cw_multi_test::AppResponse, Error> {
         (*self.app)