Skip to content

Commit

Permalink
Merge pull request #385 from CosmWasm/data-response-handling
Browse files Browse the repository at this point in the history
Corrected submessage data response handling in multi-test
  • Loading branch information
ethanfrey authored Aug 10, 2021
2 parents 84bd7e3 + b34093b commit 09e9e0f
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/multi-test/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ where
///
/// For normal use cases, you can use Router::execute() or Router::execute_multi().
/// This is designed to be handled internally as part of larger process flows.
///
/// The `data` on `AppResponse` is data returned from `reply` call, not from execution of
/// submessage itself. In case if `reply` is not called, no `data` is set.
fn execute_submsg(
&self,
api: &dyn Api,
Expand All @@ -389,28 +392,27 @@ where
});

// call reply if meaningful
if let Ok(r) = res {
if let Ok(mut r) = res {
if matches!(reply_on, ReplyOn::Always | ReplyOn::Success) {
let mut orig = r.clone();
let reply = Reply {
id,
result: ContractResult::Ok(SubMsgExecutionResponse {
events: r.events,
events: r.events.clone(),
data: r.data,
}),
};
// do reply and combine it with the original response
let res2 = self._reply(api, router, storage, block, contract, reply)?;
// override data if set
if let Some(data) = res2.data {
orig.data = Some(data);
}
let reply_res = self._reply(api, router, storage, block, contract, reply)?;
// override data
r.data = reply_res.data;
// append the events
orig.events.extend_from_slice(&res2.events);
Ok(orig)
r.events.extend_from_slice(&reply_res.events);
} else {
Ok(r)
// reply is not called, no data should be rerturned
r.data = None;
}

Ok(r)
} else if let Err(e) = res {
if matches!(reply_on, ReplyOn::Always | ReplyOn::Error) {
let reply = Reply {
Expand Down

0 comments on commit 09e9e0f

Please sign in to comment.