diff --git a/src/lib.rs b/src/lib.rs index 2c80d18e..70e13598 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,5 +41,7 @@ pub use crate::module::{AcceptingModule, FailingModule, Module}; pub use crate::staking::{ Distribution, DistributionKeeper, StakeKeeper, Staking, StakingInfo, StakingSudo, }; -pub use crate::stargate::{Stargate, StargateFailingModule, StargateMsg, StargateQuery}; +pub use crate::stargate::{ + Stargate, StargateAcceptingModule, StargateFailingModule, StargateMsg, StargateQuery, +}; pub use crate::wasm::{ContractData, Wasm, WasmKeeper, WasmSudo}; diff --git a/src/stargate.rs b/src/stargate.rs index 1e951274..7ff093dd 100644 --- a/src/stargate.rs +++ b/src/stargate.rs @@ -1,4 +1,4 @@ -use crate::{FailingModule, Module}; +use crate::{AcceptingModule, FailingModule, Module}; use cosmwasm_std::{Binary, CosmosMsg, Empty, QueryRequest}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -19,6 +19,10 @@ pub struct StargateQuery { pub trait Stargate: Module {} +pub type StargateAcceptingModule = AcceptingModule; + +impl Stargate for StargateAcceptingModule {} + pub type StargateFailingModule = FailingModule; impl Stargate for StargateFailingModule {} diff --git a/tests/test_module/accepting_module/mod.rs b/tests/test_module/accepting_module/mod.rs new file mode 100644 index 00000000..eddca26f --- /dev/null +++ b/tests/test_module/accepting_module/mod.rs @@ -0,0 +1,2 @@ +mod test_accepting_module; +mod test_stargate_accepting_module; diff --git a/tests/test_module/test_accepting_module.rs b/tests/test_module/accepting_module/test_accepting_module.rs similarity index 100% rename from tests/test_module/test_accepting_module.rs rename to tests/test_module/accepting_module/test_accepting_module.rs diff --git a/tests/test_module/accepting_module/test_stargate_accepting_module.rs b/tests/test_module/accepting_module/test_stargate_accepting_module.rs new file mode 100644 index 00000000..db8c9517 --- /dev/null +++ b/tests/test_module/accepting_module/test_stargate_accepting_module.rs @@ -0,0 +1,68 @@ +use cosmwasm_std::testing::MockStorage; +use cosmwasm_std::{Addr, Binary, Empty}; +use cw_multi_test::{AcceptingModule, App, AppResponse, Module, StargateMsg, StargateQuery}; + +/// Utility function for comparing responses. +fn eq(actual: AppResponse, expected: AppResponse) { + assert_eq!(actual.events, expected.events); + assert_eq!(actual.data, expected.data); +} + +/// Utility function for asserting default outputs returned from accepting module. +fn assert_results(accepting_module: AcceptingModule) { + let app = App::default(); + let mut storage = MockStorage::default(); + eq( + AppResponse::default(), + accepting_module + .execute( + app.api(), + &mut storage, + app.router(), + &app.block_info(), + Addr::unchecked("sender"), + StargateMsg { + type_url: Default::default(), + value: Default::default(), + }, + ) + .unwrap(), + ); + assert_eq!( + Binary::default(), + accepting_module + .query( + app.api(), + &storage, + &(*app.wrap()), + &app.block_info(), + StargateQuery { + path: Default::default(), + data: Default::default() + } + ) + .unwrap() + ); + eq( + AppResponse::default(), + accepting_module + .sudo( + app.api(), + &mut storage, + app.router(), + &app.block_info(), + Empty {}, + ) + .unwrap(), + ); +} + +#[test] +fn stargate_accepting_module_default_works() { + assert_results(AcceptingModule::default()); +} + +#[test] +fn stargate_accepting_module_new_works() { + assert_results(AcceptingModule::new()); +} diff --git a/tests/test_module/failing_module/mod.rs b/tests/test_module/failing_module/mod.rs new file mode 100644 index 00000000..eb0460dc --- /dev/null +++ b/tests/test_module/failing_module/mod.rs @@ -0,0 +1,2 @@ +mod test_failing_module; +mod test_stargate_failing_module; diff --git a/tests/test_module/test_failing_module.rs b/tests/test_module/failing_module/test_failing_module.rs similarity index 100% rename from tests/test_module/test_failing_module.rs rename to tests/test_module/failing_module/test_failing_module.rs diff --git a/tests/test_module/failing_module/test_stargate_failing_module.rs b/tests/test_module/failing_module/test_stargate_failing_module.rs new file mode 100644 index 00000000..7eb3aa59 --- /dev/null +++ b/tests/test_module/failing_module/test_stargate_failing_module.rs @@ -0,0 +1,65 @@ +use cosmwasm_std::testing::MockStorage; +use cosmwasm_std::{Addr, Empty}; +use cw_multi_test::{App, FailingModule, Module, StargateMsg, StargateQuery}; + +/// Utility function for asserting outputs returned from failing module. +fn assert_results(failing_module: FailingModule) { + let app = App::default(); + let mut storage = MockStorage::default(); + assert_eq!( + r#"Unexpected exec msg StargateMsg { type_url: "", value: Binary() } from Addr("sender")"#, + failing_module + .execute( + app.api(), + &mut storage, + app.router(), + &app.block_info(), + Addr::unchecked("sender"), + StargateMsg { + type_url: Default::default(), + value: Default::default(), + } + ) + .unwrap_err() + .to_string() + ); + assert_eq!( + r#"Unexpected custom query StargateQuery { path: "", data: Binary() }"#, + failing_module + .query( + app.api(), + &storage, + &(*app.wrap()), + &app.block_info(), + StargateQuery { + path: Default::default(), + data: Default::default() + } + ) + .unwrap_err() + .to_string() + ); + assert_eq!( + "Unexpected sudo msg Empty", + failing_module + .sudo( + app.api(), + &mut storage, + app.router(), + &app.block_info(), + Empty {} + ) + .unwrap_err() + .to_string() + ); +} + +#[test] +fn stargate_failing_module_default_works() { + assert_results(FailingModule::default()); +} + +#[test] +fn stargate_failing_module_new_works() { + assert_results(FailingModule::new()); +} diff --git a/tests/test_module/mod.rs b/tests/test_module/mod.rs index 8ccf49ca..309f94fd 100644 --- a/tests/test_module/mod.rs +++ b/tests/test_module/mod.rs @@ -1,2 +1,2 @@ -mod test_accepting_module; -mod test_failing_module; +mod accepting_module; +mod failing_module;