From 25500b7c8dae86c2df35ed0a8dcbf3563d79f1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Wed, 25 Oct 2023 14:57:38 +0200 Subject: [PATCH] feat: Wrap contract types in `sv` module --- examples/contracts/custom/src/bin/schema.rs | 2 +- .../contracts/custom/src/multitest/tests.rs | 2 +- .../contracts/cw1-subkeys/src/bin/schema.rs | 2 +- .../cw1-subkeys/src/multitest/tests.rs | 2 +- .../contracts/cw1-whitelist/src/bin/schema.rs | 2 +- .../contracts/cw1-whitelist/src/contract.rs | 2 +- .../contracts/cw1-whitelist/src/multitest.rs | 2 +- .../contracts/cw20-base/src/bin/schema.rs | 2 +- .../src/multitest/allowances_tests.rs | 4 +- .../cw20-base/src/multitest/base_tests.rs | 4 +- .../src/multitest/marketing_tests.rs | 2 +- .../cw20-base/src/multitest/minting_tests.rs | 2 +- .../entry-points-overriding/src/bin/schema.rs | 2 +- .../entry-points-overriding/src/messages.rs | 3 +- .../entry-points-overriding/src/multitest.rs | 7 +- .../generic_contract/src/bin/schema.rs | 2 +- .../generic_contract/src/contract.rs | 2 +- .../src/custom_and_generic.rs | 2 +- .../contracts/generic_contract/src/cw1.rs | 2 +- .../contracts/generic_contract/src/generic.rs | 2 +- .../src/bin/schema.rs | 4 +- .../generic_iface_on_contract/src/contract.rs | 2 +- sylvia-derive/src/input.rs | 14 +- sylvia-derive/src/message.rs | 6 +- sylvia/tests/custom_msg.rs | 2 +- sylvia/tests/custom_query.rs | 2 +- sylvia/tests/dispatching.rs | 144 ++++++++++-------- sylvia/tests/entry_points.rs | 6 +- sylvia/tests/messages_generation.rs | 20 +-- sylvia/tests/querier.rs | 14 +- sylvia/tests/query_returns.rs | 2 +- sylvia/tests/remote.rs | 6 +- sylvia/tests/replies.rs | 8 +- 33 files changed, 150 insertions(+), 130 deletions(-) diff --git a/examples/contracts/custom/src/bin/schema.rs b/examples/contracts/custom/src/bin/schema.rs index a60261b8..554d313c 100644 --- a/examples/contracts/custom/src/bin/schema.rs +++ b/examples/contracts/custom/src/bin/schema.rs @@ -1,6 +1,6 @@ use cosmwasm_schema::write_api; -use custom::contract::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; +use custom::contract::sv::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; #[cfg(not(tarpaulin_include))] fn main() { diff --git a/examples/contracts/custom/src/multitest/tests.rs b/examples/contracts/custom/src/multitest/tests.rs index 5bb92866..606444ce 100644 --- a/examples/contracts/custom/src/multitest/tests.rs +++ b/examples/contracts/custom/src/multitest/tests.rs @@ -1,6 +1,6 @@ use sylvia::multitest::App; -use crate::contract::multitest_utils::CodeId; +use crate::contract::sv::multitest_utils::CodeId; use super::custom_module::{CustomApp, CustomModule}; diff --git a/examples/contracts/cw1-subkeys/src/bin/schema.rs b/examples/contracts/cw1-subkeys/src/bin/schema.rs index b07cdbaa..c5129235 100644 --- a/examples/contracts/cw1-subkeys/src/bin/schema.rs +++ b/examples/contracts/cw1-subkeys/src/bin/schema.rs @@ -1,6 +1,6 @@ use cosmwasm_schema::write_api; -use cw1_subkeys::contract::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; +use cw1_subkeys::contract::sv::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; #[cfg(not(tarpaulin_include))] fn main() { diff --git a/examples/contracts/cw1-subkeys/src/multitest/tests.rs b/examples/contracts/cw1-subkeys/src/multitest/tests.rs index 71cc20d0..a92fe845 100644 --- a/examples/contracts/cw1-subkeys/src/multitest/tests.rs +++ b/examples/contracts/cw1-subkeys/src/multitest/tests.rs @@ -3,7 +3,7 @@ use cw2::{query_contract_info, ContractVersion}; use cw_utils::{Expiration, NativeBalance}; use sylvia::multitest::App; -use crate::contract::multitest_utils::CodeId; +use crate::contract::sv::multitest_utils::CodeId; use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION}; const ATOM: &str = "atom"; diff --git a/examples/contracts/cw1-whitelist/src/bin/schema.rs b/examples/contracts/cw1-whitelist/src/bin/schema.rs index fa957edb..3096b127 100644 --- a/examples/contracts/cw1-whitelist/src/bin/schema.rs +++ b/examples/contracts/cw1-whitelist/src/bin/schema.rs @@ -1,6 +1,6 @@ use cosmwasm_schema::write_api; -use cw1_whitelist::contract::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; +use cw1_whitelist::contract::sv::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; #[cfg(not(tarpaulin_include))] fn main() { diff --git a/examples/contracts/cw1-whitelist/src/contract.rs b/examples/contracts/cw1-whitelist/src/contract.rs index 9f5ae735..2bf302af 100644 --- a/examples/contracts/cw1-whitelist/src/contract.rs +++ b/examples/contracts/cw1-whitelist/src/contract.rs @@ -290,7 +290,7 @@ mod tests { mod msgs { use cosmwasm_std::{from_binary, from_slice, to_binary, BankMsg}; - use crate::contract::{ContractExecMsg, ContractQueryMsg}; + use crate::contract::sv::{ContractExecMsg, ContractQueryMsg}; #[test] fn freeze() { diff --git a/examples/contracts/cw1-whitelist/src/multitest.rs b/examples/contracts/cw1-whitelist/src/multitest.rs index 812f982d..a91713d6 100644 --- a/examples/contracts/cw1-whitelist/src/multitest.rs +++ b/examples/contracts/cw1-whitelist/src/multitest.rs @@ -3,7 +3,7 @@ mod test { use cosmwasm_std::{to_binary, WasmMsg}; use whitelist::responses::AdminListResponse; - use crate::contract::multitest_utils::CodeId; + use crate::contract::sv::multitest_utils::CodeId; use crate::cw1::sv::test_utils::Cw1; use crate::error::ContractError; use crate::whitelist::sv::test_utils::Whitelist; diff --git a/examples/contracts/cw20-base/src/bin/schema.rs b/examples/contracts/cw20-base/src/bin/schema.rs index 3482c2fb..ee47c95c 100644 --- a/examples/contracts/cw20-base/src/bin/schema.rs +++ b/examples/contracts/cw20-base/src/bin/schema.rs @@ -1,6 +1,6 @@ use cosmwasm_schema::write_api; -use cw20_base::contract::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; +use cw20_base::contract::sv::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; #[cfg(not(tarpaulin_include))] fn main() { diff --git a/examples/contracts/cw20-base/src/multitest/allowances_tests.rs b/examples/contracts/cw20-base/src/multitest/allowances_tests.rs index 22c2735d..29fdf0ad 100644 --- a/examples/contracts/cw20-base/src/multitest/allowances_tests.rs +++ b/examples/contracts/cw20-base/src/multitest/allowances_tests.rs @@ -8,10 +8,10 @@ use cw_utils::Expiration; use sylvia::multitest::App; use crate::allowances::sv::test_utils::Cw20Allowances; -use crate::contract::multitest_utils::CodeId; +use crate::contract::sv::multitest_utils::CodeId; use crate::contract::InstantiateMsgData; use crate::error::ContractError; -use crate::multitest::receiver_contract::multitest_utils::CodeId as ReceiverCodeId; +use crate::multitest::receiver_contract::sv::multitest_utils::CodeId as ReceiverCodeId; use crate::responses::Cw20Coin; #[test] diff --git a/examples/contracts/cw20-base/src/multitest/base_tests.rs b/examples/contracts/cw20-base/src/multitest/base_tests.rs index 7fdd3821..f97a1699 100644 --- a/examples/contracts/cw20-base/src/multitest/base_tests.rs +++ b/examples/contracts/cw20-base/src/multitest/base_tests.rs @@ -4,10 +4,10 @@ use cw_utils::Expiration; use sylvia::multitest::App; use crate::allowances::sv::test_utils::Cw20Allowances; -use crate::contract::multitest_utils::CodeId; +use crate::contract::sv::multitest_utils::CodeId; use crate::contract::InstantiateMsgData; use crate::error::ContractError; -use crate::multitest::receiver_contract::multitest_utils::CodeId as ReceiverCodeId; +use crate::multitest::receiver_contract::sv::multitest_utils::CodeId as ReceiverCodeId; use crate::responses::{BalanceResponse, Cw20Coin, TokenInfoResponse}; #[test] diff --git a/examples/contracts/cw20-base/src/multitest/marketing_tests.rs b/examples/contracts/cw20-base/src/multitest/marketing_tests.rs index d8da5c10..c5e22350 100644 --- a/examples/contracts/cw20-base/src/multitest/marketing_tests.rs +++ b/examples/contracts/cw20-base/src/multitest/marketing_tests.rs @@ -3,7 +3,7 @@ use cw20_marketing::responses::{DownloadLogoResponse, LogoInfo, MarketingInfoRes use cw20_marketing::{EmbeddedLogo, Logo}; use sylvia::multitest::App; -use crate::contract::multitest_utils::CodeId; +use crate::contract::sv::multitest_utils::CodeId; use crate::contract::{InstantiateMarketingInfo, InstantiateMsgData}; use crate::error::ContractError; use crate::marketing::sv::test_utils::Cw20Marketing; diff --git a/examples/contracts/cw20-base/src/multitest/minting_tests.rs b/examples/contracts/cw20-base/src/multitest/minting_tests.rs index 72bdad07..50418d84 100644 --- a/examples/contracts/cw20-base/src/multitest/minting_tests.rs +++ b/examples/contracts/cw20-base/src/multitest/minting_tests.rs @@ -2,7 +2,7 @@ use cosmwasm_std::{StdError, Uint128}; use cw20_minting::responses::MinterResponse; use sylvia::multitest::App; -use crate::contract::multitest_utils::CodeId; +use crate::contract::sv::multitest_utils::CodeId; use crate::contract::InstantiateMsgData; use crate::error::ContractError; use crate::minting::sv::test_utils::Cw20Minting; diff --git a/examples/contracts/entry-points-overriding/src/bin/schema.rs b/examples/contracts/entry-points-overriding/src/bin/schema.rs index 0c9fdd48..6d5bd4e0 100644 --- a/examples/contracts/entry-points-overriding/src/bin/schema.rs +++ b/examples/contracts/entry-points-overriding/src/bin/schema.rs @@ -1,6 +1,6 @@ use cosmwasm_schema::write_api; -use entry_points_overriding::contract::{ContractQueryMsg, InstantiateMsg}; +use entry_points_overriding::contract::sv::{ContractQueryMsg, InstantiateMsg}; use entry_points_overriding::messages::CustomExecMsg; use entry_points_overriding::messages::SudoMsg; diff --git a/examples/contracts/entry-points-overriding/src/messages.rs b/examples/contracts/entry-points-overriding/src/messages.rs index c032e2b4..56b372b5 100644 --- a/examples/contracts/entry-points-overriding/src/messages.rs +++ b/examples/contracts/entry-points-overriding/src/messages.rs @@ -2,7 +2,8 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::{DepsMut, Env, MessageInfo, Response, StdError, StdResult}; use sylvia::types::ExecCtx; -use crate::contract::{ContractExecMsg, CounterContract}; +use crate::contract::sv::ContractExecMsg; +use crate::contract::CounterContract; #[cw_serde] pub struct CountResponse { diff --git a/examples/contracts/entry-points-overriding/src/multitest.rs b/examples/contracts/entry-points-overriding/src/multitest.rs index d8224516..9efda4e8 100644 --- a/examples/contracts/entry-points-overriding/src/multitest.rs +++ b/examples/contracts/entry-points-overriding/src/multitest.rs @@ -1,9 +1,8 @@ #[cfg(test)] mod test { - use crate::{ - contract::{multitest_utils::CodeId, ContractExecMsg, ExecMsg}, - messages::{CustomExecMsg, SudoMsg, UserExecMsg}, - }; + use crate::contract::sv::multitest_utils::CodeId; + use crate::contract::sv::{ContractExecMsg, ExecMsg}; + use crate::messages::{CustomExecMsg, SudoMsg, UserExecMsg}; use cosmwasm_std::Addr; use cw_multi_test::Executor; use sylvia::multitest::App; diff --git a/examples/contracts/generic_contract/src/bin/schema.rs b/examples/contracts/generic_contract/src/bin/schema.rs index f84d1bb3..db8d7541 100644 --- a/examples/contracts/generic_contract/src/bin/schema.rs +++ b/examples/contracts/generic_contract/src/bin/schema.rs @@ -2,7 +2,7 @@ use cosmwasm_schema::write_api; #[cfg(not(tarpaulin_include))] fn main() { - use generic_contract::contract::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; + use generic_contract::contract::sv::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; use sylvia::types::SvCustomMsg; write_api! { diff --git a/examples/contracts/generic_contract/src/contract.rs b/examples/contracts/generic_contract/src/contract.rs index e253e06e..4fffc93e 100644 --- a/examples/contracts/generic_contract/src/contract.rs +++ b/examples/contracts/generic_contract/src/contract.rs @@ -79,7 +79,7 @@ where #[cfg(test)] mod tests { - use super::multitest_utils::CodeId; + use super::sv::multitest_utils::CodeId; use sylvia::multitest::App; use sylvia::types::SvCustomMsg; diff --git a/examples/contracts/generic_contract/src/custom_and_generic.rs b/examples/contracts/generic_contract/src/custom_and_generic.rs index 47a1929f..d1ce0b12 100644 --- a/examples/contracts/generic_contract/src/custom_and_generic.rs +++ b/examples/contracts/generic_contract/src/custom_and_generic.rs @@ -40,7 +40,7 @@ impl #[cfg(test)] mod tests { use super::sv::test_utils::CustomAndGeneric; - use crate::contract::multitest_utils::CodeId; + use crate::contract::sv::multitest_utils::CodeId; use sylvia::{multitest::App, types::SvCustomMsg}; #[test] diff --git a/examples/contracts/generic_contract/src/cw1.rs b/examples/contracts/generic_contract/src/cw1.rs index 8113c603..4c5c125c 100644 --- a/examples/contracts/generic_contract/src/cw1.rs +++ b/examples/contracts/generic_contract/src/cw1.rs @@ -36,7 +36,7 @@ impl Cw1 #[cfg(test)] mod tests { use super::sv::test_utils::Cw1; - use crate::contract::multitest_utils::CodeId; + use crate::contract::sv::multitest_utils::CodeId; use cosmwasm_std::{CosmosMsg, Empty}; use sylvia::{multitest::App, types::SvCustomMsg}; diff --git a/examples/contracts/generic_contract/src/generic.rs b/examples/contracts/generic_contract/src/generic.rs index d7b32c2c..8504c8ae 100644 --- a/examples/contracts/generic_contract/src/generic.rs +++ b/examples/contracts/generic_contract/src/generic.rs @@ -44,7 +44,7 @@ impl #[cfg(test)] mod tests { use super::sv::test_utils::Generic; - use crate::contract::multitest_utils::CodeId; + use crate::contract::sv::multitest_utils::CodeId; use cosmwasm_std::CosmosMsg; use sylvia::multitest::App; use sylvia::types::SvCustomMsg; diff --git a/examples/contracts/generic_iface_on_contract/src/bin/schema.rs b/examples/contracts/generic_iface_on_contract/src/bin/schema.rs index 8a7c48e5..03983dc6 100644 --- a/examples/contracts/generic_iface_on_contract/src/bin/schema.rs +++ b/examples/contracts/generic_iface_on_contract/src/bin/schema.rs @@ -2,7 +2,9 @@ use cosmwasm_schema::write_api; #[cfg(not(tarpaulin_include))] fn main() { - use generic_iface_on_contract::contract::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; + use generic_iface_on_contract::contract::sv::{ + ContractExecMsg, ContractQueryMsg, InstantiateMsg, + }; write_api! { instantiate: InstantiateMsg, diff --git a/examples/contracts/generic_iface_on_contract/src/contract.rs b/examples/contracts/generic_iface_on_contract/src/contract.rs index 2d0adc49..0a94398b 100644 --- a/examples/contracts/generic_iface_on_contract/src/contract.rs +++ b/examples/contracts/generic_iface_on_contract/src/contract.rs @@ -35,7 +35,7 @@ mod tests { fn mt_helpers() { let _ = NonGenericContract::new(); let app = App::>::custom(|_, _, _| {}); - let code_id = super::multitest_utils::CodeId::store_code(&app); + let code_id = super::sv::multitest_utils::CodeId::store_code(&app); let owner = "owner"; diff --git a/sylvia-derive/src/input.rs b/sylvia-derive/src/input.rs index 11afc04a..edd55cbf 100644 --- a/sylvia-derive/src/input.rs +++ b/sylvia-derive/src/input.rs @@ -207,15 +207,19 @@ impl<'a> ImplInput<'a> { #[cfg(not(tarpaulin_include))] { quote! { - #messages + pub mod sv { + use super::*; - #multitest_helpers + #messages - #remote + #multitest_helpers - #querier + #remote + + #querier - #(#querier_from_impl)* + #(#querier_from_impl)* + } } } } diff --git a/sylvia-derive/src/message.rs b/sylvia-derive/src/message.rs index 9c299103..141d1141 100644 --- a/sylvia-derive/src/message.rs +++ b/sylvia-derive/src/message.rs @@ -978,8 +978,8 @@ where .map(|module| quote! { #module ::sv::Querier }) .unwrap_or_else(|| quote! { sv::Querier }); let bound_querier = contract_module - .map(|module| quote! { #module ::BoundQuerier}) - .unwrap_or_else(|| quote! { BoundQuerier }); + .map(|module| quote! { #module ::sv::BoundQuerier}) + .unwrap_or_else(|| quote! { sv::BoundQuerier }); let querier = if !used_generics.is_empty() { quote! { #querier < #(#used_generics,)* > } @@ -1044,7 +1044,7 @@ where #[#sylvia ::cw_std::entry_point] pub fn #ep_name ( #params , - msg: #msg_name #bracketed_generics, + msg: sv:: #msg_name #bracketed_generics, ) -> Result<#resp_type, #error> { msg.dispatch(&#name ::new() , ( #values )).map_err(Into::into) } diff --git a/sylvia/tests/custom_msg.rs b/sylvia/tests/custom_msg.rs index da9aad5a..55e6693c 100644 --- a/sylvia/tests/custom_msg.rs +++ b/sylvia/tests/custom_msg.rs @@ -223,7 +223,7 @@ mod tests { fn test_custom() { let _ = MyContract::new(); let app = App::>::custom(|_, _, _| {}); - let code_id = crate::multitest_utils::CodeId::store_code(&app); + let code_id = crate::sv::multitest_utils::CodeId::store_code(&app); let owner = "owner"; diff --git a/sylvia/tests/custom_query.rs b/sylvia/tests/custom_query.rs index bf0a7cf0..00c33d34 100644 --- a/sylvia/tests/custom_query.rs +++ b/sylvia/tests/custom_query.rs @@ -254,7 +254,7 @@ mod tests { fn test_custom() { let _ = MyContract::new(); let app = App::>::custom(|_, _, _| {}); - let code_id = crate::multitest_utils::CodeId::store_code(&app); + let code_id = crate::sv::multitest_utils::CodeId::store_code(&app); let owner = "owner"; diff --git a/sylvia/tests/dispatching.rs b/sylvia/tests/dispatching.rs index 8a1a35b6..155354cf 100644 --- a/sylvia/tests/dispatching.rs +++ b/sylvia/tests/dispatching.rs @@ -1,12 +1,20 @@ use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; -use cosmwasm_std::{from_binary, Addr, Decimal, Response, StdError, StdResult}; -use interface::Interface; +use cosmwasm_std::{from_binary, Addr, Decimal, Response}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use std::cell::RefCell; -use std::collections::HashMap; -use sylvia::contract; -use sylvia::types::{ExecCtx, QueryCtx}; + +use crate::contract::Contract; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct EmptyQueryResponse {} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct QueryResponse { + coef: Decimal, + desc: String, +} mod interface { use cosmwasm_std::{Addr, Decimal, Response, StdError}; @@ -40,77 +48,83 @@ mod interface { } } -#[derive(Default)] -pub struct Contract { - execs: RefCell, - queries: RefCell, +mod impl_interface { + use cosmwasm_std::{Addr, Decimal, Response, StdError}; + use sylvia::types::{ExecCtx, QueryCtx}; - data: RefCell>, -} + use crate::{EmptyQueryResponse, QueryResponse}; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct EmptyQueryResponse {} + #[sylvia::contract(module = crate::contract)] + #[messages(crate::interface as Interface)] + impl crate::interface::Interface for crate::contract::Contract { + type Error = StdError; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct QueryResponse { - coef: Decimal, - desc: String, -} - -#[contract] -#[messages(interface as Interface)] -impl Interface for Contract { - type Error = StdError; + #[msg(exec)] + fn no_args_execution(&self, _: ExecCtx) -> Result { + *self.execs.borrow_mut() += 1; + Ok(Response::new()) + } - #[msg(exec)] - fn no_args_execution(&self, _: ExecCtx) -> Result { - *self.execs.borrow_mut() += 1; - Ok(Response::new()) - } + #[msg(exec)] + fn argumented_execution( + &self, + _: ExecCtx, + addr: Addr, + coef: Decimal, + desc: String, + ) -> Result { + *self.execs.borrow_mut() += 1; - #[msg(exec)] - fn argumented_execution( - &self, - _: ExecCtx, - addr: Addr, - coef: Decimal, - desc: String, - ) -> Result { - *self.execs.borrow_mut() += 1; - - self.data - .borrow_mut() - .insert(addr, QueryResponse { coef, desc }); - Ok(Response::new()) - } + self.data + .borrow_mut() + .insert(addr, QueryResponse { coef, desc }); + Ok(Response::new()) + } - #[msg(query)] - fn no_args_query(&self, _: QueryCtx) -> Result { - *self.queries.borrow_mut() += 1; - Ok(dbg!(EmptyQueryResponse {})) - } + #[msg(query)] + fn no_args_query(&self, _: QueryCtx) -> Result { + *self.queries.borrow_mut() += 1; + Ok(dbg!(EmptyQueryResponse {})) + } - #[msg(query)] - fn argumented_query(&self, _: QueryCtx, user: Addr) -> Result { - *self.queries.borrow_mut() += 1; - Ok(self.data.borrow().get(&user).unwrap().clone()) + #[msg(query)] + fn argumented_query(&self, _: QueryCtx, user: Addr) -> Result { + *self.queries.borrow_mut() += 1; + Ok(self.data.borrow().get(&user).unwrap().clone()) + } } } -#[allow(dead_code)] -#[cfg(not(tarpaulin_include))] -#[contract] -#[messages(interface as Interface)] -impl Contract { - fn new() -> Self { - Self::default() +mod contract { + use std::{cell::RefCell, collections::HashMap}; + + use cosmwasm_std::{Addr, Response, StdResult}; + use sylvia::types::ExecCtx; + use sylvia_derive::contract; + + use crate::QueryResponse; + + #[derive(Default)] + pub struct Contract { + pub(crate) execs: RefCell, + pub(crate) queries: RefCell, + + pub(crate) data: RefCell>, } - #[msg(instantiate)] - fn instanciate(&self, _: ExecCtx) -> StdResult { - Ok(Response::new()) + #[allow(dead_code)] + #[cfg(not(tarpaulin_include))] + #[contract] + #[messages(crate::interface as Interface)] + impl Contract { + fn new() -> Self { + Self::default() + } + + #[msg(instantiate)] + fn instanciate(&self, _: ExecCtx) -> StdResult { + Ok(Response::new()) + } } } diff --git a/sylvia/tests/entry_points.rs b/sylvia/tests/entry_points.rs index d7bbb2e4..951dfee6 100644 --- a/sylvia/tests/entry_points.rs +++ b/sylvia/tests/entry_points.rs @@ -1,4 +1,4 @@ -use contract::ContractExecMsg; +use contract::sv::ContractExecMsg; use cosmwasm_schema::cw_serde; use cosmwasm_std::Coin; use cw_storage_plus::Item; @@ -145,8 +145,8 @@ mod tests { use cw_multi_test::Executor; use sylvia::multitest::App; - use crate::contract::multitest_utils::CodeId; - use crate::contract::{ContractExecMsg, ExecMsg}; + use crate::contract::sv::multitest_utils::CodeId; + use crate::contract::sv::{ContractExecMsg, ExecMsg}; use crate::exec::{CustomExecMsg, UserExecMsg}; use crate::SudoMsg; diff --git a/sylvia/tests/messages_generation.rs b/sylvia/tests/messages_generation.rs index 023c71a5..6fe0b947 100644 --- a/sylvia/tests/messages_generation.rs +++ b/sylvia/tests/messages_generation.rs @@ -137,28 +137,28 @@ fn interface_messages_constructible() { #[test] fn contract_messages_constructible() { - let no_args_exec = contract::ExecMsg::NoArgsExecution {}; - let _argumented_exec = contract::ExecMsg::ArgumentedExecution { + let no_args_exec = contract::sv::ExecMsg::NoArgsExecution {}; + let _argumented_exec = contract::sv::ExecMsg::ArgumentedExecution { _addr: Addr::unchecked("owner"), _coef: Decimal::percent(10), _desc: "Some description".to_owned(), }; - let no_args_query = contract::QueryMsg::NoArgsQuery {}; - let _argumented_query = contract::QueryMsg::ArgumentedQuery { + let no_args_query = contract::sv::QueryMsg::NoArgsQuery {}; + let _argumented_query = contract::sv::QueryMsg::ArgumentedQuery { _user: Addr::unchecked("owner"), }; - let _ = contract::InstantiateMsg {}; - let _ = contract::MigrateMsg {}; + let _ = contract::sv::InstantiateMsg {}; + let _ = contract::sv::MigrateMsg {}; // Ensure no extra variants are generated match no_args_exec { - contract::ExecMsg::NoArgsExecution {} => (), - contract::ExecMsg::ArgumentedExecution { .. } => (), + contract::sv::ExecMsg::NoArgsExecution {} => (), + contract::sv::ExecMsg::ArgumentedExecution { .. } => (), } match no_args_query { - contract::QueryMsg::NoArgsQuery {} => (), - contract::QueryMsg::ArgumentedQuery { .. } => (), + contract::sv::QueryMsg::NoArgsQuery {} => (), + contract::sv::QueryMsg::ArgumentedQuery { .. } => (), } } diff --git a/sylvia/tests/querier.rs b/sylvia/tests/querier.rs index 8720d794..9a78ed3b 100644 --- a/sylvia/tests/querier.rs +++ b/sylvia/tests/querier.rs @@ -79,7 +79,7 @@ pub mod impl_counter { fn decrease_by_count(&self, ctx: ExecCtx) -> StdResult { let remote = self.remote.load(ctx.deps.storage)?; let other_count = - crate::counter::sv::BoundQuerier::borrowed(&remote.0, &ctx.deps.querier) + crate::counter::sv::BoundQuerier::borrowed(remote.as_ref(), &ctx.deps.querier) .count()? .count; self.count.update(ctx.deps.storage, |count| { @@ -94,7 +94,7 @@ pub mod impl_counter { pub struct CounterContract<'a> { pub count: Item<'static, u64>, - pub remote: Item<'static, Remote<'a>>, + pub remote: Item<'static, sv::Remote<'a>>, } #[contract] @@ -112,7 +112,7 @@ impl CounterContract<'_> { fn instantiate(&self, ctx: InstantiateCtx, remote_addr: Addr) -> StdResult { self.count.save(ctx.deps.storage, &0)?; self.remote - .save(ctx.deps.storage, &Remote::new(remote_addr))?; + .save(ctx.deps.storage, &sv::Remote::new(remote_addr))?; Ok(Response::new()) } } @@ -125,7 +125,7 @@ mod tests { use sylvia::multitest::App; use crate::impl_counter::sv::test_utils::Counter; - use crate::multitest_utils::CodeId; + use crate::sv::multitest_utils::CodeId; #[test] fn querier_generation() { @@ -136,12 +136,12 @@ mod tests { // Remote generation let remote = super::counter::sv::Remote::new(remote_addr.clone()); let _: super::counter::sv::BoundQuerier<_> = remote.querier(&querier_wrapper); - let remote = super::Remote::new(remote_addr.clone()); - let _: super::BoundQuerier<_> = remote.querier(&querier_wrapper); + let remote = super::sv::Remote::new(remote_addr.clone()); + let _: super::sv::BoundQuerier<_> = remote.querier(&querier_wrapper); // Querier generation let _ = super::counter::sv::BoundQuerier::borrowed(&remote_addr, &querier_wrapper); - let querier = super::BoundQuerier::borrowed(&remote_addr, &querier_wrapper); + let querier = super::sv::BoundQuerier::borrowed(&remote_addr, &querier_wrapper); let _ = super::counter::sv::BoundQuerier::from(&querier); } diff --git a/sylvia/tests/query_returns.rs b/sylvia/tests/query_returns.rs index 9bd63ce9..b85dd6a1 100644 --- a/sylvia/tests/query_returns.rs +++ b/sylvia/tests/query_returns.rs @@ -69,7 +69,7 @@ mod tests { #[test] fn generate_contract_query() { - let _ = QueryMsg::ContractQuery { + let _ = sv::QueryMsg::ContractQuery { _name: "some_name".to_owned(), }; } diff --git a/sylvia/tests/remote.rs b/sylvia/tests/remote.rs index 0628e1a9..4c937085 100644 --- a/sylvia/tests/remote.rs +++ b/sylvia/tests/remote.rs @@ -37,7 +37,7 @@ impl SomeContract { #[cw_serde] #[allow(dead_code)] struct CustomStorage { - remote: crate::Remote<'static>, + remote: crate::sv::Remote<'static>, } #[cfg(test)] @@ -54,9 +54,9 @@ mod tests { let _ = some_interface::sv::Remote::borrowed(&addr); // contract - let new_remote = crate::Remote::new(Addr::unchecked("some_contract")); + let new_remote = crate::sv::Remote::new(Addr::unchecked("some_contract")); let addr = Addr::unchecked("some_contract"); - let borrowed_remote = crate::Remote::borrowed(&addr); + let borrowed_remote = crate::sv::Remote::borrowed(&addr); assert_eq!(&Addr::unchecked("some_contract"), borrowed_remote.as_ref()); let _ = some_interface::sv::Remote::from(&borrowed_remote); diff --git a/sylvia/tests/replies.rs b/sylvia/tests/replies.rs index a7bf5021..979db3cc 100644 --- a/sylvia/tests/replies.rs +++ b/sylvia/tests/replies.rs @@ -55,7 +55,7 @@ mod reply_contract { #[msg(exec)] fn poke(&self, _ctx: ExecCtx, noop: String) -> StdResult { - let msg = noop_contract::ExecMsg::Noop {}; + let msg = noop_contract::sv::ExecMsg::Noop {}; let msg = WasmMsg::Execute { contract_addr: noop, msg: to_binary(&msg)?, @@ -93,16 +93,16 @@ fn entry_point_generation() { assert_eq!(data, "data"); } -#[cfg(feature = "mt")] +#[cfg(all(test, feature = "mt"))] #[test] fn mt_helper_generation() { let app = sylvia::multitest::App::default(); let owner = "owner"; - let noop_contract_code = noop_contract::multitest_utils::CodeId::store_code(&app); + let noop_contract_code = noop_contract::sv::multitest_utils::CodeId::store_code(&app); let noop_contract = noop_contract_code.instantiate().call(owner).unwrap(); - let reply_contract_code = reply_contract::multitest_utils::CodeId::store_code(&app); + let reply_contract_code = reply_contract::sv::multitest_utils::CodeId::store_code(&app); let reply_contract = reply_contract_code.instantiate().call(owner).unwrap(); let resp = reply_contract