message: Test context builder
diff: @@ -281,6 +281,7 @@ mod test {
  use super::*;
  use crate::errors::StdError;
  use crate::{coins, from_slice, to_vec, Uint128};
  + use std::convert::TryInto;
  #[test]
  fn log_works_for_different_types() {
  @@ -342,4 +343,68 @@ mod test {
  _ => panic!("must encode in Bank variant"),
  }
  }
  +
  + #[test]
  + fn empty_context() {
  + let ctx = Context::new();
  +
  + let init: InitResponse = ctx.clone().try_into().unwrap();
  + assert_eq!(init, InitResponse::default());
  +
  + let init: HandleResponse = ctx.clone().try_into().unwrap();
  + assert_eq!(init, HandleResponse::default());
  +
  + let init: MigrateResponse = ctx.clone().try_into().unwrap();
  + assert_eq!(init, MigrateResponse::default());
  + }
  +
  + #[test]
  + fn full_context() {
  + let mut ctx = Context::new();
  +
  + // build it up with the builder commands
  + ctx.emit("sender", &HumanAddr::from("john"));
  + ctx.emit("action", "test");
  + ctx.send_action(BankMsg::Send {
  + from_address: HumanAddr::from("goo"),
  + to_address: HumanAddr::from("foo"),
  + amount: coins(128, "uint"),
  + });
  +
  + // and this is what is should return
  + let expected_log = vec![log("sender", "john"), log("action", "test")];
  + let expected_msgs = vec![CosmosMsg::Bank(BankMsg::Send {
  + from_address: HumanAddr::from("goo"),
  + to_address: HumanAddr::from("foo"),
  + amount: coins(128, "uint"),
  + })];
  + let expected_data = Some(Binary::from(b"banana"));
  +
  + // try InitResponse before setting data
  + let init: InitResponse = ctx.clone().try_into().unwrap();
  + assert_eq!(&init.messages, &expected_msgs);
  + assert_eq!(&init.log, &expected_log);
  +
  + ctx.set_data(b"banana");
  + // should fail with data set
  + let init_err: StdResult<InitResponse> = ctx.clone().try_into();
  + match init_err.unwrap_err() {
  + StdError::GenericErr { msg, .. } => {
  + assert_eq!(msg, "cannot convert Context with data to InitResponse")
  + }
  + e => panic!("Unexpected error: {}", e),
  + }
  +
  + // try Handle with everything set
  + let handle: HandleResponse = ctx.clone().try_into().unwrap();
  + assert_eq!(&handle.messages, &expected_msgs);
  + assert_eq!(&handle.log, &expected_log);
  + assert_eq!(&handle.data, &expected_data);
  +
  + // try Migrate with everything set
  + let migrate: MigrateResponse = ctx.clone().try_into().unwrap();
  + assert_eq!(&migrate.messages, &expected_msgs);
  + assert_eq!(&migrate.log, &expected_log);
  + assert_eq!(&migrate.data, &expected_data);
  + }
  }
  