Skip to content

Commit

Permalink
Additional tests helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
MissingNO57 committed Apr 15, 2024
1 parent 62fffb2 commit 0e55e97
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/testing/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cosmwasm_std::testing::{mock_dependencies, MockApi, MockQuerier, MockStorage};
use cosmwasm_std::ContractResult as StdContractResult;
use cosmwasm_std::{
to_json_binary, Addr, ContractInfoResponse, Empty, OwnedDeps, SystemError, SystemResult,
WasmQuery,
};
use cosmwasm_std::{BankMsg, Coin, ContractResult as StdContractResult, Response, SubMsg, Uint128};

pub fn deps_with_creator(
creator: Addr,
Expand Down Expand Up @@ -31,3 +31,23 @@ pub fn deps_with_creator(
deps.querier = querier;
deps
}

pub fn assert_err<T, E: std::fmt::Debug>(result: Result<T, E>, error: &E) {
// Check if result contains specific error
match result {
Ok(_) => panic!("Expected Err, got Ok"),
Err(res_error) => assert_eq!(format!("{:?}", res_error), format!("{:?}", error)),
}
}

pub fn assert_transfer(res: &Response, address: &Addr, amount: &u128, denom: &str) {
let send_msg = SubMsg::new(BankMsg::Send {
to_address: address.to_string(),
amount: vec![Coin {
denom: denom.to_string(),
amount: Uint128::new(*amount),
}],
});

assert_eq!(res.messages[0], send_msg);
}

0 comments on commit 0e55e97

Please sign in to comment.