Skip to content

Commit

Permalink
Merge pull request #10 from CosmWasm/rename_mt_modules
Browse files Browse the repository at this point in the history
Rename mt modules
  • Loading branch information
jawoznia authored Mar 13, 2024
2 parents 8b792fe + 319a805 commit 01e373f
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 168 deletions.
68 changes: 34 additions & 34 deletions src/advanced/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ use sylvia::types::{ExecCtx, QueryCtx};
pub trait SvCustom {
type Error: From<StdError>;

#[msg(exec)]
#[sv::msg(exec)]
fn sv_custom_exec(
&self,
ctx: ExecCtx<ExternalQuery>,
) -> Result<Response<ExternalMsg>, Self::Error>;

#[msg(query)]
#[sv::msg(query)]
fn sv_custom_query(&self, ctx: QueryCtx<ExternalQuery>) -> Result<String, Self::Error>;
}
```
Expand All @@ -77,11 +77,11 @@ pub trait Associated {
type ExecC: CustomMsg;
type QueryC: CustomQuery;

#[msg(exec)]
#[sv::msg(exec)]
fn associated_exec(&self, ctx: ExecCtx<Self::QueryC>)
-> Result<Response<Self::ExecC>, Self::Error>;

#[msg(query)]
#[sv::msg(query)]
fn associated_query(&self, ctx: QueryCtx<Self::QueryC>) -> Result<String, Self::Error>;
}
```
Expand Down Expand Up @@ -111,7 +111,7 @@ impl CustomContract {
Self
}

#[msg(instantiate)]
#[sv::msg(instantiate)]
pub fn instantiate(
&self,
_ctx: InstantiateCtx<ExternalQuery>,
Expand Down Expand Up @@ -141,20 +141,20 @@ use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};

#[contract(module=crate::contract)]
#[messages(crate::sv_custom as SvCustom)]
#[sv::messages(crate::sv_custom as SvCustom)]
#[sv::custom(msg=ExternalMsg, query=ExternalQuery)]
impl SvCustom for CustomContract {
type Error = StdError;

#[msg(exec)]
#[sv::msg(exec)]
fn sv_custom_exec(
&self,
_ctx: ExecCtx<ExternalQuery>,
) -> Result<Response<ExternalMsg>, Self::Error> {
Ok(Response::new())
}

#[msg(query)]
#[sv::msg(query)]
fn sv_custom_query(&self, _ctx: QueryCtx<ExternalQuery>) -> Result<String, Self::Error> {
Ok(String::default())
}
Expand All @@ -175,21 +175,21 @@ use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};

#[contract(module=crate::contract)]
#[messages(crate::associated as Associated)]
#[sv::messages(crate::associated as Associated)]
impl Associated for CustomContract {
type Error = StdError;
type ExecC = ExternalMsg;
type QueryC = ExternalQuery;

#[msg(exec)]
#[sv::msg(exec)]
fn associated_exec(
&self,
_ctx: ExecCtx<Self::QueryC>,
) -> Result<Response<Self::ExecC>, Self::Error> {
Ok(Response::new())
}

#[msg(query)]
#[sv::msg(query)]
fn associated_query(&self, _ctx: QueryCtx<Self::QueryC>) -> Result<String, Self::Error> {
Ok(String::default())
}
Expand All @@ -212,15 +212,15 @@ use crate::messages::{ExternalMsg, ExternalQuery};
pub struct CustomContract;

#[contract]
#[messages(crate::sv_custom as SvCustomInterface)]
#[messages(crate::associated as AssociatedInterface)]
#[sv::messages(crate::sv_custom as SvCustomInterface)]
#[sv::messages(crate::associated as AssociatedInterface)]
#[sv::custom(msg=ExternalMsg, query=ExternalQuery)]
impl CustomContract {
pub const fn new() -> Self {
Self
}

#[msg(instantiate)]
#[sv::msg(instantiate)]
pub fn instantiate(
&self,
_ctx: InstantiateCtx<ExternalQuery>,
Expand All @@ -244,10 +244,10 @@ use sylvia::types::{ExecCtx, QueryCtx};
pub trait NonCustom {
type Error: From<StdError>;

#[msg(exec)]
#[sv::msg(exec)]
fn non_custom_exec(&self, ctx: ExecCtx) -> Result<Response, Self::Error>;

#[msg(query)]
#[sv::msg(query)]
fn non_custom_query(&self, ctx: QueryCtx) -> Result<String, Self::Error>;
}

Expand All @@ -260,17 +260,17 @@ pub mod impl_non_custom {
use super::NonCustom;

#[contract(module=crate::contract)]
#[messages(crate::non_custom as NonCustom)]
#[sv::messages(crate::non_custom as NonCustom)]
#[sv::custom(msg=ExternalMsg, query=ExternalQuery)]
impl NonCustom for CustomContract {
type Error = StdError;

#[msg(exec)]
#[sv::msg(exec)]
fn non_custom_exec(&self, _ctx: ExecCtx) -> Result<Response, Self::Error> {
Ok(Response::new())
}

#[msg(query)]
#[sv::msg(query)]
fn non_custom_query(&self, _ctx: QueryCtx) -> Result<String, Self::Error> {
Ok(String::default())
}
Expand All @@ -294,16 +294,16 @@ use crate::messages::{ExternalMsg, ExternalQuery};
pub struct CustomContract;

#[contract]
#[messages(crate::sv_custom as SvCustomInterface)]
#[messages(crate::associated as AssociatedInterface)]
#[messages(crate::non_custom as NonCustom: custom(msg query))]
#[sv::messages(crate::sv_custom as SvCustomInterface)]
#[sv::messages(crate::associated as AssociatedInterface)]
#[sv::messages(crate::non_custom as NonCustom: custom(msg query))]
#[sv::custom(msg=ExternalMsg, query=ExternalQuery)]
impl CustomContract {
pub const fn new() -> Self {
Self
}

#[msg(instantiate)]
#[sv::msg(instantiate)]
pub fn instantiate(
&self,
_ctx: InstantiateCtx<ExternalQuery>,
Expand Down Expand Up @@ -334,31 +334,31 @@ pub struct CustomContract;

#[cfg_attr(not(feature = "library"), entry_points)]
#[contract]
#[messages(crate::sv_custom as SvCustomInterface)]
#[messages(crate::associated as AssociatedInterface)]
#[messages(crate::non_custom as NonCustom: custom(msg query))]
#[sv::messages(crate::sv_custom as SvCustomInterface)]
#[sv::messages(crate::associated as AssociatedInterface)]
#[sv::messages(crate::non_custom as NonCustom: custom(msg query))]
#[sv::custom(msg=ExternalMsg, query=ExternalQuery)]
impl CustomContract {
pub const fn new() -> Self {
Self
}

#[msg(instantiate)]
#[sv::msg(instantiate)]
pub fn instantiate(
&self,
_ctx: InstantiateCtx<ExternalQuery>,
) -> StdResult<Response<ExternalMsg>> {
Ok(Response::new())
}

#[msg(exec)]
#[sv::msg(exec)]
pub fn poke(&self, _ctx: ExecCtx<ExternalQuery>) -> StdResult<Response<ExternalMsg>> {
let msg = CosmosMsg::Custom(ExternalMsg::Poke {});
let resp = Response::default().add_message(msg);
Ok(resp)
}

#[msg(query)]
#[sv::msg(query)]
pub fn is_poked(&self, ctx: QueryCtx<ExternalQuery>) -> StdResult<bool> {
let resp = ctx
.deps
Expand Down Expand Up @@ -392,7 +392,7 @@ use std::fmt::Debug;
use crate::messages::{ExternalMsg, ExternalQuery};

pub struct CustomModule {
pub is_poked: Item<'static, bool>,
pub is_poked: Item<bool>,
}

impl CustomModule {
Expand Down Expand Up @@ -478,12 +478,12 @@ Running `poke` on our contract will send the `ExternalMsg::Poke`, which `App` wi
```rust
use sylvia::multitest::App;

use crate::contract::multitest_utils::CodeId;
use crate::contract::sv::mt::{CodeId, CounterContractProxy};
use crate::multitest::custom_module::CustomModule;

#[test]
fn test_custom() {
let owner = "owner";
let owner = "owner".into_addr();

let mt_app = cw_multi_test::BasicAppBuilder::new_custom()
.with_custom(CustomModule::new())
Expand All @@ -495,9 +495,9 @@ fn test_custom() {

let code_id = CodeId::store_code(&app);

let contract = code_id.instantiate().call(owner).unwrap();
let contract = code_id.instantiate().call(&owner).unwrap();

contract.poke().call(owner).unwrap();
contract.poke().call(&owner).unwrap();

let count = contract.is_poked().unwrap();
assert!(count);
Expand Down
8 changes: 4 additions & 4 deletions src/advanced/generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ pub trait Associated {
type ExecParam: CustomMsg;
type QueryParam: CustomMsg;

#[msg(exec)]
#[sv::msg(exec)]
fn generic_exec(&self, ctx: ExecCtx, param: Self::ExecParam) -> StdResult<Response>;

#[msg(query)]
#[sv::msg(query)]
fn generic_query(&self, ctx: QueryCtx, param: Self::QueryParam) -> StdResult<String>;
}
```
Expand Down Expand Up @@ -92,7 +92,7 @@ impl NonGenericContract {
Self {}
}

#[msg(instantiate)]
#[sv::msg(instantiate)]
pub fn instantiate(&self, _ctx: InstantiateCtx) -> StdResult<Response> {
Ok(Response::new())
}
Expand Down Expand Up @@ -258,7 +258,7 @@ The only change is to pass the generics into the contract.
`src/generic_contract.rs`
```rust
#[contract]
#[messages(crate::associated<MyMsg, MyMsg> as Associated)]
#[sv::messages(crate::associated<MyMsg, MyMsg> as Associated)]
impl<DataType, InstantiateParam> GenericContract<DataType, InstantiateParam>
where
InstantiateParam: CustomMsg + 'static,
Expand Down
4 changes: 2 additions & 2 deletions src/basics/entry-points.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ impl CounterContract {
Self
}
#[msg(instantiate)]
#[sv::msg(instantiate)]
pub fn instantiate(&self, _ctx: InstantiateCtx) -> StdResult<Response> {
Ok(Response::default())
}
}
```

Note that **`#[entry_points]`** is added above the **`#[contract]`**.
It is because **`#[contract]`** removes attributes like **`#[msg(...)]`** on which both these macros rely.
It is because **`#[contract]`** removes attributes like **`#[sv::msg(...)]`** on which both these macros rely.

Always remember to place **`#[entry_points]`** first.

Expand Down
Loading

0 comments on commit 01e373f

Please sign in to comment.