Skip to content

Commit

Permalink
Parse protobuf data before executing submsg, update test contract to …
Browse files Browse the repository at this point in the history
…match
  • Loading branch information
GumboLimbo committed Mar 13, 2024
1 parent 96438a5 commit 4ccd49b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
20 changes: 2 additions & 18 deletions packages/multi-test/src/multi/test_helpers/contracts/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,13 @@ where
{
let res = Response::new();
if let Reply {
id,
id: _,
result: SubMsgResult::Ok(SubMsgResponse {
data: Some(data), ..
}),
} = msg
{
// We parse out the WasmMsg::Execute wrapper...
// TODO: Handle all of Execute, Instantiate, and BankMsg replies differently.
let parsed_data = if id < EXECUTE_REPLY_BASE_ID {
parse_instantiate_response_data(data.as_slice())
.map_err(|e| StdError::generic_err(e.to_string()))?
.data
} else {
parse_execute_response_data(data.as_slice())
.map_err(|e| StdError::generic_err(e.to_string()))?
.data
};

if let Some(data) = parsed_data {
Ok(res.set_data(data))
} else {
Ok(res)
}
Ok(res.set_data(data))
} else {
Ok(res)
}
Expand Down
10 changes: 9 additions & 1 deletion packages/multi-test/src/multi/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use cosmwasm_std::{
use nanoid::nanoid;
use prost::Message;
use schemars::JsonSchema;
use secret_utils::parse_execute_response_data;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -571,11 +572,18 @@ where
// call reply if meaningful
if let Ok(mut r) = res {
if matches!(reply_on, ReplyOn::Always | ReplyOn::Success) {
let data: Option<Binary> = if let Some(b) = r.data {
let parsed = parse_execute_response_data(b.as_slice())?;
parsed.data
} else {
None
};

let reply = Reply {
id,
result: SubMsgResult::Ok(SubMsgResponse {
events: r.events.clone(),
data: r.data,
data,
}),
};
// do reply and combine it with the original response
Expand Down

0 comments on commit 4ccd49b

Please sign in to comment.