Skip to content

Commit

Permalink
Merge pull request #395 from CosmWasm/app-response-into
Browse files Browse the repository at this point in the history
Make it easier to assert events on reply statements
  • Loading branch information
ethanfrey authored Aug 26, 2021
2 parents 3539081 + 9e2a88b commit 2d2c7f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 2 additions & 6 deletions packages/multi-test/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,8 @@ mod test {
// validate the events written in the reply blob...should just be bank transfer
let reply = res.result.unwrap();
assert_eq!(1, reply.events.len());
// Note: this shows we must make the helpers more generic
let app_res = AppResponse {
events: reply.events,
data: reply.data,
};
app_res.assert_event(&Event::new("transfer").add_attribute("amount", "7eth"));
AppResponse::from(reply)
.assert_event(&Event::new("transfer").add_attribute("amount", "7eth"));

// reflect sends 300 btc, failure, but error caught by submessage (so shows success)
let msg = SubMsg::reply_always(
Expand Down
16 changes: 15 additions & 1 deletion packages/multi-test/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::fmt;

use crate::parse_contract_addr;
use cosmwasm_std::{to_binary, Addr, Attribute, BankMsg, Binary, Coin, CosmosMsg, Event, WasmMsg};
use cosmwasm_std::{
to_binary, Addr, Attribute, BankMsg, Binary, Coin, CosmosMsg, Event, SubMsgExecutionResponse,
WasmMsg,
};
use schemars::JsonSchema;
use serde::Serialize;

Expand Down Expand Up @@ -47,6 +50,17 @@ impl AppResponse {
}
}

/// They have the same shape, SubMsgExecutionResponse is what is returned in reply.
/// This is just to make some test cases easier.
impl From<SubMsgExecutionResponse> for AppResponse {
fn from(reply: SubMsgExecutionResponse) -> Self {
AppResponse {
data: reply.data,
events: reply.events,
}
}
}

pub trait Executor<C>
where
C: Clone + fmt::Debug + PartialEq + JsonSchema + 'static,
Expand Down

0 comments on commit 2d2c7f9

Please sign in to comment.