diff --git a/examples/contracts/cw1-subkeys/src/multitest/tests.rs b/examples/contracts/cw1-subkeys/src/multitest/tests.rs index ab2a0405..63d0f743 100644 --- a/examples/contracts/cw1-subkeys/src/multitest/tests.rs +++ b/examples/contracts/cw1-subkeys/src/multitest/tests.rs @@ -46,7 +46,7 @@ fn get_contract_version_works() { .unwrap(); let version: ContractVersion = - query_contract_info(&app.app_mut().wrap(), contract.contract_addr.to_string()).unwrap(); + query_contract_info(&app.querier(), contract.contract_addr.to_string()).unwrap(); assert_eq!( ContractVersion { diff --git a/sylvia-derive/src/message.rs b/sylvia-derive/src/message.rs index b8703df1..3be5f42a 100644 --- a/sylvia-derive/src/message.rs +++ b/sylvia-derive/src/message.rs @@ -704,8 +704,7 @@ impl<'a> MsgVariant<'a> { let msg = #enum_name :: #name ( #(#arguments),* ); (*self.app) - .app() - .wrap() + .querier() .query_wasm_smart(self.contract_addr.clone(), &msg) .map_err(Into::into) } @@ -763,8 +762,7 @@ impl<'a> MsgVariant<'a> { let msg = #interface_api :: #type_name :: #name ( #(#arguments),* ); (*self.app) - .app() - .wrap() + .querier() .query_wasm_smart(self.contract_addr.clone(), &msg) .map_err(Into::into) } diff --git a/sylvia-derive/src/multitest.rs b/sylvia-derive/src/multitest.rs index 86d71f8c..d251e85c 100644 --- a/sylvia-derive/src/multitest.rs +++ b/sylvia-derive/src/multitest.rs @@ -194,13 +194,8 @@ impl<'a> ContractMtHelpers<'a> { for #sylvia ::multitest::Proxy <'app, #mt_app, #contract_name > where CustomT: #sylvia ::cw_multi_test::Module, - CustomT::ExecT: std::fmt::Debug - + PartialEq - + Clone - + #sylvia ::schemars::JsonSchema - + #sylvia ::serde::de::DeserializeOwned - + 'static, - CustomT::QueryT: #sylvia ::cw_std::CustomQuery + #sylvia ::serde::de::DeserializeOwned + 'static, + CustomT::ExecT: #sylvia::types::CustomMsg + 'static, + CustomT::QueryT: #sylvia ::types::CustomQuery + 'static, WasmT: #sylvia ::cw_multi_test::Wasm, BankT: #sylvia ::cw_multi_test::Bank, ApiT: #sylvia ::cw_std::Api, @@ -322,7 +317,7 @@ impl<'a> ContractMtHelpers<'a> { let code_info = if cfg!(feature = "cosmwasm_1_2") { quote! { pub fn code_info(&self) -> #sylvia ::cw_std::StdResult< #sylvia ::cw_std::CodeInfoResponse> { - self.app.app().wrap().query_wasm_code_info(self.code_id) + self.app.querier().query_wasm_code_info(self.code_id) } } } else { @@ -719,13 +714,8 @@ impl<'a> TraitMtHelpers<'a> { DistrT: #sylvia ::cw_multi_test::Distribution, IbcT: #sylvia ::cw_multi_test::Ibc, GovT: #sylvia ::cw_multi_test::Gov, - CustomT::ExecT: Clone - + std::fmt::Debug - + PartialEq - + #sylvia ::schemars::JsonSchema - + #sylvia ::serde::de::DeserializeOwned - + 'static, - CustomT::QueryT: #sylvia:: cw_std::CustomQuery + #sylvia ::serde::de::DeserializeOwned + 'static, + CustomT::ExecT: #sylvia ::types::CustomMsg + 'static, + CustomT::QueryT: #sylvia:: types::CustomQuery + 'static, #mt_app : #sylvia ::cw_multi_test::Executor< #custom_msg >, #where_predicates { diff --git a/sylvia/src/multitest.rs b/sylvia/src/multitest.rs index 20176295..4d0cff5b 100644 --- a/sylvia/src/multitest.rs +++ b/sylvia/src/multitest.rs @@ -2,19 +2,22 @@ use std::cell::{Ref, RefCell, RefMut}; use std::fmt::{Debug, Display}; use std::marker::PhantomData; -use cosmwasm_std::{Addr, Api, BlockInfo, Coin, CustomQuery, Empty, Storage}; +use cosmwasm_std::{ + Addr, Api, BlockInfo, Coin, Empty, Querier, QuerierResult, QuerierWrapper, Storage, +}; #[cfg(feature = "cosmwasm_1_2")] use cosmwasm_std::{CodeInfoResponse, StdResult}; use cw_multi_test::{ Bank, BankKeeper, Distribution, DistributionKeeper, Executor, FailingModule, Gov, - GovFailingModule, Ibc, IbcFailingModule, Module, Router, StakeKeeper, Staking, StargateFailing, - Wasm, WasmKeeper, + GovFailingModule, Ibc, IbcFailingModule, Module, Router, StakeKeeper, Staking, Stargate, + StargateFailing, Wasm, WasmKeeper, }; use derivative::Derivative; use schemars::JsonSchema; -use serde::de::DeserializeOwned; use serde::Serialize; +use crate::types::{CustomMsg, CustomQuery}; + #[derive(Derivative)] #[derivative(Debug)] pub struct Proxy<'a, MtApp, Contract> { @@ -29,7 +32,7 @@ impl<'a, MtApp, Contract> Proxy<'a, MtApp, Contract> { Proxy { contract_addr, app, - _phantom: std::marker::PhantomData::<(MtApp, Contract)>::default(), + _phantom: std::marker::PhantomData::<(MtApp, Contract)>, } } } @@ -59,8 +62,8 @@ impl App> { /// Creates new default `App` implementation working with customized exec and query messages. pub fn custom(init_fn: F) -> Self where - ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static, - QueryC: Debug + CustomQuery + DeserializeOwned + 'static, + ExecC: CustomMsg + 'static, + QueryC: Debug + CustomQuery + 'static, F: FnOnce( &mut Router< BankKeeper, @@ -101,8 +104,8 @@ impl App { impl App> where - CustomT::ExecT: std::fmt::Debug + PartialEq + Clone + JsonSchema + DeserializeOwned + 'static, - CustomT::QueryT: CustomQuery + DeserializeOwned + 'static, + CustomT::ExecT: CustomMsg + 'static, + CustomT::QueryT: CustomQuery + 'static, WasmT: Wasm, BankT: Bank, ApiT: Api, @@ -127,7 +130,48 @@ where #[cfg(feature = "cosmwasm_1_2")] pub fn code_info(&self, code_id: u64) -> StdResult { - self.app.borrow().wrap().query_wasm_code_info(code_id) + self.querier().query_wasm_code_info(code_id) + } + + /// Initialize a new `cosmwasm_std::QuerierWrapper` used to call e.g. `query_wasm_smart` or + /// `query_all_balances`. + /// A counterpart to `cw_multi_test::App::wrap` method. + pub fn querier(&self) -> QuerierWrapper<'_, CustomT::QueryT> { + QuerierWrapper::new(self) + } +} + +impl Querier + for App< + cw_multi_test::App< + BankT, + ApiT, + StorageT, + CustomT, + WasmT, + StakingT, + DistrT, + IbcT, + GovT, + StargateT, + >, + > +where + CustomT::ExecT: CustomMsg + 'static, + CustomT::QueryT: CustomQuery + 'static, + WasmT: Wasm, + BankT: Bank, + ApiT: Api, + StorageT: Storage, + CustomT: Module, + StakingT: Staking, + DistrT: Distribution, + IbcT: Ibc, + GovT: Gov, + StargateT: Stargate, +{ + fn raw_query(&self, bin_request: &[u8]) -> QuerierResult { + self.app.borrow().raw_query(bin_request) } }