From c8bfa9cf32efceb37f57afa4005eff8c1ffad764 Mon Sep 17 00:00:00 2001 From: 0xArb Date: Sun, 18 Dec 2022 13:45:00 +1300 Subject: [PATCH 1/4] supplyresponse::new --- packages/std/src/query/bank.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/std/src/query/bank.rs b/packages/std/src/query/bank.rs index 9656ea6138..373ba8fcd9 100644 --- a/packages/std/src/query/bank.rs +++ b/packages/std/src/query/bank.rs @@ -31,6 +31,16 @@ pub struct SupplyResponse { pub amount: Coin, } +#[cfg(feature = "cosmwasm_1_1")] +impl SupplyResponse { + pub fn new(amount: Coin) -> Self { + Self { + amount, + } + } +} + + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct BalanceResponse { From 6da0ab73364aa02638509846e2b919d79fa523de Mon Sep 17 00:00:00 2001 From: Simon Warta <2603011+webmaster128@users.noreply.github.com> Date: Wed, 21 Dec 2022 17:47:23 +0100 Subject: [PATCH 2/4] Format code --- packages/std/src/query/bank.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/std/src/query/bank.rs b/packages/std/src/query/bank.rs index 373ba8fcd9..d8d99d030e 100644 --- a/packages/std/src/query/bank.rs +++ b/packages/std/src/query/bank.rs @@ -34,13 +34,10 @@ pub struct SupplyResponse { #[cfg(feature = "cosmwasm_1_1")] impl SupplyResponse { pub fn new(amount: Coin) -> Self { - Self { - amount, - } + Self { amount } } } - #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct BalanceResponse { From ad62c70065e010675cebb59aa6b8ab77610b0550 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 21 Dec 2022 17:52:35 +0100 Subject: [PATCH 3/4] Improve documentation for query response constructors --- packages/std/src/query/bank.rs | 5 +++++ packages/std/src/query/wasm.rs | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/std/src/query/bank.rs b/packages/std/src/query/bank.rs index d8d99d030e..e53dbcc9b0 100644 --- a/packages/std/src/query/bank.rs +++ b/packages/std/src/query/bank.rs @@ -33,6 +33,11 @@ pub struct SupplyResponse { #[cfg(feature = "cosmwasm_1_1")] impl SupplyResponse { + /// Constructor for testing frameworks such as cw-multi-test. + /// This is required because query response types should be #[non_exhaustive]. + /// As a contract developer you should not need this constructor since + /// query responses are constructed for you via deserialization. + #[doc(hidden)] pub fn new(amount: Coin) -> Self { Self { amount } } diff --git a/packages/std/src/query/wasm.rs b/packages/std/src/query/wasm.rs index cbac899834..fee0334635 100644 --- a/packages/std/src/query/wasm.rs +++ b/packages/std/src/query/wasm.rs @@ -41,7 +41,10 @@ pub struct ContractInfoResponse { } impl ContractInfoResponse { - /// Convenience constructor for tests / mocks + /// Constructor for testing frameworks such as cw-multi-test. + /// This is required because query response types should be #[non_exhaustive]. + /// As a contract developer you should not need this constructor since + /// query responses are constructed for you via deserialization. #[doc(hidden)] pub fn new(code_id: u64, creator: impl Into) -> Self { Self { From 629aa722fc16721b0c82d394788baa0f00f3dd42 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 21 Dec 2022 17:56:36 +0100 Subject: [PATCH 4/4] Add CHANGELOG entry for SupplyResponse::new --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 806a673192..f8b77d714d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to - cosmwasm-std: Upgrade `serde-json-wasm` dependency to 0.5.0 which adds map support to `to_vec`/`to_binary` and friends. - cosmwasm-std: Implement `AsRef<[u8]>` for `Binary` and `HexBinary` ([#1550]). +- cosmwasm-std: Add constructor `SupplyResponse::new` ([#1552]). [#1436]: https://github.com/CosmWasm/cosmwasm/issues/1436 [#1437]: https://github.com/CosmWasm/cosmwasm/issues/1437 @@ -30,6 +31,7 @@ and this project adheres to [#1478]: https://github.com/CosmWasm/cosmwasm/pull/1478 [#1533]: https://github.com/CosmWasm/cosmwasm/pull/1533 [#1550]: https://github.com/CosmWasm/cosmwasm/issues/1550 +[#1552]: https://github.com/CosmWasm/cosmwasm/pull/1552 [#1554]: https://github.com/CosmWasm/cosmwasm/pull/1554 ### Changed