Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Hartnell committed Aug 18, 2023
1 parent a15a415 commit 854bc32
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/cw-hooks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a> Hooks<'a> {
#[cfg(test)]
mod tests {
use super::*;
use cosmwasm_std::{coins, testing::mock_dependencies, BankMsg};
use cosmwasm_std::{coins, testing::mock_dependencies, BankMsg, Empty};

// Shorthand for an unchecked address.
macro_rules! addr {
Expand Down Expand Up @@ -151,6 +151,30 @@ mod tests {
)]
);

// Test prepare hooks with custom messages.
// In a real world scenario, you would be using something like
// TokenFactoryMsg.
let msgs = hooks
.prepare_hooks_custom_msg(storage, |a| {
Ok(SubMsg::<Empty>::reply_always(
BankMsg::Burn {
amount: coins(a.as_str().len() as u128, "uekez"),
},
2,
))
})
.unwrap();

assert_eq!(
msgs,
vec![SubMsg::<Empty>::reply_always(
BankMsg::Burn {
amount: coins(4, "uekez"),
},
2,
)]
);

let HooksResponse { hooks: the_hooks } = hooks.query_hooks(deps.as_ref()).unwrap();

assert_eq!(the_hooks, vec![addr!("meow")]);
Expand Down

0 comments on commit 854bc32

Please sign in to comment.