diff --git a/contracts/airdrop/src/contract.rs b/contracts/airdrop/src/contract.rs index 471345b..a4e04bb 100644 --- a/contracts/airdrop/src/contract.rs +++ b/contracts/airdrop/src/contract.rs @@ -12,6 +12,7 @@ use cosmwasm_std::{ Empty, Env, MessageInfo, Response, StdError, StdResult, Uint128, }; use cw2::{get_contract_version, set_contract_version}; +use cw2::VersionError::Std; use semver::Version; pub const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); @@ -103,29 +104,22 @@ pub fn reward_users( ) -> Result { let mut res = vec![]; + let mut campaign = CAMPAIGN.load(deps.storage).map_err(|_| { + StdError::generic_err("Failed to load campaign data") + })?; + + if campaign.owner != info.sender + && !campaign.managers.contains(&info.sender) + { + return Err(StdError::generic_err("Unauthorized")); + } + for req in requests { - let mut campaign = CAMPAIGN.load(deps.storage).map_err(|_| { - StdError::generic_err("Failed to load campaign data") - })?; - - if campaign.owner != info.sender - && !campaign.managers.contains(&info.sender) - { - res.push(RewardUserResponse { - user_address: req.user_address.clone(), - success: false, - error_msg: "Unauthorized".to_string(), - }); - continue; - } if campaign.unallocated_amount < req.amount { - res.push(RewardUserResponse { - user_address: req.user_address.clone(), - success: false, - error_msg: "Not enough funds in campaign".to_string(), - }); - continue; + return Err(StdError::generic_err( + "Not enough funds in the campaign", + )); } match USER_REWARDS.may_load(deps.storage, req.user_address.clone())? { diff --git a/contracts/airdrop/src/tests/execute/reward_users.rs b/contracts/airdrop/src/tests/execute/reward_users.rs index 6d3f1b8..57ac5bd 100644 --- a/contracts/airdrop/src/tests/execute/reward_users.rs +++ b/contracts/airdrop/src/tests/execute/reward_users.rs @@ -171,3 +171,8 @@ fn test_reward_users_as_manager() { Uint128::new(250) ); } + +fn test_fails_when_we_try_to_allocate_more_than_available() { + let mut deps = mock_dependencies(); + let env = mock_env(); +} \ No newline at end of file