Skip to content

Commit

Permalink
chore: Remove SvCustomMsg and SvCustomQuery from sylvia types (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird authored Mar 14, 2024
1 parent 606a812 commit a9fbe33
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.70.0
toolchain: 1.73.0
target: wasm32-unknown-unknown
profile: minimal
override: true
Expand Down
4 changes: 2 additions & 2 deletions examples/contracts/cw1-subkeys/src/cw1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ impl Cw1 for Cw1SubkeysContract<'_> {
ctx: ExecCtx,
msgs: Vec<cosmwasm_std::CosmosMsg>,
) -> Result<cosmwasm_std::Response, Self::Error> {
let authorized: StdResult<_> = msgs.iter().fold(Ok(true), |acc, msg| {
Ok(acc? & self.is_authorized(ctx.deps.as_ref(), &ctx.env, &ctx.info.sender, msg)?)
let authorized: StdResult<_> = msgs.iter().try_fold(true, |acc, msg| {
Ok(acc & self.is_authorized(ctx.deps.as_ref(), &ctx.env, &ctx.info.sender, msg)?)
});

ensure!(authorized?, ContractError::Unauthorized);
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/generic_contract/src/bin/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmwasm_schema::write_api;
#[cfg(not(tarpaulin_include))]
fn main() {
use generic_contract::contract::sv::{ContractExecMsg, ContractQueryMsg, InstantiateMsg};
use sylvia::types::SvCustomMsg;
use generic_contract::contract::SvCustomMsg;

write_api! {
instantiate: InstantiateMsg<SvCustomMsg>,
Expand Down
17 changes: 11 additions & 6 deletions examples/contracts/generic_contract/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use cosmwasm_std::{Reply, Response, StdResult};
use cw_storage_plus::Item;
use serde::Deserialize;
use sylvia::types::{
CustomMsg, ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, ReplyCtx, SudoCtx, SvCustomMsg,
SvCustomQuery,
};
use sylvia::types::{CustomMsg, ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, ReplyCtx, SudoCtx};
use sylvia::{contract, schemars};

#[cfg(not(feature = "library"))]
use sylvia::entry_points;

#[cosmwasm_schema::cw_serde]
pub struct SvCustomMsg;
impl cosmwasm_std::CustomMsg for SvCustomMsg {}

#[cosmwasm_schema::cw_serde]
pub struct SvCustomQuery;
impl cosmwasm_std::CustomQuery for SvCustomQuery {}

pub struct GenericContract<
InstantiateT,
Exec1T,
Expand Down Expand Up @@ -42,7 +47,7 @@ pub struct GenericContract<
)>,
}

#[cfg_attr(not(feature = "library"), entry_points(generics<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, String>))]
#[cfg_attr(not(feature = "library"), entry_points(generics<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, String>))]
#[contract]
#[sv::messages(cw1 as Cw1: custom(msg, query))]
#[sv::messages(generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
Expand Down Expand Up @@ -189,9 +194,9 @@ where
#[cfg(test)]
mod tests {
use super::sv::multitest_utils::CodeId;
use super::{SvCustomMsg, SvCustomQuery};
use crate::contract::sv::multitest_utils::GenericContractProxy;
use sylvia::multitest::App;
use sylvia::types::{SvCustomMsg, SvCustomQuery};

#[test]
fn generic_contract() {
Expand Down
6 changes: 4 additions & 2 deletions examples/contracts/generic_contract/src/custom_and_generic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult};
use custom_and_generic::CustomAndGeneric;
use sylvia::types::{ExecCtx, QueryCtx, SudoCtx, SvCustomMsg, SvCustomQuery};
use sylvia::types::{ExecCtx, QueryCtx, SudoCtx};

use crate::contract::{SvCustomMsg, SvCustomQuery};

impl<
InstantiateT,
Expand Down Expand Up @@ -102,10 +104,10 @@ impl<

#[cfg(test)]
mod tests {
use super::{SvCustomMsg, SvCustomQuery};
use crate::contract::sv::multitest_utils::CodeId;
use custom_and_generic::sv::test_utils::CustomAndGenericProxy;
use sylvia::multitest::App;
use sylvia::types::{SvCustomMsg, SvCustomQuery};

#[test]
fn proxy_methods() {
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/generic_contract/src/cw1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ impl<
#[cfg(test)]
mod tests {
use crate::contract::sv::multitest_utils::CodeId;
use crate::contract::{SvCustomMsg, SvCustomQuery};
use cosmwasm_std::{CosmosMsg, Empty};
use cw1::sv::test_utils::Cw1Proxy;
use sylvia::multitest::App;
use sylvia::types::{SvCustomMsg, SvCustomQuery};

#[test]
fn proxy_methods() {
Expand Down
6 changes: 4 additions & 2 deletions examples/contracts/generic_contract/src/generic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult};
use generic::Generic;
use serde::Deserialize;
use sylvia::types::{CustomMsg, ExecCtx, QueryCtx, SudoCtx, SvCustomMsg};
use sylvia::types::{CustomMsg, ExecCtx, QueryCtx, SudoCtx};

use crate::contract::SvCustomMsg;

impl<
InstantiateT,
Expand Down Expand Up @@ -115,10 +117,10 @@ where
#[cfg(test)]
mod tests {
use crate::contract::sv::multitest_utils::CodeId;
use crate::contract::{SvCustomMsg, SvCustomQuery};
use cosmwasm_std::CosmosMsg;
use generic::sv::test_utils::GenericProxy;
use sylvia::multitest::App;
use sylvia::types::{SvCustomMsg, SvCustomQuery};

#[test]
fn proxy_methods() {
Expand Down
12 changes: 10 additions & 2 deletions examples/contracts/generic_iface_on_contract/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
use cosmwasm_std::{Response, StdResult};
use sylvia::types::{InstantiateCtx, SvCustomMsg, SvCustomQuery};
use sylvia::types::InstantiateCtx;
use sylvia::{contract, schemars};

#[cfg(not(feature = "library"))]
use sylvia::entry_points;

pub struct NonGenericContract;

#[cosmwasm_schema::cw_serde]
pub struct SvCustomMsg;
impl cosmwasm_std::CustomMsg for SvCustomMsg {}

#[cosmwasm_schema::cw_serde]
pub struct SvCustomQuery;
impl cosmwasm_std::CustomQuery for SvCustomQuery {}

#[cfg_attr(not(feature = "library"), entry_points)]
#[contract]
#[sv::messages(generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
Expand All @@ -30,9 +38,9 @@ impl NonGenericContract {

#[cfg(test)]
mod tests {
use super::{SvCustomMsg, SvCustomQuery};
use cosmwasm_std::{CosmosMsg, Empty};
use sylvia::multitest::App;
use sylvia::types::{SvCustomMsg, SvCustomQuery};

use super::NonGenericContract;
use custom_and_generic::sv::test_utils::CustomAndGenericProxy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::contract::{SvCustomMsg, SvCustomQuery};
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult};
use custom_and_generic::CustomAndGeneric;
use sylvia::types::{ExecCtx, QueryCtx, SudoCtx, SvCustomMsg, SvCustomQuery};
use sylvia::types::{ExecCtx, QueryCtx, SudoCtx};

impl CustomAndGeneric for crate::contract::NonGenericContract {
type Error = StdError;
Expand Down
4 changes: 3 additions & 1 deletion examples/contracts/generic_iface_on_contract/src/generic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult};
use generic::Generic;
use sylvia::types::{ExecCtx, QueryCtx, SudoCtx, SvCustomMsg};
use sylvia::types::{ExecCtx, QueryCtx, SudoCtx};

use crate::contract::SvCustomMsg;

impl Generic for crate::contract::NonGenericContract {
type Error = StdError;
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/generics_forwarded/src/bin/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmwasm_schema::write_api;
#[cfg(not(tarpaulin_include))]
fn main() {
use generics_forwarded::contract::sv::{ContractExecMsg, ContractQueryMsg, InstantiateMsg};
use sylvia::types::SvCustomMsg;
use generics_forwarded::contract::SvCustomMsg;

write_api! {
instantiate: InstantiateMsg<SvCustomMsg>,
Expand Down
12 changes: 8 additions & 4 deletions examples/contracts/generics_forwarded/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ use cw_storage_plus::Item;
use serde::Deserialize;
use sylvia::types::{
CustomMsg, CustomQuery, ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, ReplyCtx, SudoCtx,
SvCustomMsg,
};
use sylvia::{contract, schemars};

#[cfg(not(feature = "library"))]
use sylvia::types::SvCustomQuery;
#[cosmwasm_schema::cw_serde]
pub struct SvCustomMsg;
impl cosmwasm_std::CustomMsg for SvCustomMsg {}

#[cosmwasm_schema::cw_serde]
pub struct SvCustomQuery;
impl cosmwasm_std::CustomQuery for SvCustomQuery {}

pub struct GenericsForwardedContract<
InstantiateT,
Expand Down Expand Up @@ -198,9 +202,9 @@ where
#[cfg(test)]
mod tests {
use super::sv::multitest_utils::CodeId;
use super::{SvCustomMsg, SvCustomQuery};
use crate::contract::sv::multitest_utils::GenericsForwardedContractProxy;
use sylvia::multitest::App;
use sylvia::types::{SvCustomMsg, SvCustomQuery};

#[test]
fn generic_contract() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult};
use custom_and_generic::CustomAndGeneric;
use serde::Deserialize;
use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx, SudoCtx, SvCustomMsg};
use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx, SudoCtx};

use crate::contract::SvCustomMsg;

impl<
InstantiateT,
Expand Down Expand Up @@ -123,10 +125,10 @@ where
#[cfg(test)]
mod tests {
use crate::contract::sv::multitest_utils::CodeId;
use crate::contract::{SvCustomMsg, SvCustomQuery};
use cosmwasm_std::CosmosMsg;
use custom_and_generic::sv::test_utils::CustomAndGenericProxy;
use sylvia::multitest::App;
use sylvia::types::{SvCustomMsg, SvCustomQuery};

#[test]
fn proxy_methods() {
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/generics_forwarded/src/cw1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ where
#[cfg(test)]
mod tests {
use crate::contract::sv::multitest_utils::CodeId;
use crate::contract::{SvCustomMsg, SvCustomQuery};
use cosmwasm_std::{CosmosMsg, Empty};
use cw1::sv::test_utils::Cw1Proxy;
use sylvia::multitest::App;
use sylvia::types::{SvCustomMsg, SvCustomQuery};

#[test]
fn proxy_methods() {
Expand Down
6 changes: 4 additions & 2 deletions examples/contracts/generics_forwarded/src/generic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult};
use generic::Generic;
use serde::Deserialize;
use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx, SudoCtx, SvCustomMsg};
use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx, SudoCtx};

use crate::contract::SvCustomMsg;

impl<
InstantiateT,
Expand Down Expand Up @@ -121,10 +123,10 @@ where
#[cfg(test)]
mod tests {
use crate::contract::sv::multitest_utils::CodeId;
use crate::contract::{SvCustomMsg, SvCustomQuery};
use cosmwasm_std::CosmosMsg;
use generic::sv::test_utils::GenericProxy;
use sylvia::multitest::App;
use sylvia::types::{SvCustomMsg, SvCustomQuery};

#[test]
fn proxy_methods() {
Expand Down
6 changes: 5 additions & 1 deletion examples/interfaces/custom-and-generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ pub trait CustomAndGeneric {
mod tests {
use cosmwasm_std::testing::mock_dependencies;
use cosmwasm_std::{Addr, CosmosMsg, Empty, QuerierWrapper};
use sylvia::types::{InterfaceApi, SvCustomMsg};
use sylvia::types::InterfaceApi;

use crate::sv::Querier;

#[cosmwasm_schema::cw_serde]
pub struct SvCustomMsg;
impl cosmwasm_std::CustomMsg for SvCustomMsg {}

#[test]
fn construct_messages() {
let contract = Addr::unchecked("contract");
Expand Down
6 changes: 5 additions & 1 deletion examples/interfaces/generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ pub trait Generic {
mod tests {
use cosmwasm_std::testing::mock_dependencies;
use cosmwasm_std::{Addr, CosmosMsg, Empty, QuerierWrapper};
use sylvia::types::{InterfaceApi, SvCustomMsg};
use sylvia::types::InterfaceApi;

use crate::sv::Querier;

#[cosmwasm_schema::cw_serde]
pub struct SvCustomMsg;
impl cosmwasm_std::CustomMsg for SvCustomMsg {}

#[test]
fn construct_messages() {
let contract = Addr::unchecked("contract");
Expand Down
13 changes: 0 additions & 13 deletions sylvia/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Deps, DepsMut, Empty, Env, MessageInfo};
use schemars::JsonSchema;
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -198,18 +197,6 @@ pub trait CustomQuery: cosmwasm_std::CustomQuery + DeserializeOwned + JsonSchema

impl<T> CustomQuery for T where T: cosmwasm_std::CustomQuery + DeserializeOwned + JsonSchema {}

/// This type is meant to be used in internal testing purpose.
#[cw_serde]
pub struct SvCustomMsg;

impl cosmwasm_std::CustomMsg for SvCustomMsg {}

/// This type is meant to be used in internal testing purpose.
#[cw_serde]
pub struct SvCustomQuery;

impl cosmwasm_std::CustomQuery for SvCustomQuery {}

/// Api trait for easier access to generated types and messages.
pub trait InterfaceApi {
type Exec;
Expand Down
6 changes: 5 additions & 1 deletion sylvia/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ mod tests {
use crate::SomeContract;
use cosmwasm_std::testing::mock_dependencies;
use cosmwasm_std::{Addr, QuerierWrapper};
use sylvia::types::{ContractApi, SvCustomMsg};
use sylvia::types::ContractApi;

#[cosmwasm_schema::cw_serde]
pub struct SvCustomMsg;
impl cosmwasm_std::CustomMsg for SvCustomMsg {}

#[test]
fn api() {
Expand Down

0 comments on commit a9fbe33

Please sign in to comment.