Skip to content

Commit

Permalink
fix linting errors and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-c-child committed May 13, 2024
1 parent ace3b83 commit fa2769b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
40 changes: 19 additions & 21 deletions contracts/name-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn execute_mint_and_list(
return Err(ContractError::MintingNotStarted {});
}

for list in list.iter() {
if let Some(list) = list {
match list.contract_type {
WhitelistContractType::UpdatableFlatrateDiscount => {
let contract = WhitelistUpdatableFlatrateContract(list.addr.clone());
Expand All @@ -206,21 +206,21 @@ pub fn execute_mint_and_list(
let discount = list.map(|list| match list.contract_type {
WhitelistContractType::UpdatableFlatrateDiscount => {
let contract = WhitelistUpdatableFlatrateContract(list.addr.clone());
return Discount::Flatrate(
Discount::Flatrate(
contract
.mint_discount_amount(&deps.querier)
.unwrap()
.unwrap(),
);
.unwrap_or(0u64),
)
}
WhitelistContractType::UpdatablePercentDiscount => {
let contract = WhitelistUpdatableContract(list.addr.clone());
return Discount::Percent(
Discount::Percent(
contract
.mint_discount_percent(&deps.querier)
.unwrap()
.unwrap(),
);
.unwrap_or(Decimal::zero()),
)
}
});

Expand Down Expand Up @@ -411,22 +411,20 @@ fn validate_payment(
})
.into();

match discount {
Some(Discount::Flatrate(discount)) => {
let discount = Uint128::from(discount);
if amount.ge(&discount) {
amount = amount
.checked_sub(discount)
.map_err(|_| StdError::generic_err("invalid discount amount"))?;
}
}
Some(Discount::Percent(discount)) => {
amount = amount * (Decimal::one() - discount);
}
None => {
amount = amount;
match discount {
Some(Discount::Flatrate(discount)) => {
let discount = Uint128::from(discount);
if amount.ge(&discount) {
amount = amount
.checked_sub(discount)
.map_err(|_| StdError::generic_err("invalid discount amount"))?;
}
}
Some(Discount::Percent(discount)) => {
amount = amount * (Decimal::one() - discount);
}
None => {}
}

if amount.is_zero() {
return Ok(None);
Expand Down
2 changes: 1 addition & 1 deletion contracts/name-minter/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn instantiate_contracts(
if let Some(admin) = admin {
let msg = ExecuteMsg::AddWhitelist {
address: wl.to_string(),
whitelist_type: "FlatrateDiscount".to_string()
whitelist_type: "FlatrateDiscount".to_string(),
};
let res = app.execute_contract(Addr::unchecked(admin), Addr::unchecked(minter), &msg, &[]);
assert!(res.is_ok());
Expand Down
2 changes: 0 additions & 2 deletions contracts/name-minter/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Addr, Uint128};
use sg_name_minter::{Config, SudoParams};

use crate::state::{WhitelistContract, WhitelistContractType};

#[cw_serde]
pub struct InstantiateMsg {
/// Temporary admin for managing whitelists
Expand Down
4 changes: 1 addition & 3 deletions contracts/name-minter/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ use cw_storage_plus::Item;
use serde::{Deserialize, Serialize};
use sg_name_minter::{Config, SudoParams};

use whitelist_updatable_flatrate::helpers::WhitelistUpdatableFlatrateContract;

#[derive(Serialize, Deserialize)]
pub struct WhitelistContract {
pub contract_type: WhitelistContractType,
pub addr: Addr,
}

#[derive(Serialize, Deserialize, PartialEq)]
#[derive(Serialize, Deserialize, PartialEq, Eq)]
pub enum WhitelistContractType {
UpdatableFlatrateDiscount,
UpdatablePercentDiscount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ mod tests {
// add wl_addr to minter
let msg = sg_name_minter::SgNameMinterExecuteMsg::AddWhitelist {
address: wl_addr.to_string(),
whitelist_type: "FlatrateDiscount".to_string(),
};
let res = app.execute_contract(Addr::unchecked(CREATOR), minter_addr.clone(), &msg, &[]);
assert!(res.is_ok());
Expand Down Expand Up @@ -337,6 +338,7 @@ mod tests {
// surpass limit
let msg = sg_name_minter::SgNameMinterExecuteMsg::AddWhitelist {
address: wl_addr.to_string(),
whitelist_type: "FlatrateDiscount".to_string(),
};
let res = app.execute_contract(Addr::unchecked(CREATOR), minter_addr.clone(), &msg, &[]);
assert!(res.is_ok());
Expand Down Expand Up @@ -457,6 +459,7 @@ mod tests {

let msg = sg_name_minter::SgNameMinterExecuteMsg::AddWhitelist {
address: wl_addr.to_string(),
whitelist_type: "FlatrateDiscount".to_string(),
};
let res = app.execute_contract(Addr::unchecked(CREATOR), minter_addr, &msg, &[]);
assert!(res.is_ok());
Expand Down
2 changes: 2 additions & 0 deletions contracts/whitelist-updatable/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ mod tests {
// add wl_addr to minter
let msg = sg_name_minter::SgNameMinterExecuteMsg::AddWhitelist {
address: wl_addr.to_string(),
whitelist_type: "FlatrateDiscount".to_string(),
};
let res = app.execute_contract(Addr::unchecked(CREATOR), minter_addr.clone(), &msg, &[]);
assert!(res.is_ok());
Expand Down Expand Up @@ -332,6 +333,7 @@ mod tests {
// surpass limit
let msg = sg_name_minter::SgNameMinterExecuteMsg::AddWhitelist {
address: wl_addr.to_string(),
whitelist_type: "FlatrateDiscount".to_string(),
};
let res = app.execute_contract(Addr::unchecked(CREATOR), minter_addr.clone(), &msg, &[]);
assert!(res.is_ok());
Expand Down
5 changes: 4 additions & 1 deletion packages/sg-name-minter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ pub enum SgNameMinterExecuteMsg {
/// Will be set to null after go-to-market
UpdateAdmin { admin: Option<String> },
/// Add a whiltelist address
AddWhitelist { address: String },
AddWhitelist {
address: String,
whitelist_type: String,
},
/// Remove a whitelist address
RemoveWhitelist { address: String },
/// Update config, only callable by admin
Expand Down

0 comments on commit fa2769b

Please sign in to comment.