Skip to content

Commit

Permalink
Merge pull request #456 from CosmWasm/multitest-fixes
Browse files Browse the repository at this point in the history
Expose essential multitest types
  • Loading branch information
ethanfrey authored Sep 29, 2021
2 parents 61c7d4b + f8cc9c9 commit 36798d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
10 changes: 5 additions & 5 deletions packages/multi-test/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::marker::PhantomData;
use anyhow::Result as AnyResult;
use cosmwasm_std::testing::{mock_env, MockApi, MockStorage};
use cosmwasm_std::{
from_slice, to_vec, Addr, Api, Binary, BlockInfo, ContractResult, CustomQuery, Empty, Querier,
QuerierResult, QuerierWrapper, QueryRequest, Storage, SystemError, SystemResult,
from_slice, to_binary, Addr, Api, Binary, BlockInfo, ContractResult, CustomQuery, Empty,
Querier, QuerierResult, QuerierWrapper, QueryRequest, Storage, SystemError, SystemResult,
};
use schemars::JsonSchema;
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -596,7 +596,7 @@ where

/// Simple helper so we get access to all the QuerierWrapper helpers,
/// eg. wrap().query_wasm_smart, query_all_balances, ...
pub fn wrap(&self) -> QuerierWrapper {
pub fn wrap(&self) -> QuerierWrapper<CustomT::QueryT> {
QuerierWrapper::new(self)
}

Expand Down Expand Up @@ -634,7 +634,7 @@ where
contract_addr: U,
msg: &T,
) -> AnyResult<AppResponse> {
let msg = to_vec(msg)?;
let msg = to_binary(msg)?;

let Self {
block,
Expand Down Expand Up @@ -1346,7 +1346,7 @@ mod test {
let msg = payout::SudoMsg { set_count: 49 };
let sudo_msg = WasmSudo {
contract_addr: payout_addr.clone(),
msg: to_vec(&msg).unwrap(),
msg: to_binary(&msg).unwrap(),
};
app.sudo(sudo_msg.into()).unwrap();

Expand Down
10 changes: 7 additions & 3 deletions packages/multi-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ mod transactions;
mod untyped_msg;
mod wasm;

pub use crate::app::{custom_app, next_block, App, AppBuilder, BasicApp, BasicAppBuilder, Router};
pub use crate::bank::{Bank, BankKeeper};
pub use crate::app::{
custom_app, next_block, App, AppBuilder, BasicApp, BasicAppBuilder, CosmosRouter, Router,
SudoMsg,
};
pub use crate::bank::{Bank, BankKeeper, BankSudo};
pub use crate::contracts::{Contract, ContractWrapper};
pub use crate::executor::{AppResponse, Executor};
pub use crate::module::Module;
pub use crate::wasm::{parse_contract_addr, Wasm, WasmKeeper};
pub use crate::staking::{FailingDistribution, FailingStaking, Staking, StakingSudo};
pub use crate::wasm::{parse_contract_addr, Wasm, WasmKeeper, WasmSudo};
18 changes: 9 additions & 9 deletions packages/multi-test/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::fmt;
use std::ops::Deref;

use cosmwasm_std::{
to_vec, Addr, Api, Attribute, BankMsg, Binary, BlockInfo, Coin, ContractInfo, ContractResult,
CustomQuery, Deps, DepsMut, Env, Event, MessageInfo, Order, Querier, QuerierWrapper, Reply,
ReplyOn, Response, StdResult, Storage, SubMsg, SubMsgExecutionResponse, TransactionInfo,
WasmMsg, WasmQuery,
to_binary, Addr, Api, Attribute, BankMsg, Binary, BlockInfo, Coin, ContractInfo,
ContractResult, CustomQuery, Deps, DepsMut, Env, Event, MessageInfo, Order, Querier,
QuerierWrapper, Reply, ReplyOn, Response, StdResult, Storage, SubMsg, SubMsgExecutionResponse,
TransactionInfo, WasmMsg, WasmQuery,
};
use cosmwasm_storage::{prefixed, prefixed_read, PrefixedStorage, ReadonlyPrefixedStorage};
use prost::Message;
Expand Down Expand Up @@ -34,14 +34,14 @@ const CONTRACT_ATTR: &str = "_contract_addr";
#[derive(Clone, std::fmt::Debug, PartialEq, JsonSchema)]
pub struct WasmSudo {
pub contract_addr: Addr,
pub msg: Vec<u8>,
pub msg: Binary,
}

impl WasmSudo {
pub fn new<T: Serialize>(contract_addr: &Addr, msg: &T) -> StdResult<WasmSudo> {
Ok(WasmSudo {
contract_addr: contract_addr.clone(),
msg: to_vec(msg)?,
msg: to_binary(msg)?,
})
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ pub trait Wasm<ExecC, QueryC> {
storage: &mut dyn Storage,
router: &dyn CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
block: &BlockInfo,
msg: Vec<u8>,
msg: Binary,
) -> AnyResult<AppResponse>;
}

Expand Down Expand Up @@ -162,11 +162,11 @@ where
storage: &mut dyn Storage,
router: &dyn CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
block: &BlockInfo,
msg: Vec<u8>,
msg: Binary,
) -> AnyResult<AppResponse> {
let custom_event = Event::new("sudo").add_attribute(CONTRACT_ATTR, &contract);

let res = self.call_sudo(contract.clone(), api, storage, router, block, msg)?;
let res = self.call_sudo(contract.clone(), api, storage, router, block, msg.to_vec())?;
let (res, msgs) = self.build_app_response(&contract, custom_event, res);
self.process_response(api, router, storage, block, contract, res, msgs)
}
Expand Down

0 comments on commit 36798d6

Please sign in to comment.