Skip to content

Commit

Permalink
Fixing tests helpers (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
MissingNO57 authored Apr 16, 2024
1 parent a769b4c commit 18c4b05
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cosmwasm-std = "1.1.3"
cosmwasm-storage = "1.1.3"
cw-storage-plus = "1.0.1"
cosmwasm-std = "1.5.3"
cw-storage-plus = "1.2.0"
bech32 = "0.9.1"
sha2 = "0.10.6"
ripemd = "0.1.3"
Expand Down
1 change: 0 additions & 1 deletion src/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod iteration_guard;
pub mod tests_helpers;
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod events;
pub mod helpers;
pub mod permissions;
pub mod storage;
pub mod testing;
24 changes: 22 additions & 2 deletions src/helpers/tests_helpers.rs → 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 All @@ -13,7 +13,7 @@ pub fn deps_with_creator(
let mut querier = MockQuerier::default();
querier.update_wasm(move |request| match request {
WasmQuery::ContractInfo { contract_addr } => {
if *contract_addr == contract_address {
if contract_addr == contract_address.as_str() {
let mut response = ContractInfoResponse::default();
response.admin = Some(creator.to_string());
SystemResult::Ok(StdContractResult::Ok(to_json_binary(&response).unwrap()))
Expand All @@ -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);
}
6 changes: 6 additions & 0 deletions src/testing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![cfg(not(target_arch = "wasm32"))]

// Exposed for testing only
// Both unit tests and integration tests are compiled to native code, so everything in here does not need to compile to Wasm.

pub mod helpers;

0 comments on commit 18c4b05

Please sign in to comment.