Skip to content

Commit

Permalink
feat: Wrap impl types in sv module
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Nov 13, 2023
1 parent eb4dfcf commit 423e03c
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 54 deletions.
2 changes: 1 addition & 1 deletion examples/contracts/cw1-subkeys/src/multitest/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
4 changes: 2 additions & 2 deletions examples/contracts/cw1-whitelist/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw20-base/src/multitest/base_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
36 changes: 21 additions & 15 deletions examples/contracts/cw20-base/src/multitest/receiver.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,18 +16,26 @@ pub trait Receiver {
) -> Result<Response, Self::Error>;
}

#[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<Response, Self::Error> {
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<Response, Self::Error> {
Ok(Response::default())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<InstantiateParam, ExecParam, QueryParam, MigrateParam, RetType>

#[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};

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 @@ -35,7 +35,7 @@ impl<InstantiateParam, ExecParam, QueryParam, MigrateParam, RetType> 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};
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/generic_contract/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<InstantiateParam, ExecParam, QueryParam, MigrateParam, RetType>

#[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;
Expand Down
6 changes: 3 additions & 3 deletions examples/contracts/generic_iface_on_contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 6 additions & 2 deletions sylvia-derive/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion sylvia/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions sylvia/tests/custom_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions sylvia/tests/custom_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 16 additions & 7 deletions sylvia/tests/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,8 +35,17 @@ pub mod counter {
#[msg(exec)]
fn decrease_by_count(&self, ctx: ExecCtx) -> StdResult<Response>;
}
}

#[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;
Expand Down Expand Up @@ -70,9 +78,10 @@ pub mod counter {
#[msg(exec)]
fn decrease_by_count(&self, ctx: ExecCtx) -> StdResult<Response> {
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)
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 423e03c

Please sign in to comment.