Skip to content

Commit

Permalink
Make it easier to assert events on reply statements
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Aug 26, 2021
1 parent 3539081 commit 9e2a88b
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 9e2a88b

Please sign in to comment.