Skip to content

Commit

Permalink
adds tests to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Aug 30, 2024
1 parent 561adf5 commit 05a2e70
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
20 changes: 20 additions & 0 deletions contracts/auctions/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,23 @@ pub fn set_highest_bid(

Ok(())
}

#[cfg(test)]
mod test {
use soroban_sdk::Env;

use super::validate_input_params;

#[test]
#[should_panic(expected = "Auction: Validate input: Invalid inputs used")]
fn validate_input_params_should_fail_with_invalid_input() {
let env = Env::default();
let _ = validate_input_params(&env, &[&1, &2, &3, &0]);
}

#[test]
fn validate_input_params_should_work() {
let env = Env::default();
assert!(validate_input_params(&env, &[&1, &2, &3]).is_ok());
}
}
30 changes: 30 additions & 0 deletions contracts/auctions/src/test/initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,33 @@ fn mp_should_be_able_create_multiple_auctions_and_query_them_with_pagination() {
(1..=25).collect::<std::vec::Vec<u64>>()
);
}

#[test]
fn get_auction_by_id_should_return_an_err_when_id_not_found() {
let env = Env::default();
env.mock_all_auths();
env.budget().reset_unlimited();
let seller = Address::generate(&env);

let (mp_client, _) = generate_marketplace_and_collection_client(&env, &seller, None, None);

assert_eq!(
mp_client.try_get_auction(&5),
Err(Ok(ContractError::AuctionNotFound))
)
}

#[test]
fn get_auction_by_seller_should_return_an_err_when_id_not_found() {
let env = Env::default();
env.mock_all_auths();
env.budget().reset_unlimited();
let seller = Address::generate(&env);

let (mp_client, _) = generate_marketplace_and_collection_client(&env, &seller, None, None);

assert_eq!(
mp_client.try_get_auctions_by_seller(&Address::generate(&env)),
Err(Ok(ContractError::AuctionNotFound))
)
}

0 comments on commit 05a2e70

Please sign in to comment.