From fbc64ebe1e9f5983c7c73fb1af59dcc4cd50db21 Mon Sep 17 00:00:00 2001 From: Sturdy <91910406+apollo-sturdy@users.noreply.github.com> Date: Fri, 14 Jul 2023 20:26:07 +0200 Subject: [PATCH] fix: remove unnecessary if in query map (#249) --- contracts/incentives/src/contract.rs | 9 +-------- contracts/incentives/tests/test_quering.rs | 23 ++++++++++++++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/contracts/incentives/src/contract.rs b/contracts/incentives/src/contract.rs index 7527f737..d26b748b 100644 --- a/contracts/incentives/src/contract.rs +++ b/contracts/incentives/src/contract.rs @@ -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) } diff --git a/contracts/incentives/tests/test_quering.rs b/contracts/incentives/tests/test_quering.rs index 8575e0dd..f91bbdb4 100644 --- a/contracts/incentives/tests/test_quering.rs +++ b/contracts/incentives/tests/test_quering.rs @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, },