From 423e03c2b50278b0944198ded5d54982fc7e8810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Wed, 25 Oct 2023 14:27:12 +0200 Subject: [PATCH] feat: Wrap impl types in `sv` module --- .../cw1-subkeys/src/multitest/tests.rs | 2 +- .../contracts/cw1-whitelist/src/multitest.rs | 4 +-- .../src/multitest/allowances_tests.rs | 2 +- .../cw20-base/src/multitest/base_tests.rs | 2 +- .../src/multitest/marketing_tests.rs | 2 +- .../cw20-base/src/multitest/minting_tests.rs | 2 +- .../cw20-base/src/multitest/receiver.rs | 36 +++++++++++-------- .../src/custom_and_generic.rs | 2 +- .../contracts/generic_contract/src/cw1.rs | 2 +- .../contracts/generic_contract/src/generic.rs | 2 +- .../generic_iface_on_contract/src/contract.rs | 6 ++-- sylvia-derive/src/input.rs | 8 +++-- sylvia/examples/basic.rs | 2 +- sylvia/tests/custom_msg.rs | 16 ++++----- sylvia/tests/custom_query.rs | 16 ++++----- sylvia/tests/querier.rs | 23 ++++++++---- 16 files changed, 73 insertions(+), 54 deletions(-) diff --git a/examples/contracts/cw1-subkeys/src/multitest/tests.rs b/examples/contracts/cw1-subkeys/src/multitest/tests.rs index e0d6c61b..71cc20d0 100644 --- a/examples/contracts/cw1-subkeys/src/multitest/tests.rs +++ b/examples/contracts/cw1-subkeys/src/multitest/tests.rs @@ -370,7 +370,7 @@ mod permissions { } mod cw1_execute { - use crate::cw1::test_utils::Cw1; + use crate::cw1::sv::test_utils::Cw1; use cosmwasm_std::BankMsg; use super::*; diff --git a/examples/contracts/cw1-whitelist/src/multitest.rs b/examples/contracts/cw1-whitelist/src/multitest.rs index c45e7c04..812f982d 100644 --- a/examples/contracts/cw1-whitelist/src/multitest.rs +++ b/examples/contracts/cw1-whitelist/src/multitest.rs @@ -4,9 +4,9 @@ mod test { use whitelist::responses::AdminListResponse; use crate::contract::multitest_utils::CodeId; - use crate::cw1::test_utils::Cw1; + use crate::cw1::sv::test_utils::Cw1; use crate::error::ContractError; - use crate::whitelist::test_utils::Whitelist; + use crate::whitelist::sv::test_utils::Whitelist; use assert_matches::assert_matches; use sylvia::multitest::App; diff --git a/examples/contracts/cw20-base/src/multitest/allowances_tests.rs b/examples/contracts/cw20-base/src/multitest/allowances_tests.rs index 005b0105..22c2735d 100644 --- a/examples/contracts/cw20-base/src/multitest/allowances_tests.rs +++ b/examples/contracts/cw20-base/src/multitest/allowances_tests.rs @@ -7,7 +7,7 @@ use cw_multi_test::next_block; use cw_utils::Expiration; use sylvia::multitest::App; -use crate::allowances::test_utils::Cw20Allowances; +use crate::allowances::sv::test_utils::Cw20Allowances; use crate::contract::multitest_utils::CodeId; use crate::contract::InstantiateMsgData; use crate::error::ContractError; diff --git a/examples/contracts/cw20-base/src/multitest/base_tests.rs b/examples/contracts/cw20-base/src/multitest/base_tests.rs index 30eca4e6..7fdd3821 100644 --- a/examples/contracts/cw20-base/src/multitest/base_tests.rs +++ b/examples/contracts/cw20-base/src/multitest/base_tests.rs @@ -3,7 +3,7 @@ use cw20_allowances::responses::{AllAllowancesResponse, SpenderAllowanceInfo}; use cw_utils::Expiration; use sylvia::multitest::App; -use crate::allowances::test_utils::Cw20Allowances; +use crate::allowances::sv::test_utils::Cw20Allowances; use crate::contract::multitest_utils::CodeId; use crate::contract::InstantiateMsgData; use crate::error::ContractError; diff --git a/examples/contracts/cw20-base/src/multitest/marketing_tests.rs b/examples/contracts/cw20-base/src/multitest/marketing_tests.rs index a32fb8d8..d8da5c10 100644 --- a/examples/contracts/cw20-base/src/multitest/marketing_tests.rs +++ b/examples/contracts/cw20-base/src/multitest/marketing_tests.rs @@ -6,7 +6,7 @@ use sylvia::multitest::App; use crate::contract::multitest_utils::CodeId; use crate::contract::{InstantiateMarketingInfo, InstantiateMsgData}; use crate::error::ContractError; -use crate::marketing::test_utils::Cw20Marketing; +use crate::marketing::sv::test_utils::Cw20Marketing; const PNG_HEADER: [u8; 8] = [0x89, b'P', b'N', b'G', 0x0d, 0x0a, 0x1a, 0x0a]; diff --git a/examples/contracts/cw20-base/src/multitest/minting_tests.rs b/examples/contracts/cw20-base/src/multitest/minting_tests.rs index 9ae818d8..72bdad07 100644 --- a/examples/contracts/cw20-base/src/multitest/minting_tests.rs +++ b/examples/contracts/cw20-base/src/multitest/minting_tests.rs @@ -5,7 +5,7 @@ use sylvia::multitest::App; use crate::contract::multitest_utils::CodeId; use crate::contract::InstantiateMsgData; use crate::error::ContractError; -use crate::minting::test_utils::Cw20Minting; +use crate::minting::sv::test_utils::Cw20Minting; use crate::responses::{Cw20Coin, TokenInfoResponse}; #[test] diff --git a/examples/contracts/cw20-base/src/multitest/receiver.rs b/examples/contracts/cw20-base/src/multitest/receiver.rs index b3494612..3a127237 100644 --- a/examples/contracts/cw20-base/src/multitest/receiver.rs +++ b/examples/contracts/cw20-base/src/multitest/receiver.rs @@ -1,8 +1,6 @@ use cosmwasm_std::{Binary, Response, StdError, Uint128}; use sylvia::types::ExecCtx; -use sylvia::{contract, interface, schemars}; - -use super::receiver_contract::ReceiverContract; +use sylvia::{interface, schemars}; #[interface] pub trait Receiver { @@ -18,18 +16,26 @@ pub trait Receiver { ) -> Result; } -#[contract(module=crate::multitest::receiver_contract)] -impl Receiver for ReceiverContract { - type Error = StdError; +pub mod impl_receiver { + use crate::multitest::receiver_contract::ReceiverContract; + use cosmwasm_std::{Response, StdError}; + use sylvia::contract; + use sylvia::types::ExecCtx; - #[msg(exec)] - fn receive( - &self, - _ctx: ExecCtx, - _sender: String, - _amount: cosmwasm_std::Uint128, - _msg: cosmwasm_std::Binary, - ) -> Result { - Ok(Response::default()) + #[contract(module=crate::multitest::receiver_contract)] + #[messages(crate::multitest::receiver as Receiver)] + impl super::Receiver for ReceiverContract { + type Error = StdError; + + #[msg(exec)] + fn receive( + &self, + _ctx: ExecCtx, + _sender: String, + _amount: cosmwasm_std::Uint128, + _msg: cosmwasm_std::Binary, + ) -> Result { + Ok(Response::default()) + } } } diff --git a/examples/contracts/generic_contract/src/custom_and_generic.rs b/examples/contracts/generic_contract/src/custom_and_generic.rs index 98926abc..47a1929f 100644 --- a/examples/contracts/generic_contract/src/custom_and_generic.rs +++ b/examples/contracts/generic_contract/src/custom_and_generic.rs @@ -39,7 +39,7 @@ impl #[cfg(test)] mod tests { - use super::test_utils::CustomAndGeneric; + use super::sv::test_utils::CustomAndGeneric; use crate::contract::multitest_utils::CodeId; use sylvia::{multitest::App, types::SvCustomMsg}; diff --git a/examples/contracts/generic_contract/src/cw1.rs b/examples/contracts/generic_contract/src/cw1.rs index 48bd0870..8113c603 100644 --- a/examples/contracts/generic_contract/src/cw1.rs +++ b/examples/contracts/generic_contract/src/cw1.rs @@ -35,7 +35,7 @@ impl Cw1 #[cfg(test)] mod tests { - use super::test_utils::Cw1; + use super::sv::test_utils::Cw1; use crate::contract::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 aef1ac96..d7b32c2c 100644 --- a/examples/contracts/generic_contract/src/generic.rs +++ b/examples/contracts/generic_contract/src/generic.rs @@ -43,7 +43,7 @@ impl #[cfg(test)] mod tests { - use super::test_utils::Generic; + use super::sv::test_utils::Generic; use crate::contract::multitest_utils::CodeId; use cosmwasm_std::CosmosMsg; use sylvia::multitest::App; diff --git a/examples/contracts/generic_iface_on_contract/src/contract.rs b/examples/contracts/generic_iface_on_contract/src/contract.rs index f35d0d69..2d0adc49 100644 --- a/examples/contracts/generic_iface_on_contract/src/contract.rs +++ b/examples/contracts/generic_iface_on_contract/src/contract.rs @@ -27,9 +27,9 @@ mod tests { use sylvia::{multitest::App, types::SvCustomMsg}; use super::NonGenericContract; - use crate::custom_and_generic::test_utils::CustomAndGeneric; - use crate::cw1::test_utils::Cw1; - use crate::generic::test_utils::Generic; + use crate::custom_and_generic::sv::test_utils::CustomAndGeneric; + use crate::cw1::sv::test_utils::Cw1; + use crate::generic::sv::test_utils::Generic; #[test] fn mt_helpers() { diff --git a/sylvia-derive/src/input.rs b/sylvia-derive/src/input.rs index 7e0ae593..11afc04a 100644 --- a/sylvia-derive/src/input.rs +++ b/sylvia-derive/src/input.rs @@ -178,9 +178,13 @@ impl<'a> ImplInput<'a> { #[cfg(not(tarpaulin_include))] quote! { - #multitest_helpers + pub mod sv { + use super::*; - #querier_bound_for_impl + #multitest_helpers + + #querier_bound_for_impl + } } } diff --git a/sylvia/examples/basic.rs b/sylvia/examples/basic.rs index 7feb0b98..404aa660 100644 --- a/sylvia/examples/basic.rs +++ b/sylvia/examples/basic.rs @@ -70,7 +70,7 @@ mod impl_group { use crate::{GroupContract, MemberResp}; - #[contract(module=super)] + #[contract(module=crate)] #[messages(crate::group as Group)] impl crate::group::Group for GroupContract { type Error = Error; diff --git a/sylvia/tests/custom_msg.rs b/sylvia/tests/custom_msg.rs index 2896b593..da9aad5a 100644 --- a/sylvia/tests/custom_msg.rs +++ b/sylvia/tests/custom_msg.rs @@ -49,7 +49,7 @@ mod impl_some_interface { use crate::some_interface::SomeInterface; use crate::{MyMsg, SomeResponse}; - #[contract(module=super)] + #[contract(module=crate)] #[messages(crate::some_interface as SomeInterface)] #[sv::custom(msg=MyMsg)] impl SomeInterface for crate::MyContract { @@ -92,7 +92,7 @@ mod impl_interface { use sylvia::contract; use sylvia::types::ExecCtx; - #[contract(module=super)] + #[contract(module=crate)] #[messages(crate::interface as Interface)] #[sv::custom(msg=MyMsg)] impl Interface for crate::MyContract { @@ -126,7 +126,7 @@ mod impl_other_interface { use sylvia::contract; use sylvia::types::ExecCtx; - #[contract(module=super)] + #[contract(module=crate)] #[messages(crate::other_interface as OtherInterface)] #[sv::custom(msg=crate::MyMsg)] impl OtherInterface for crate::MyContract { @@ -161,7 +161,7 @@ mod impl_associated_interface { use sylvia::contract; use sylvia::types::ExecCtx; - #[contract(module=super)] + #[contract(module=crate)] #[messages(crate::associated_interface as AssociatedInterface)] #[sv::custom(msg=MyMsg)] impl AssociatedInterface for crate::MyContract { @@ -211,10 +211,10 @@ impl MyContract { #[cfg(all(test, feature = "mt"))] mod tests { - use crate::impl_associated_interface::test_utils::AssociatedInterface; - use crate::impl_interface::test_utils::Interface; - use crate::impl_other_interface::test_utils::OtherInterface; - use crate::impl_some_interface::test_utils::SomeInterface; + use crate::impl_associated_interface::sv::test_utils::AssociatedInterface; + use crate::impl_interface::sv::test_utils::Interface; + use crate::impl_other_interface::sv::test_utils::OtherInterface; + use crate::impl_some_interface::sv::test_utils::SomeInterface; use crate::MyContract; use crate::MyMsg; use sylvia::multitest::App; diff --git a/sylvia/tests/custom_query.rs b/sylvia/tests/custom_query.rs index 8405f873..bf0a7cf0 100644 --- a/sylvia/tests/custom_query.rs +++ b/sylvia/tests/custom_query.rs @@ -48,7 +48,7 @@ mod impl_interface { use crate::{MyQuery, OtherQuery, SomeResponse}; - #[contract(module=super)] + #[contract(module=crate)] #[messages(crate::interface as Interface)] #[sv::custom(query=MyQuery)] impl crate::interface::Interface for crate::MyContract { @@ -96,7 +96,7 @@ mod impl_some_interface { use crate::{MyQuery, SomeResponse}; - #[contract(module=super)] + #[contract(module=crate)] #[messages(crate::some_interface as SomeInterface)] #[sv::custom(query=MyQuery)] impl super::some_interface::SomeInterface for crate::MyContract { @@ -142,7 +142,7 @@ mod impl_associated_type_interface { use sylvia::types::{ExecCtx, QueryCtx}; use sylvia_derive::contract; - #[contract(module=super)] + #[contract(module=crate)] #[messages(crate::associated_type_interface as AssociatedTypeInterface)] impl AssociatedTypeInterface for crate::MyContract { type Error = StdError; @@ -187,7 +187,7 @@ mod impl_default_query_interface { use sylvia::types::{ExecCtx, QueryCtx}; use sylvia_derive::contract; - #[contract(module=super)] + #[contract(module=crate)] #[messages(crate::default_query_interface as DefaultQueryInterface)] #[sv::custom(query=MyQuery)] impl DefaultQueryInterface for crate::MyContract { @@ -241,10 +241,10 @@ impl MyContract { #[cfg(all(test, feature = "mt"))] mod tests { - use crate::impl_associated_type_interface::test_utils::AssociatedTypeInterface; - use crate::impl_default_query_interface::test_utils::DefaultQueryInterface; - use crate::impl_interface::test_utils::Interface; - use crate::impl_some_interface::test_utils::SomeInterface; + use crate::impl_associated_type_interface::sv::test_utils::AssociatedTypeInterface; + use crate::impl_default_query_interface::sv::test_utils::DefaultQueryInterface; + use crate::impl_interface::sv::test_utils::Interface; + use crate::impl_some_interface::sv::test_utils::SomeInterface; use crate::{MyContract, MyQuery}; use cosmwasm_std::Empty; diff --git a/sylvia/tests/querier.rs b/sylvia/tests/querier.rs index b5c32ed3..8720d794 100644 --- a/sylvia/tests/querier.rs +++ b/sylvia/tests/querier.rs @@ -14,9 +14,8 @@ pub struct CountResponse { pub mod counter { use cosmwasm_std::{Response, StdError, StdResult}; - use sv::Querier; + use sylvia::interface; use sylvia::types::{ExecCtx, QueryCtx}; - use sylvia::{contract, interface}; use crate::CountResponse; @@ -36,8 +35,17 @@ pub mod counter { #[msg(exec)] fn decrease_by_count(&self, ctx: ExecCtx) -> StdResult; } +} - #[contract(module=super)] +pub mod impl_counter { + use crate::counter::sv::Querier; + use crate::counter::Counter; + use crate::CountResponse; + use cosmwasm_std::{Response, StdError, StdResult}; + use sylvia::contract; + use sylvia::types::{ExecCtx, QueryCtx}; + + #[contract(module=crate)] #[messages(crate::counter as Counter)] impl Counter for super::CounterContract<'_> { type Error = StdError; @@ -70,9 +78,10 @@ pub mod counter { #[msg(exec)] fn decrease_by_count(&self, ctx: ExecCtx) -> StdResult { let remote = self.remote.load(ctx.deps.storage)?; - let other_count = sv::BoundQuerier::borrowed(&remote.0, &ctx.deps.querier) - .count()? - .count; + let other_count = + crate::counter::sv::BoundQuerier::borrowed(&remote.0, &ctx.deps.querier) + .count()? + .count; self.count.update(ctx.deps.storage, |count| { let count = count.saturating_sub(other_count); Ok::<_, StdError>(count) @@ -115,7 +124,7 @@ mod tests { use cosmwasm_std::{Addr, Empty, QuerierWrapper}; use sylvia::multitest::App; - use crate::counter::test_utils::Counter; + use crate::impl_counter::sv::test_utils::Counter; use crate::multitest_utils::CodeId; #[test]