Skip to content

Commit

Permalink
fix: remove unnecessary if in query map (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo-sturdy authored and pacmanifold committed Jul 19, 2023
1 parent cc5950a commit fbc64eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
9 changes: 1 addition & 8 deletions contracts/incentives/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,7 @@ pub fn query_emission(
)
.next()
.transpose()?
.map(|(start_time, emission)| {
// The next emission has not yet started, so the emission at the requested timestamp is 0
if timestamp < start_time {
Uint128::zero()
} else {
emission
}
})
.map(|(_, emission)| emission)
.unwrap_or_default();
Ok(emission)
}
Expand Down
23 changes: 17 additions & 6 deletions contracts/incentives/tests/test_quering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ fn query_emission() {

EMISSIONS.save(deps.as_mut().storage, ("uosmo", "umars", 604800), &Uint128::new(100)).unwrap();
EMISSIONS
.save(deps.as_mut().storage, ("uatom", "umars", 604800 * 2), &Uint128::new(50))
.save(deps.as_mut().storage, ("uosmo", "umars", 604800 * 2), &Uint128::new(50))
.unwrap();

// Query before emission start
let res: Uint128 = helpers::th_query(
deps.as_ref(),
QueryMsg::Emission {
collateral_denom: "uusdc".to_string(),
collateral_denom: "uosmo".to_string(),
incentive_denom: "umars".to_string(),
timestamp: 0,
},
Expand All @@ -139,18 +139,29 @@ fn query_emission() {
let res: Uint128 = helpers::th_query(
deps.as_ref(),
QueryMsg::Emission {
collateral_denom: "uatom".to_string(),
collateral_denom: "uosmo".to_string(),
incentive_denom: "umars".to_string(),
timestamp: 604800 * 2,
},
);
assert_eq!(res, Uint128::new(50));

// Query one second before second emission start
let res: Uint128 = helpers::th_query(
deps.as_ref(),
QueryMsg::Emission {
collateral_denom: "uosmo".to_string(),
incentive_denom: "umars".to_string(),
timestamp: 604800 * 2 - 1,
},
);
assert_eq!(res, Uint128::new(100));

// Query at timestamp some time into second emission start
let res: Uint128 = helpers::th_query(
deps.as_ref(),
QueryMsg::Emission {
collateral_denom: "uatom".to_string(),
collateral_denom: "uosmo".to_string(),
incentive_denom: "umars".to_string(),
timestamp: 604800 * 2 + 100,
},
Expand All @@ -161,7 +172,7 @@ fn query_emission() {
let res: Uint128 = helpers::th_query(
deps.as_ref(),
QueryMsg::Emission {
collateral_denom: "uatom".to_string(),
collateral_denom: "uosmo".to_string(),
incentive_denom: "umars".to_string(),
timestamp: 604800 * 3 - 1,
},
Expand All @@ -172,7 +183,7 @@ fn query_emission() {
let res: Uint128 = helpers::th_query(
deps.as_ref(),
QueryMsg::Emission {
collateral_denom: "uatom".to_string(),
collateral_denom: "uosmo".to_string(),
incentive_denom: "umars".to_string(),
timestamp: 604800 * 3,
},
Expand Down

0 comments on commit fbc64eb

Please sign in to comment.