Skip to content

Commit

Permalink
Wrap on WasmMsg::Execute,Migrate, remove wrapper in top-level execute…
Browse files Browse the repository at this point in the history
…_contract
  • Loading branch information
ethanfrey authored and maurolacy committed Oct 28, 2021
1 parent 7b3b1cf commit 0a4f3f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 2 additions & 4 deletions packages/multi-test/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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")));
}
}
}
11 changes: 8 additions & 3 deletions packages/multi-test/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<T: Serialize>(
&mut self,
sender: Addr,
Expand All @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions packages/multi-test/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -871,7 +871,6 @@ struct ExecuteResponse {
}

// empty return if no data present in original
#[allow(dead_code)]
fn execute_response(data: Option<Binary>) -> Option<Binary> {
data.map(|d| {
let exec_data = ExecuteResponse { data: d.to_vec() };
Expand Down

0 comments on commit 0a4f3f3

Please sign in to comment.