From 7330bbfa4719806591cba57d0a3cdd33b17aef0c Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:48:12 +0200 Subject: [PATCH 01/13] test: Make cw1 iface generic --- examples/interfaces/cw1/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/interfaces/cw1/src/lib.rs b/examples/interfaces/cw1/src/lib.rs index 0aedc602..188318e2 100644 --- a/examples/interfaces/cw1/src/lib.rs +++ b/examples/interfaces/cw1/src/lib.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult}; use serde::{Deserialize, Serialize}; -use sylvia::types::{ExecCtx, QueryCtx}; +use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx}; use sylvia::{interface, schemars}; #[derive( @@ -11,15 +11,21 @@ pub struct CanExecuteResp { } #[interface] -#[sv::custom(msg=cosmwasm_std::Empty, query=cosmwasm_std::Empty)] pub trait Cw1 { type Error: From; + type ExecC: CustomMsg; + type QueryC: CustomQuery; + type CosmosCustomMsg: CustomMsg; /// Execute requests the contract to re-dispatch all these messages with the /// contract's address as sender. Every implementation has it's own logic to /// determine in #[sv::msg(exec)] - fn execute(&self, ctx: ExecCtx, msgs: Vec) -> Result; + fn execute( + &self, + ctx: ExecCtx, + msgs: Vec>, + ) -> Result, Self::Error>; /// Checks permissions of the caller on this proxy. /// If CanExecute returns true then a call to `Execute` with the same message, @@ -27,9 +33,9 @@ pub trait Cw1 { #[sv::msg(query)] fn can_execute( &self, - ctx: QueryCtx, + ctx: QueryCtx, sender: String, - msg: CosmosMsg, + msg: CosmosMsg, ) -> StdResult; } From caef50483357e08cbce1a1b5773fed8aba208c67 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:48:27 +0200 Subject: [PATCH 02/13] test: Make cw4 iface generic --- examples/interfaces/cw4/src/lib.rs | 61 ++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/examples/interfaces/cw4/src/lib.rs b/examples/interfaces/cw4/src/lib.rs index 1c75eca9..f19c79b9 100644 --- a/examples/interfaces/cw4/src/lib.rs +++ b/examples/interfaces/cw4/src/lib.rs @@ -1,39 +1,76 @@ use cosmwasm_std::{Response, StdError}; - -use sylvia::types::{ExecCtx, QueryCtx}; +use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx}; use sylvia::{interface, schemars}; #[interface] -#[sv::custom(msg=cosmwasm_std::Empty, query=cosmwasm_std::Empty)] pub trait Cw4 { type Error: From; + type ExecC: CustomMsg; + type QueryC: CustomQuery; + type MemberCustomMsg: CustomMsg; + type ListMembersCustomMsg: CustomMsg; + type TotalWeightCustomMsg: CustomMsg; + type AdminCustomMsg: CustomMsg; + type HooksCustomMsg: CustomMsg; #[sv::msg(exec)] - fn update_admin(&self, ctx: ExecCtx, admin: String) -> Result; + fn update_admin( + &self, + ctx: ExecCtx, + admin: String, + ) -> Result, Self::Error>; #[sv::msg(exec)] - fn update_members(&self, ctx: ExecCtx, members: Vec) -> Result; + fn update_members( + &self, + ctx: ExecCtx, + members: Vec, + ) -> Result, Self::Error>; #[sv::msg(exec)] - fn add_hook(&self, ctx: ExecCtx, hook: String) -> Result; + fn add_hook( + &self, + ctx: ExecCtx, + hook: String, + ) -> Result, Self::Error>; #[sv::msg(exec)] - fn remove_hook(&self, ctx: ExecCtx, hook: String) -> Result; + fn remove_hook( + &self, + ctx: ExecCtx, + hook: String, + ) -> Result, Self::Error>; #[sv::msg(query)] - fn member(&self, ctx: QueryCtx, member: String) -> Result; + fn member( + &self, + ctx: QueryCtx, + member: String, + ) -> Result, Self::Error>; #[sv::msg(query)] - fn list_members(&self, ctx: QueryCtx) -> Result; + fn list_members( + &self, + ctx: QueryCtx, + ) -> Result, Self::Error>; #[sv::msg(query)] - fn total_weight(&self, ctx: QueryCtx) -> Result; + fn total_weight( + &self, + ctx: QueryCtx, + ) -> Result, Self::Error>; #[sv::msg(query)] - fn admin(&self, ctx: QueryCtx) -> Result; + fn admin( + &self, + ctx: QueryCtx, + ) -> Result, Self::Error>; #[sv::msg(query)] - fn hooks(&self, ctx: QueryCtx) -> Result; + fn hooks( + &self, + ctx: QueryCtx, + ) -> Result, Self::Error>; } #[cfg(test)] From 150af91dc29b38913daba12b32512cad08e07af9 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:48:45 +0200 Subject: [PATCH 03/13] test: Make cw20-allowances iface generic --- .../interfaces/cw20-allowances/src/lib.rs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/examples/interfaces/cw20-allowances/src/lib.rs b/examples/interfaces/cw20-allowances/src/lib.rs index 35ed061f..8a7d0219 100644 --- a/examples/interfaces/cw20-allowances/src/lib.rs +++ b/examples/interfaces/cw20-allowances/src/lib.rs @@ -5,73 +5,74 @@ use cw_utils::Expiration; use responses::{ AllAccountsResponse, AllAllowancesResponse, AllSpenderAllowancesResponse, AllowanceResponse, }; -use sylvia::types::{ExecCtx, QueryCtx}; +use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx}; use sylvia::{interface, schemars}; #[interface] -#[sv::custom(msg=cosmwasm_std::Empty, query=cosmwasm_std::Empty)] pub trait Cw20Allowances { type Error: From; + type ExecC: CustomMsg; + type QueryC: CustomQuery; /// Allows spender to access an additional amount tokens from the owner's (env.sender) account. /// If expires is Some(), overwrites current allowance expiration with this one. #[sv::msg(exec)] fn increase_allowance( &self, - ctx: ExecCtx, + ctx: ExecCtx, spender: String, amount: Uint128, expires: Option, - ) -> Result; + ) -> Result, Self::Error>; /// Lowers the spender's access of tokens from the owner's (env.sender) account by amount. /// If expires is Some(), overwrites current allowance expiration with this one. #[sv::msg(exec)] fn decrease_allowance( &self, - ctx: ExecCtx, + ctx: ExecCtx, spender: String, amount: Uint128, expires: Option, - ) -> Result; + ) -> Result, Self::Error>; /// Transfers amount tokens from owner -> recipient /// if `env.sender` has sufficient pre-approval. #[sv::msg(exec)] fn transfer_from( &self, - ctx: ExecCtx, + ctx: ExecCtx, owner: String, recipient: String, amount: Uint128, - ) -> Result; + ) -> Result, Self::Error>; /// Sends amount tokens from owner -> contract /// if `env.sender` has sufficient pre-approval. #[sv::msg(exec)] fn send_from( &self, - ctx: ExecCtx, + ctx: ExecCtx, owner: String, contract: String, amount: Uint128, msg: Binary, - ) -> Result; + ) -> Result, Self::Error>; /// Destroys amount of tokens forever #[sv::msg(exec)] fn burn_from( &self, - ctx: ExecCtx, + ctx: ExecCtx, owner: String, amount: Uint128, - ) -> Result; + ) -> Result, Self::Error>; /// Returns how much spender can use from owner account, 0 if unset. #[sv::msg(query)] fn allowance( &self, - ctx: QueryCtx, + ctx: QueryCtx, owner: String, spender: String, ) -> StdResult; @@ -80,7 +81,7 @@ pub trait Cw20Allowances { #[sv::msg(query)] fn all_allowances( &self, - ctx: QueryCtx, + ctx: QueryCtx, owner: String, start_after: Option, limit: Option, @@ -90,7 +91,7 @@ pub trait Cw20Allowances { #[sv::msg(query)] fn all_spender_allowances( &self, - ctx: QueryCtx, + ctx: QueryCtx, spender: String, start_after: Option, limit: Option, @@ -100,7 +101,7 @@ pub trait Cw20Allowances { #[sv::msg(query)] fn all_accounts( &self, - ctx: QueryCtx, + ctx: QueryCtx, start_after: Option, limit: Option, ) -> StdResult; From 0c69b71ce71b0a0fbcd5ed4b5649b7368d917278 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:49:01 +0200 Subject: [PATCH 04/13] test: Make cw20-marketing iface generic --- examples/interfaces/cw20-marketing/src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/interfaces/cw20-marketing/src/lib.rs b/examples/interfaces/cw20-marketing/src/lib.rs index 31b63834..f0d3d2f1 100644 --- a/examples/interfaces/cw20-marketing/src/lib.rs +++ b/examples/interfaces/cw20-marketing/src/lib.rs @@ -3,7 +3,7 @@ pub mod responses; use cosmwasm_schema::cw_serde; use cosmwasm_std::{Binary, Response, StdError, StdResult}; use responses::{DownloadLogoResponse, MarketingInfoResponse}; -use sylvia::types::{ExecCtx, QueryCtx}; +use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx}; use sylvia::{interface, schemars}; /// This is used for uploading logo data, or setting it in InstantiateData @@ -29,9 +29,10 @@ pub enum EmbeddedLogo { } #[interface] -#[sv::custom(msg=cosmwasm_std::Empty, query=cosmwasm_std::Empty)] pub trait Cw20Marketing { type Error: From; + type ExecC: CustomMsg; + type QueryC: CustomQuery; /// If authorized, updates marketing metadata. /// Setting None/null for any of these will leave it unchanged. @@ -42,23 +43,27 @@ pub trait Cw20Marketing { #[sv::msg(exec)] fn update_marketing( &self, - ctx: ExecCtx, + ctx: ExecCtx, project: Option, description: Option, marketing: Option, - ) -> Result; + ) -> Result, Self::Error>; /// If set as the "marketing" role on the contract, upload a new URL, SVG, or PNG for the token #[sv::msg(exec)] - fn upload_logo(&self, ctx: ExecCtx, logo: Logo) -> Result; + fn upload_logo( + &self, + ctx: ExecCtx, + logo: Logo, + ) -> Result, Self::Error>; /// Returns more metadata on the contract to display in the client: /// - description, logo, project url, etc. #[sv::msg(query)] - fn marketing_info(&self, ctx: QueryCtx) -> StdResult; + fn marketing_info(&self, ctx: QueryCtx) -> StdResult; /// Downloads the embedded logo data (if stored on chain). Errors if no logo data is stored for this /// contract. #[sv::msg(query)] - fn download_logo(&self, ctx: QueryCtx) -> StdResult; + fn download_logo(&self, ctx: QueryCtx) -> StdResult; } From 4ff2f313b9b0668c8069546532a22a63a2d35c53 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:49:15 +0200 Subject: [PATCH 05/13] test: Make cw20-minting iface generic --- examples/interfaces/cw20-minting/src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/interfaces/cw20-minting/src/lib.rs b/examples/interfaces/cw20-minting/src/lib.rs index f2627fba..405e3a89 100644 --- a/examples/interfaces/cw20-minting/src/lib.rs +++ b/examples/interfaces/cw20-minting/src/lib.rs @@ -2,33 +2,34 @@ pub mod responses; use cosmwasm_std::{Response, StdError, StdResult, Uint128}; use responses::MinterResponse; -use sylvia::types::{ExecCtx, QueryCtx}; +use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx}; use sylvia::{interface, schemars}; #[interface] -#[sv::custom(msg=cosmwasm_std::Empty, query=cosmwasm_std::Empty)] pub trait Cw20Minting { type Error: From; + type ExecC: CustomMsg; + type QueryC: CustomQuery; /// If authorized, creates amount new tokens and adds to the recipient balance. #[sv::msg(exec)] fn mint( &self, - ctx: ExecCtx, + ctx: ExecCtx, recipient: String, amount: Uint128, - ) -> Result; + ) -> Result, Self::Error>; /// The current minter may set a new minter. /// Setting the minter to None will remove the token's minter forever. #[sv::msg(exec)] fn update_minter( &self, - ctx: ExecCtx, + ctx: ExecCtx, new_minter: Option, - ) -> Result; + ) -> Result, Self::Error>; /// Returns who can mint and the hard cap on maximum tokens after minting. #[sv::msg(query)] - fn minter(&self, ctx: QueryCtx) -> StdResult>; + fn minter(&self, ctx: QueryCtx) -> StdResult>; } From 9fd78518211dbf6c5877525a908f93b436ca10e7 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:49:39 +0200 Subject: [PATCH 06/13] test: Make whitelist iface generic --- examples/interfaces/whitelist/src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/interfaces/whitelist/src/lib.rs b/examples/interfaces/whitelist/src/lib.rs index a14fc3f9..58bdf102 100644 --- a/examples/interfaces/whitelist/src/lib.rs +++ b/examples/interfaces/whitelist/src/lib.rs @@ -1,23 +1,28 @@ -use cosmwasm_std::{Response, StdResult}; +use cosmwasm_std::{Response, StdError, StdResult}; use responses::AdminListResponse; -use sylvia::types::{ExecCtx, QueryCtx}; +use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx}; use sylvia::{interface, schemars}; pub mod responses; #[interface] -#[sv::custom(msg=cosmwasm_std::Empty, query=cosmwasm_std::Empty)] pub trait Whitelist { - type Error: From; + type Error: From; + type ExecC: CustomMsg; + type QueryC: CustomQuery; #[sv::msg(exec)] - fn freeze(&self, ctx: ExecCtx) -> Result; + fn freeze(&self, ctx: ExecCtx) -> Result, Self::Error>; #[sv::msg(exec)] - fn update_admins(&self, ctx: ExecCtx, admins: Vec) -> Result; + fn update_admins( + &self, + ctx: ExecCtx, + admins: Vec, + ) -> Result, Self::Error>; #[sv::msg(query)] - fn admin_list(&self, ctx: QueryCtx) -> StdResult; + fn admin_list(&self, ctx: QueryCtx) -> StdResult; } #[cfg(test)] From 106f13cbd098122af957b958be0eb97563139965 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:52:49 +0200 Subject: [PATCH 07/13] test: fix typos in whitelist iface --- examples/interfaces/whitelist/src/responses.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/interfaces/whitelist/src/responses.rs b/examples/interfaces/whitelist/src/responses.rs index 252c06d6..420d87c7 100644 --- a/examples/interfaces/whitelist/src/responses.rs +++ b/examples/interfaces/whitelist/src/responses.rs @@ -9,8 +9,8 @@ pub struct AdminListResponse { #[cfg(any(test, feature = "test-utils"))] impl AdminListResponse { - /// Utility function forconverting message to its canonical form, so two messages with - /// different representation but same semantical meaning can be easly compared. + /// Utility function for converting message to its canonical form, so two messages with + /// different representation but same semantical meaning can be easily compared. /// /// It could be encapsulated in custom `PartialEq` implementation, but `PartialEq` is expected /// to be quickly, so it seems to be reasonable to keep it as representation-equality, and From 907284ea09c77a4b842ac4ffac2c82db6191dd31 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:54:02 +0200 Subject: [PATCH 08/13] test: Use empty types for cw1 impls --- examples/contracts/custom/src/cw1.rs | 5 ++++- examples/contracts/cw1-subkeys/src/cw1.rs | 5 ++++- examples/contracts/cw1-whitelist/src/cw1.rs | 5 ++++- examples/contracts/generic_contract/src/cw1.rs | 5 ++++- examples/contracts/generic_iface_on_contract/src/cw1.rs | 5 ++++- examples/contracts/generics_forwarded/src/cw1.rs | 5 ++++- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/examples/contracts/custom/src/cw1.rs b/examples/contracts/custom/src/cw1.rs index fcc93444..17c24978 100644 --- a/examples/contracts/custom/src/cw1.rs +++ b/examples/contracts/custom/src/cw1.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult}; +use cosmwasm_std::{CosmosMsg, Empty, Response, StdError, StdResult}; use cw1::{CanExecuteResp, Cw1}; use sylvia::types::{ExecCtx, QueryCtx}; @@ -6,6 +6,9 @@ use crate::contract::CustomContract; impl Cw1 for CustomContract { type Error = StdError; + type ExecC = Empty; + type QueryC = Empty; + type CosmosCustomMsg = Empty; fn execute(&self, _ctx: ExecCtx, _msgs: Vec) -> StdResult { Ok(Response::new()) diff --git a/examples/contracts/cw1-subkeys/src/cw1.rs b/examples/contracts/cw1-subkeys/src/cw1.rs index a349deb6..2e3a1d2e 100644 --- a/examples/contracts/cw1-subkeys/src/cw1.rs +++ b/examples/contracts/cw1-subkeys/src/cw1.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{ensure, Addr, Response, StdResult}; +use cosmwasm_std::{ensure, Addr, Empty, Response, StdResult}; use cw1::{CanExecuteResp, Cw1}; use sylvia::types::{ExecCtx, QueryCtx}; @@ -7,6 +7,9 @@ use crate::error::ContractError; impl Cw1 for Cw1SubkeysContract { type Error = ContractError; + type ExecC = Empty; + type QueryC = Empty; + type CosmosCustomMsg = Empty; fn execute( &self, diff --git a/examples/contracts/cw1-whitelist/src/cw1.rs b/examples/contracts/cw1-whitelist/src/cw1.rs index 0c94b658..2dc4e424 100644 --- a/examples/contracts/cw1-whitelist/src/cw1.rs +++ b/examples/contracts/cw1-whitelist/src/cw1.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{Addr, CosmosMsg, Response, StdResult}; +use cosmwasm_std::{Addr, CosmosMsg, Empty, Response, StdResult}; use cw1::{CanExecuteResp, Cw1}; use sylvia::types::{ExecCtx, QueryCtx}; @@ -7,6 +7,9 @@ use crate::error::ContractError; impl Cw1 for Cw1WhitelistContract { type Error = ContractError; + type ExecC = Empty; + type QueryC = Empty; + type CosmosCustomMsg = Empty; fn execute(&self, ctx: ExecCtx, msgs: Vec) -> Result { if !self.is_admin(ctx.deps.as_ref(), &ctx.info.sender) { diff --git a/examples/contracts/generic_contract/src/cw1.rs b/examples/contracts/generic_contract/src/cw1.rs index fff63bbd..420f06f7 100644 --- a/examples/contracts/generic_contract/src/cw1.rs +++ b/examples/contracts/generic_contract/src/cw1.rs @@ -1,5 +1,5 @@ use crate::contract::GenericContract; -use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult}; +use cosmwasm_std::{CosmosMsg, Empty, Response, StdError, StdResult}; use cw1::{CanExecuteResp, Cw1}; use sylvia::types::{ExecCtx, QueryCtx}; @@ -33,6 +33,9 @@ impl< > { type Error = StdError; + type ExecC = Empty; + type QueryC = Empty; + type CosmosCustomMsg = Empty; fn execute(&self, _ctx: ExecCtx, _msgs: Vec) -> StdResult { Ok(Response::new()) diff --git a/examples/contracts/generic_iface_on_contract/src/cw1.rs b/examples/contracts/generic_iface_on_contract/src/cw1.rs index a566f504..746e6a17 100644 --- a/examples/contracts/generic_iface_on_contract/src/cw1.rs +++ b/examples/contracts/generic_iface_on_contract/src/cw1.rs @@ -1,9 +1,12 @@ -use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult}; +use cosmwasm_std::{CosmosMsg, Empty, Response, StdError, StdResult}; use cw1::{CanExecuteResp, Cw1}; use sylvia::types::{ExecCtx, QueryCtx}; impl Cw1 for crate::contract::NonGenericContract { type Error = StdError; + type ExecC = Empty; + type QueryC = Empty; + type CosmosCustomMsg = Empty; fn execute(&self, _ctx: ExecCtx, _msgs: Vec) -> StdResult { Ok(Response::new()) diff --git a/examples/contracts/generics_forwarded/src/cw1.rs b/examples/contracts/generics_forwarded/src/cw1.rs index a4ddc172..44b78d74 100644 --- a/examples/contracts/generics_forwarded/src/cw1.rs +++ b/examples/contracts/generics_forwarded/src/cw1.rs @@ -1,5 +1,5 @@ use cosmwasm_schema::schemars::JsonSchema; -use cosmwasm_std::{CosmosMsg, CustomMsg, Response, StdResult}; +use cosmwasm_std::{CosmosMsg, CustomMsg, Empty, Response, StdResult}; use cw1::{CanExecuteResp, Cw1}; use serde::de::DeserializeOwned; use serde::Deserialize; @@ -57,6 +57,9 @@ where FieldT: 'static, { type Error = ContractError; + type ExecC = Empty; + type QueryC = Empty; + type CosmosCustomMsg = Empty; fn execute(&self, _ctx: ExecCtx, _msgs: Vec) -> Result { Ok(Response::new()) From 8e0d3e9b7fba19702ad6e955c240424cde7ac2b4 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:54:17 +0200 Subject: [PATCH 09/13] test: Use empty types for whitelist impls --- examples/contracts/cw1-subkeys/src/whitelist.rs | 4 +++- examples/contracts/cw1-whitelist/src/whitelist.rs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/contracts/cw1-subkeys/src/whitelist.rs b/examples/contracts/cw1-subkeys/src/whitelist.rs index 0817282d..c0e8af0d 100644 --- a/examples/contracts/cw1-subkeys/src/whitelist.rs +++ b/examples/contracts/cw1-subkeys/src/whitelist.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{Response, StdResult}; +use cosmwasm_std::{Empty, Response, StdResult}; use sylvia::types::{ExecCtx, QueryCtx}; use whitelist::responses::AdminListResponse; use whitelist::Whitelist; @@ -8,6 +8,8 @@ use crate::error::ContractError; impl Whitelist for Cw1SubkeysContract { type Error = ContractError; + type ExecC = Empty; + type QueryC = Empty; fn freeze(&self, ctx: ExecCtx) -> Result { self.whitelist.freeze(ctx).map_err(From::from) diff --git a/examples/contracts/cw1-whitelist/src/whitelist.rs b/examples/contracts/cw1-whitelist/src/whitelist.rs index 0d9d2240..ed003146 100644 --- a/examples/contracts/cw1-whitelist/src/whitelist.rs +++ b/examples/contracts/cw1-whitelist/src/whitelist.rs @@ -8,6 +8,8 @@ use crate::error::ContractError; impl Whitelist for Cw1WhitelistContract { type Error = ContractError; + type ExecC = Empty; + type QueryC = Empty; fn freeze(&self, ctx: ExecCtx) -> Result { if !self.is_admin(ctx.deps.as_ref(), &ctx.info.sender) { From 23b0a2526a59964905489f94a021c4317cbd3355 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:54:59 +0200 Subject: [PATCH 10/13] test: Use empty types for cw20-x impls --- examples/contracts/cw20-base/src/allowances.rs | 4 +++- examples/contracts/cw20-base/src/marketing.rs | 4 +++- examples/contracts/cw20-base/src/minting.rs | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/contracts/cw20-base/src/allowances.rs b/examples/contracts/cw20-base/src/allowances.rs index deb2d4db..2433ad1f 100644 --- a/examples/contracts/cw20-base/src/allowances.rs +++ b/examples/contracts/cw20-base/src/allowances.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{Addr, Binary, Order, Response, StdError, StdResult, Uint128}; +use cosmwasm_std::{Addr, Binary, Empty, Order, Response, StdError, StdResult, Uint128}; use cw20_allowances::responses::{ AllAccountsResponse, AllAllowancesResponse, AllSpenderAllowancesResponse, AllowanceInfo, AllowanceResponse, SpenderAllowanceInfo, @@ -18,6 +18,8 @@ const DEFAULT_LIMIT: u32 = 10; impl Cw20Allowances for Cw20Base { type Error = ContractError; + type ExecC = Empty; + type QueryC = Empty; /// Allows spender to access an additional amount tokens from the owner's (env.sender) account. /// If expires is Some(), overwrites current allowance expiration with this one. diff --git a/examples/contracts/cw20-base/src/marketing.rs b/examples/contracts/cw20-base/src/marketing.rs index ed95836c..4bf344c0 100644 --- a/examples/contracts/cw20-base/src/marketing.rs +++ b/examples/contracts/cw20-base/src/marketing.rs @@ -1,13 +1,15 @@ use crate::contract::Cw20Base; use crate::error::ContractError; use crate::validation::verify_logo; -use cosmwasm_std::{Response, StdError, StdResult}; +use cosmwasm_std::{Empty, Response, StdError, StdResult}; use cw20_marketing::responses::{DownloadLogoResponse, LogoInfo, MarketingInfoResponse}; use cw20_marketing::{Cw20Marketing, EmbeddedLogo, Logo}; use sylvia::types::{ExecCtx, QueryCtx}; impl Cw20Marketing for Cw20Base { type Error = ContractError; + type ExecC = Empty; + type QueryC = Empty; fn update_marketing( &self, diff --git a/examples/contracts/cw20-base/src/minting.rs b/examples/contracts/cw20-base/src/minting.rs index a6e4e416..4ec047a5 100644 --- a/examples/contracts/cw20-base/src/minting.rs +++ b/examples/contracts/cw20-base/src/minting.rs @@ -1,12 +1,14 @@ use crate::contract::{Cw20Base, MinterData}; use crate::error::ContractError; -use cosmwasm_std::{Response, StdResult, Uint128}; +use cosmwasm_std::{Empty, Response, StdResult, Uint128}; use cw20_minting::responses::MinterResponse; use cw20_minting::Cw20Minting; use sylvia::types::{ExecCtx, QueryCtx}; impl Cw20Minting for Cw20Base { type Error = ContractError; + type ExecC = Empty; + type QueryC = Empty; fn mint( &self, From 5b7cd174a812d893c33d005c9f94dc7de871f20c Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:01:48 +0200 Subject: [PATCH 11/13] test: Use empty types for cw1 tests --- examples/interfaces/cw1/src/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/interfaces/cw1/src/lib.rs b/examples/interfaces/cw1/src/lib.rs index 188318e2..8146a113 100644 --- a/examples/interfaces/cw1/src/lib.rs +++ b/examples/interfaces/cw1/src/lib.rs @@ -41,11 +41,13 @@ pub trait Cw1 { #[cfg(test)] mod tests { - use cosmwasm_std::{coins, from_json, to_json_binary, BankMsg}; + use cosmwasm_std::{coins, from_json, to_json_binary, BankMsg, Empty}; + + use crate::sv::{Cw1ExecMsg, Cw1QueryMsg}; #[test] fn execute() { - let original = super::sv::ExecMsg::Execute { + let original: Cw1ExecMsg = super::sv::ExecMsg::Execute { msgs: vec![BankMsg::Send { to_address: "receiver".to_owned(), amount: coins(10, "atom"), @@ -61,13 +63,13 @@ mod tests { #[test] fn execute_from_json() { - let deserialized = from_json(br#"{"execute": { "msgs": [] }}"#).unwrap(); + let deserialized: Cw1ExecMsg = from_json(br#"{"execute": { "msgs": [] }}"#).unwrap(); assert_eq!(super::sv::ExecMsg::Execute { msgs: vec![] }, deserialized); } #[test] fn query() { - let original = super::sv::QueryMsg::CanExecute { + let original: Cw1QueryMsg = super::sv::QueryMsg::CanExecute { sender: "sender".to_owned(), msg: BankMsg::Send { to_address: "receiver".to_owned(), @@ -84,7 +86,7 @@ mod tests { #[test] fn query_from_json() { - let deserialized = from_json( + let deserialized: Cw1QueryMsg = from_json( br#"{"can_execute": { "sender": "address", "msg": { From 7b18347fb0f4deaee635cf9cd24d6548e2efce41 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:02:27 +0200 Subject: [PATCH 12/13] test: Use empty types for cw4 tests --- examples/interfaces/cw4/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/interfaces/cw4/src/lib.rs b/examples/interfaces/cw4/src/lib.rs index f19c79b9..10e10bcd 100644 --- a/examples/interfaces/cw4/src/lib.rs +++ b/examples/interfaces/cw4/src/lib.rs @@ -75,7 +75,7 @@ pub trait Cw4 { #[cfg(test)] mod tests { - use cosmwasm_std::{from_json, to_json_binary}; + use cosmwasm_std::{from_json, to_json_binary, Empty}; use super::sv::*; @@ -96,7 +96,8 @@ mod tests { let original_msg = Cw4QueryMsg::Admin {}; let serialized_msg = to_json_binary(&original_msg).unwrap(); - let serialized_msg: Cw4QueryMsg = from_json(serialized_msg).unwrap(); + let serialized_msg: Cw4QueryMsg = + from_json(serialized_msg).unwrap(); assert_eq!(serialized_msg, original_msg); } @@ -115,7 +116,8 @@ mod tests { #[test] fn query_from_json() { - let deserialized: Cw4QueryMsg = from_json(br#"{"admin": {}}"#).unwrap(); + let deserialized: Cw4QueryMsg = + from_json(br#"{"admin": {}}"#).unwrap(); assert_eq!(deserialized, Cw4QueryMsg::Admin {}); } From 4e0bafd64f8ad2a0357f9bb26f75fe8cb929209a Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:37:10 +0200 Subject: [PATCH 13/13] test: Fix Cw4 responses --- examples/interfaces/cw4/src/lib.rs | 34 +++++++++-------------- examples/interfaces/cw4/src/responses.rs | 35 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 examples/interfaces/cw4/src/responses.rs diff --git a/examples/interfaces/cw4/src/lib.rs b/examples/interfaces/cw4/src/lib.rs index 10e10bcd..b4c4ecbb 100644 --- a/examples/interfaces/cw4/src/lib.rs +++ b/examples/interfaces/cw4/src/lib.rs @@ -1,4 +1,9 @@ +pub mod responses; + use cosmwasm_std::{Response, StdError}; +use responses::{ + AdminResponse, HooksResponse, MemberListResponse, MemberResponse, TotalWeightResponse, +}; use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx}; use sylvia::{interface, schemars}; @@ -7,11 +12,6 @@ pub trait Cw4 { type Error: From; type ExecC: CustomMsg; type QueryC: CustomQuery; - type MemberCustomMsg: CustomMsg; - type ListMembersCustomMsg: CustomMsg; - type TotalWeightCustomMsg: CustomMsg; - type AdminCustomMsg: CustomMsg; - type HooksCustomMsg: CustomMsg; #[sv::msg(exec)] fn update_admin( @@ -46,36 +46,30 @@ pub trait Cw4 { &self, ctx: QueryCtx, member: String, - ) -> Result, Self::Error>; + ) -> Result, Self::Error>; #[sv::msg(query)] fn list_members( &self, ctx: QueryCtx, - ) -> Result, Self::Error>; + ) -> Result, Self::Error>; #[sv::msg(query)] fn total_weight( &self, ctx: QueryCtx, - ) -> Result, Self::Error>; + ) -> Result, Self::Error>; #[sv::msg(query)] - fn admin( - &self, - ctx: QueryCtx, - ) -> Result, Self::Error>; + fn admin(&self, ctx: QueryCtx) -> Result, Self::Error>; #[sv::msg(query)] - fn hooks( - &self, - ctx: QueryCtx, - ) -> Result, Self::Error>; + fn hooks(&self, ctx: QueryCtx) -> Result, Self::Error>; } #[cfg(test)] mod tests { - use cosmwasm_std::{from_json, to_json_binary, Empty}; + use cosmwasm_std::{from_json, to_json_binary}; use super::sv::*; @@ -96,8 +90,7 @@ mod tests { let original_msg = Cw4QueryMsg::Admin {}; let serialized_msg = to_json_binary(&original_msg).unwrap(); - let serialized_msg: Cw4QueryMsg = - from_json(serialized_msg).unwrap(); + let serialized_msg: Cw4QueryMsg = from_json(serialized_msg).unwrap(); assert_eq!(serialized_msg, original_msg); } @@ -116,8 +109,7 @@ mod tests { #[test] fn query_from_json() { - let deserialized: Cw4QueryMsg = - from_json(br#"{"admin": {}}"#).unwrap(); + let deserialized: Cw4QueryMsg = from_json(br#"{"admin": {}}"#).unwrap(); assert_eq!(deserialized, Cw4QueryMsg::Admin {}); } diff --git a/examples/interfaces/cw4/src/responses.rs b/examples/interfaces/cw4/src/responses.rs new file mode 100644 index 00000000..f5797e8b --- /dev/null +++ b/examples/interfaces/cw4/src/responses.rs @@ -0,0 +1,35 @@ +use cosmwasm_schema::cw_serde; + +#[cw_serde] +pub struct AdminResponse { + pub admin: Option, +} + +/// A group member has a weight associated with them. +/// This may all be equal, or may have meaning in the app that +/// makes use of the group (eg. voting power) +#[cw_serde] +pub struct Member { + pub addr: String, + pub weight: u64, +} + +#[cw_serde] +pub struct MemberListResponse { + pub members: Vec, +} + +#[cw_serde] +pub struct MemberResponse { + pub weight: Option, +} + +#[cw_serde] +pub struct TotalWeightResponse { + pub weight: u64, +} + +#[cw_serde] +pub struct HooksResponse { + pub hooks: Vec, +}