From deef1df68c7d34bb917bf0dc09c2cc1eee7e4532 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 7 Jun 2022 10:13:52 +0200 Subject: [PATCH 1/2] Use standard CosmosMsg --- packages/multi-test/src/app.rs | 7 +- packages/multi-test/src/lib.rs | 1 - packages/multi-test/src/untyped_msg.rs | 95 -------------------------- 3 files changed, 4 insertions(+), 99 deletions(-) delete mode 100644 packages/multi-test/src/untyped_msg.rs diff --git a/packages/multi-test/src/app.rs b/packages/multi-test/src/app.rs index 57db2fba8..ac5fe558d 100644 --- a/packages/multi-test/src/app.rs +++ b/packages/multi-test/src/app.rs @@ -1,11 +1,12 @@ use std::fmt::{self, Debug}; use std::marker::PhantomData; +use anyhow::bail; use anyhow::Result as AnyResult; use cosmwasm_std::testing::{mock_env, MockApi, MockStorage}; use cosmwasm_std::{ - from_slice, to_binary, Addr, Api, Binary, BlockInfo, ContractResult, CustomQuery, Empty, - Querier, QuerierResult, QuerierWrapper, QueryRequest, Record, Storage, SystemError, + from_slice, to_binary, Addr, Api, Binary, BlockInfo, ContractResult, CosmosMsg, CustomQuery, + Empty, Querier, QuerierResult, QuerierWrapper, QueryRequest, Record, Storage, SystemError, SystemResult, }; use schemars::JsonSchema; @@ -18,7 +19,6 @@ use crate::executor::{AppResponse, Executor}; use crate::module::{FailingModule, Module}; use crate::staking::{Distribution, FailingDistribution, FailingStaking, Staking, StakingSudo}; use crate::transactions::transactional; -use crate::untyped_msg::CosmosMsg; use crate::wasm::{ContractData, Wasm, WasmKeeper, WasmSudo}; pub fn next_block(block: &mut BlockInfo) { @@ -799,6 +799,7 @@ where CosmosMsg::Distribution(msg) => self .distribution .execute(api, storage, self, block, sender, msg), + _ => bail!("Cannot execute {:?}", msg), } } diff --git a/packages/multi-test/src/lib.rs b/packages/multi-test/src/lib.rs index 543f07d3a..b532a8152 100644 --- a/packages/multi-test/src/lib.rs +++ b/packages/multi-test/src/lib.rs @@ -17,7 +17,6 @@ mod module; mod staking; mod test_helpers; mod transactions; -mod untyped_msg; mod wasm; pub use crate::app::{ diff --git a/packages/multi-test/src/untyped_msg.rs b/packages/multi-test/src/untyped_msg.rs deleted file mode 100644 index 9e857fdcb..000000000 --- a/packages/multi-test/src/untyped_msg.rs +++ /dev/null @@ -1,95 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use std::fmt; - -use cosmwasm_std::{BankMsg, DistributionMsg, Empty, StakingMsg, WasmMsg}; - -/// This is needed so we can embed CosmosMsg as a trait bound. -/// See https://github.com/CosmWasm/cosmwasm/pull/1098 for a proper solution -/// (when we can deprecate this one) -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum CosmosMsg { - Bank(BankMsg), - // by default we use RawMsg, but a contract can override that - // to call into more app-specific code (whatever they define) - Custom(T), - #[cfg(feature = "staking")] - Distribution(DistributionMsg), - #[cfg(feature = "staking")] - Staking(StakingMsg), - Wasm(WasmMsg), -} - -impl From> for cosmwasm_std::CosmosMsg -where - T: Clone + fmt::Debug + PartialEq + JsonSchema, -{ - fn from(input: CosmosMsg) -> Self { - match input { - CosmosMsg::Bank(b) => cosmwasm_std::CosmosMsg::Bank(b), - CosmosMsg::Custom(c) => cosmwasm_std::CosmosMsg::Custom(c), - #[cfg(feature = "staking")] - CosmosMsg::Distribution(d) => cosmwasm_std::CosmosMsg::Distribution(d), - #[cfg(feature = "staking")] - CosmosMsg::Staking(s) => cosmwasm_std::CosmosMsg::Staking(s), - CosmosMsg::Wasm(w) => cosmwasm_std::CosmosMsg::Wasm(w), - } - } -} - -impl From> for CosmosMsg -where - T: Clone + fmt::Debug + PartialEq + JsonSchema, -{ - fn from(input: cosmwasm_std::CosmosMsg) -> CosmosMsg { - match input { - cosmwasm_std::CosmosMsg::Bank(b) => CosmosMsg::Bank(b), - cosmwasm_std::CosmosMsg::Custom(c) => CosmosMsg::Custom(c), - #[cfg(feature = "staking")] - cosmwasm_std::CosmosMsg::Distribution(d) => CosmosMsg::Distribution(d), - #[cfg(feature = "staking")] - cosmwasm_std::CosmosMsg::Staking(s) => CosmosMsg::Staking(s), - cosmwasm_std::CosmosMsg::Wasm(w) => CosmosMsg::Wasm(w), - _ => panic!("Unsupported type"), - } - } -} - -impl From for CosmosMsg -where - T: Clone + fmt::Debug + PartialEq + JsonSchema, -{ - fn from(msg: BankMsg) -> Self { - CosmosMsg::Bank(msg) - } -} - -#[cfg(feature = "staking")] -impl From for CosmosMsg -where - T: Clone + fmt::Debug + PartialEq + JsonSchema, -{ - fn from(msg: StakingMsg) -> Self { - CosmosMsg::Staking(msg) - } -} - -#[cfg(feature = "staking")] -impl From for CosmosMsg -where - T: Clone + fmt::Debug + PartialEq + JsonSchema, -{ - fn from(msg: DistributionMsg) -> Self { - CosmosMsg::Distribution(msg) - } -} - -impl From for CosmosMsg -where - T: Clone + fmt::Debug + PartialEq + JsonSchema, -{ - fn from(msg: WasmMsg) -> Self { - CosmosMsg::Wasm(msg) - } -} From aef5e80fe8c1677129e35e259fba84da6b8b8a90 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 7 Jun 2022 10:26:08 +0200 Subject: [PATCH 2/2] Fix clippy warnings --- packages/multi-test/src/app.rs | 4 ++-- packages/multi-test/src/wasm.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/multi-test/src/app.rs b/packages/multi-test/src/app.rs index ac5fe558d..68995265c 100644 --- a/packages/multi-test/src/app.rs +++ b/packages/multi-test/src/app.rs @@ -627,7 +627,7 @@ where transactional(&mut *storage, |write_cache, _| { msgs.into_iter() - .map(|msg| router.execute(&*api, write_cache, block, sender.clone(), msg.into())) + .map(|msg| router.execute(&*api, write_cache, block, sender.clone(), msg)) .collect() }) } @@ -1499,7 +1499,7 @@ mod test { lucky_winner: winner.clone(), runner_up: second.clone(), }); - app.execute(Addr::unchecked("anyone"), msg.into()).unwrap(); + app.execute(Addr::unchecked("anyone"), msg).unwrap(); // see if coins were properly added let big_win = app.wrap().query_balance(&winner, denom).unwrap(); diff --git a/packages/multi-test/src/wasm.rs b/packages/multi-test/src/wasm.rs index 42c350ffe..cdbd06143 100644 --- a/packages/multi-test/src/wasm.rs +++ b/packages/multi-test/src/wasm.rs @@ -320,7 +320,7 @@ where amount: amount.to_vec(), } .into(); - let res = router.execute(api, storage, block, sender.into(), msg.into())?; + let res = router.execute(api, storage, block, sender.into(), msg)?; Ok(res) } else { Ok(AppResponse::default()) @@ -502,7 +502,7 @@ where // execute in cache let res = transactional(storage, |write_cache, _| { - router.execute(api, write_cache, block, contract.clone(), msg.into()) + router.execute(api, write_cache, block, contract.clone(), msg) }); // call reply if meaningful