-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Impl interfaces on generic_contract
- Loading branch information
Showing
8 changed files
with
281 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
examples/contracts/generic_contract/src/custom_and_generic.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult}; | ||
use custom_and_generic::CustomAndGeneric; | ||
use sylvia::contract; | ||
use sylvia::types::{ExecCtx, QueryCtx, SvCustomMsg}; | ||
|
||
#[contract(module = crate::contract)] | ||
#[messages(custom_and_generic as CustomAndGeneric)] | ||
#[sv::custom(msg=sylvia::types::SvCustomMsg)] | ||
impl<InstantiateParam, ExecParam, QueryParam, MigrateParam, RetType> | ||
CustomAndGeneric<SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg> | ||
for crate::contract::GenericContract< | ||
InstantiateParam, | ||
ExecParam, | ||
QueryParam, | ||
MigrateParam, | ||
RetType, | ||
> | ||
{ | ||
type Error = StdError; | ||
|
||
#[msg(exec)] | ||
fn custom_generic_execute( | ||
&self, | ||
_ctx: ExecCtx, | ||
_msgs: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>, | ||
) -> StdResult<Response<SvCustomMsg>> { | ||
Ok(Response::new()) | ||
} | ||
|
||
#[msg(query)] | ||
fn custom_generic_query( | ||
&self, | ||
_ctx: QueryCtx, | ||
_msg: sylvia::types::SvCustomMsg, | ||
) -> StdResult<SvCustomMsg> { | ||
Ok(SvCustomMsg {}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::test_utils::CustomAndGeneric; | ||
use crate::contract::multitest_utils::CodeId; | ||
use sylvia::{multitest::App, types::SvCustomMsg}; | ||
|
||
#[test] | ||
fn proxy_methods() { | ||
let app = App::<cw_multi_test::BasicApp<SvCustomMsg>>::custom(|_, _, _| {}); | ||
let code_id = CodeId::< | ||
SvCustomMsg, | ||
sylvia::types::SvCustomMsg, | ||
SvCustomMsg, | ||
SvCustomMsg, | ||
sylvia::types::SvCustomMsg, | ||
_, | ||
>::store_code(&app); | ||
|
||
let owner = "owner"; | ||
|
||
let contract = code_id | ||
.instantiate(SvCustomMsg {}) | ||
.with_label("GenericContract") | ||
.with_admin(owner) | ||
.call(owner) | ||
.unwrap(); | ||
|
||
contract | ||
.custom_and_generic_proxy() | ||
.custom_generic_execute(vec![]) | ||
.call(owner) | ||
.unwrap(); | ||
contract | ||
.custom_and_generic_proxy() | ||
.custom_generic_query(SvCustomMsg {}) | ||
.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult}; | ||
use cw1::{CanExecuteResp, Cw1}; | ||
use sylvia::contract; | ||
use sylvia::types::{ExecCtx, QueryCtx}; | ||
|
||
#[contract(module = crate::contract)] | ||
#[messages(cw1 as Cw1)] | ||
#[sv::custom(msg=sylvia::types::SvCustomMsg)] | ||
impl<InstantiateParam, ExecParam, QueryParam, MigrateParam, RetType> Cw1 | ||
for crate::contract::GenericContract< | ||
InstantiateParam, | ||
ExecParam, | ||
QueryParam, | ||
MigrateParam, | ||
RetType, | ||
> | ||
{ | ||
type Error = StdError; | ||
|
||
#[msg(exec)] | ||
fn execute(&self, _ctx: ExecCtx, _msgs: Vec<CosmosMsg>) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
|
||
#[msg(query)] | ||
fn can_execute( | ||
&self, | ||
_ctx: QueryCtx, | ||
_sender: String, | ||
_msg: CosmosMsg, | ||
) -> StdResult<CanExecuteResp> { | ||
Ok(CanExecuteResp::default()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::test_utils::Cw1; | ||
use crate::contract::multitest_utils::CodeId; | ||
use cosmwasm_std::{CosmosMsg, Empty}; | ||
use sylvia::{multitest::App, types::SvCustomMsg}; | ||
|
||
#[test] | ||
fn proxy_methods() { | ||
let app = App::<cw_multi_test::BasicApp<SvCustomMsg>>::custom(|_, _, _| {}); | ||
let code_id = CodeId::< | ||
SvCustomMsg, | ||
sylvia::types::SvCustomMsg, | ||
SvCustomMsg, | ||
SvCustomMsg, | ||
sylvia::types::SvCustomMsg, | ||
_, | ||
>::store_code(&app); | ||
|
||
let owner = "owner"; | ||
|
||
let contract = code_id | ||
.instantiate(SvCustomMsg {}) | ||
.with_label("GenericContract") | ||
.with_admin(owner) | ||
.call(owner) | ||
.unwrap(); | ||
|
||
contract.cw1_proxy().execute(vec![]).call(owner).unwrap(); | ||
contract | ||
.cw1_proxy() | ||
.can_execute("sender".to_owned(), CosmosMsg::Custom(Empty {})) | ||
.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult}; | ||
use generic::Generic; | ||
use sylvia::contract; | ||
use sylvia::types::{ExecCtx, QueryCtx, SvCustomMsg}; | ||
|
||
#[contract(module = crate::contract)] | ||
#[messages(generic as Generic)] | ||
#[sv::custom(msg=SvCustomMsg)] | ||
impl<InstantiateParam, ExecParam, QueryParam, MigrateParam, RetType> | ||
Generic<SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg> | ||
for crate::contract::GenericContract< | ||
InstantiateParam, | ||
ExecParam, | ||
QueryParam, | ||
MigrateParam, | ||
RetType, | ||
> | ||
{ | ||
type Error = StdError; | ||
|
||
#[msg(exec)] | ||
fn generic_exec( | ||
&self, | ||
_ctx: ExecCtx, | ||
_msgs: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>, | ||
) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
|
||
// Sylvia will fail if single type is used to match against two different generics | ||
// It's because we have to map unique generics used as they can be used multiple times. | ||
// If for some reason like here one type would be used in place of two generics either full | ||
// path or some alias has to be used. | ||
#[msg(query)] | ||
fn generic_query( | ||
&self, | ||
_ctx: QueryCtx, | ||
_msg: sylvia::types::SvCustomMsg, | ||
) -> StdResult<SvCustomMsg> { | ||
Ok(SvCustomMsg {}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::test_utils::Generic; | ||
use crate::contract::multitest_utils::CodeId; | ||
use cosmwasm_std::CosmosMsg; | ||
use sylvia::multitest::App; | ||
use sylvia::types::SvCustomMsg; | ||
|
||
#[test] | ||
fn proxy_methods() { | ||
let app = App::<cw_multi_test::BasicApp<SvCustomMsg>>::custom(|_, _, _| {}); | ||
let code_id: CodeId< | ||
SvCustomMsg, | ||
sylvia::types::SvCustomMsg, | ||
SvCustomMsg, | ||
SvCustomMsg, | ||
sylvia::types::SvCustomMsg, | ||
_, | ||
> = CodeId::store_code(&app); | ||
|
||
let owner = "owner"; | ||
|
||
let contract = code_id | ||
.instantiate(SvCustomMsg {}) | ||
.with_label("GenericContract") | ||
.with_admin(owner) | ||
.call(owner) | ||
.unwrap(); | ||
|
||
contract | ||
.generic_proxy() | ||
.generic_exec(vec![CosmosMsg::Custom(SvCustomMsg {})]) | ||
.call(owner) | ||
.unwrap(); | ||
contract.generic_proxy().generic_query(SvCustomMsg).unwrap(); | ||
} | ||
} |
Oops, something went wrong.