From 0a4f3f38e56e8320bbda8c090cbe3f5fcde77889 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 28 Oct 2021 12:33:11 +0200 Subject: [PATCH] Wrap on WasmMsg::Execute,Migrate, remove wrapper in top-level execute_contract --- packages/multi-test/src/app.rs | 6 ++---- packages/multi-test/src/executor.rs | 11 ++++++++--- packages/multi-test/src/wasm.rs | 9 ++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/multi-test/src/app.rs b/packages/multi-test/src/app.rs index 180186020..2339b9db6 100644 --- a/packages/multi-test/src/app.rs +++ b/packages/multi-test/src/app.rs @@ -2511,7 +2511,6 @@ mod test { assert_ne!(parsed.contract_address, addr1.to_string()); } - #[ignore] #[test] fn execute_wrapped_properly() { let owner = Addr::unchecked("owner"); @@ -2528,10 +2527,9 @@ mod test { data: Some("hello".into()), ..echo::Message::default() }; + // execute_contract now decodes a protobuf wrapper, so we get the top-level response let exec_res = app.execute_contract(owner, echo_addr, &msg, &[]).unwrap(); - assert!(exec_res.data.is_some()); - let parsed = parse_execute_response_data(&exec_res.data.unwrap()).unwrap(); - assert_eq!(parsed.data, Some(Binary::from(b"hello"))); + assert_eq!(exec_res.data, Some(Binary::from(b"hello"))); } } } diff --git a/packages/multi-test/src/executor.rs b/packages/multi-test/src/executor.rs index 3138716c2..db9e57320 100644 --- a/packages/multi-test/src/executor.rs +++ b/packages/multi-test/src/executor.rs @@ -4,7 +4,7 @@ use cosmwasm_std::{ to_binary, Addr, Attribute, BankMsg, Binary, Coin, CosmosMsg, Event, SubMsgExecutionResponse, WasmMsg, }; -use cw0::parse_instantiate_response_data; +use cw0::{parse_execute_response_data, parse_instantiate_response_data}; use schemars::JsonSchema; use serde::Serialize; @@ -96,7 +96,8 @@ where } /// Execute a contract and process all returned messages. - /// This is just a helper around execute() + /// This is just a helper around execute(), + /// but we parse out the data field to that what is returned by the contract (not the protobuf wrapper) fn execute_contract( &mut self, sender: Addr, @@ -110,7 +111,11 @@ where msg, funds: send_funds.to_vec(), }; - self.execute(sender, msg.into()) + let mut res = self.execute(sender, msg.into())?; + res.data = res + .data + .and_then(|d| parse_execute_response_data(d.as_slice()).unwrap().data); + Ok(res) } /// Migrate a contract. Sender must be registered admin. diff --git a/packages/multi-test/src/wasm.rs b/packages/multi-test/src/wasm.rs index a13a318cc..76bc883c9 100644 --- a/packages/multi-test/src/wasm.rs +++ b/packages/multi-test/src/wasm.rs @@ -286,9 +286,9 @@ where Event::new("execute").add_attribute(CONTRACT_ATTR, &contract_addr); let (res, msgs) = self.build_app_response(&contract_addr, custom_event, res); - let res = + let mut res = self.process_response(api, router, storage, block, contract_addr, res, msgs)?; - // res.data = execute_response(res.data); + res.data = execute_response(res.data); Ok(res) } WasmMsg::Instantiate { @@ -384,9 +384,9 @@ where .add_attribute(CONTRACT_ATTR, &contract_addr) .add_attribute("code_id", new_code_id.to_string()); let (res, msgs) = self.build_app_response(&contract_addr, custom_event, res); - let res = + let mut res = self.process_response(api, router, storage, block, contract_addr, res, msgs)?; - // res.data = execute_response(res.data); + res.data = execute_response(res.data); Ok(res) } msg => bail!(Error::UnsupportedWasmMsg(msg)), @@ -871,7 +871,6 @@ struct ExecuteResponse { } // empty return if no data present in original -#[allow(dead_code)] fn execute_response(data: Option) -> Option { data.map(|d| { let exec_data = ExecuteResponse { data: d.to_vec() };