Skip to content

Commit

Permalink
Address linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MightOfOaks committed Dec 12, 2023
1 parent 62170e3 commit edfb461
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 deletions.
66 changes: 34 additions & 32 deletions contracts/minter/src/contract_updatable_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,8 @@ fn test_update_none_royalties() {
err.source().unwrap().to_string(),
sg721_updatable::ContractError::InvalidRoyalties(format!(
"Share percentage cannot be greater than 10%"
)).to_string()
))
.to_string()
);

let update_royalty_msg: Sg721UpdatableExecuteMsg<Extension> =
Expand All @@ -1549,22 +1550,21 @@ fn test_update_none_royalties() {
share_bps: 400,
};

let res = router
.execute_contract(
creator.clone(),
Addr::unchecked(sg71_address.clone()),
&update_royalty_msg,
&[],
);

let res = router.execute_contract(
creator.clone(),
Addr::unchecked(sg71_address.clone()),
&update_royalty_msg,
&[],
);

let err = res.unwrap_err();

assert_eq!(
err.source().unwrap().to_string(),
sg721_updatable::ContractError::InvalidRoyalties(format!(
"Share increase cannot be greater than 2%"
)).to_string()
))
.to_string()
);

let update_royalty_msg: Sg721UpdatableExecuteMsg<Extension> =
Expand Down Expand Up @@ -1612,21 +1612,21 @@ fn test_update_none_royalties() {

setup_block_time(&mut router, GENESIS_MINT_START_TIME + 86400000000000);

let res = router
.execute_contract(
creator.clone(),
Addr::unchecked(sg71_address.clone()),
&update_royalty_msg,
&[],
);
let res = router.execute_contract(
creator.clone(),
Addr::unchecked(sg71_address.clone()),
&update_royalty_msg,
&[],
);

let err = res.unwrap_err();

assert_eq!(
err.source().unwrap().to_string(),
sg721_updatable::ContractError::InvalidRoyalties(format!(
"Share increase cannot be greater than 2%"
)).to_string()
))
.to_string()
);

let update_royalty_msg: Sg721UpdatableExecuteMsg<Extension> =
Expand All @@ -1635,12 +1635,14 @@ fn test_update_none_royalties() {
share_bps: 200,
};

let res = router.execute_contract(
creator.clone(),
Addr::unchecked(sg71_address.clone()),
&update_royalty_msg,
&[],
).unwrap();
let res = router
.execute_contract(
creator.clone(),
Addr::unchecked(sg71_address.clone()),
&update_royalty_msg,
&[],
)
.unwrap();

assert_eq!(res.events[1].attributes[0].key, "_contract_addr");
assert_eq!(res.events[1].attributes[0].value, "contract1");
Expand Down Expand Up @@ -1748,7 +1750,8 @@ fn test_update_royalties() {
err.source().unwrap().to_string(),
sg721_updatable::ContractError::InvalidRoyalties(format!(
"Share percentage cannot be greater than 10%"
)).to_string()
))
.to_string()
);

let update_royalty_msg: sg721_updatable::msg::ExecuteMsg<Extension> =
Expand Down Expand Up @@ -1964,13 +1967,12 @@ fn try_migrate() {

let sg721_base_address = config.sg721_address;

let res = router
.migrate_contract(
creator,
Addr::unchecked(sg721_base_address.clone()),
&Empty {},
sg721_code_id,
);
let res = router.migrate_contract(
creator,
Addr::unchecked(sg721_base_address.clone()),
&Empty {},
sg721_code_id,
);

assert!(res.is_ok());
}
16 changes: 10 additions & 6 deletions contracts/sg721-updatable/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ pub fn execute_update_royalty_info(
let share = Decimal::percent(share_bps) / Uint128::from(100u128);
let max_share_limit = Decimal::percent(MAX_ROYALTY_SHARE_BPS) / Uint128::from(100u128);
let max_share_delta = Decimal::percent(MAX_ROYALTY_SHARE_DELTA_BPS) / Uint128::from(100u128);
ensure!(share <= max_share_limit,
ensure!(
share <= max_share_limit,
// multiply by 100 to get the percentage for error message
ContractError::InvalidRoyalties(format!(
"Share percentage cannot be greater than {}%", max_share_limit * Uint128::from(100u128)
)));

"Share percentage cannot be greater than {}%",
max_share_limit * Uint128::from(100u128)
))
);

let updated_at = ROYALTY_UPDATED_AT.load(deps.storage)?;

Expand All @@ -173,15 +175,17 @@ pub fn execute_update_royalty_info(
ensure!(
share_delta <= max_share_delta,
ContractError::InvalidRoyalties(format!(
"Share increase cannot be greater than {}%", max_share_delta * Uint128::from(100u128)
"Share increase cannot be greater than {}%",
max_share_delta * Uint128::from(100u128)
))
);
}
} else {
ensure!(
share <= max_share_delta,
ContractError::InvalidRoyalties(format!(
"Share increase cannot be greater than {}%", max_share_delta * Uint128::from(100u128)
"Share increase cannot be greater than {}%",
max_share_delta * Uint128::from(100u128)
))
);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/sg721-updatable/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ pub struct RoyaltyInfoResponse {
impl RoyaltyInfoResponse {
pub fn share_validate(&self) -> Result<Decimal, ContractError> {
if self.share > Decimal::one() {
return Err(ContractError::InvalidRoyalties(format!(
"Invalid royalty share percentage"
)));
return Err(ContractError::InvalidRoyalties(
"Invalid royalty percentage".to_string(),
));
}

Ok(self.share)
Expand Down

0 comments on commit edfb461

Please sign in to comment.