From 6fdcde121558077629905d426f355d47bbafbcf0 Mon Sep 17 00:00:00 2001 From: Dorin Marian Iancu Date: Thu, 31 Oct 2024 10:18:47 +0200 Subject: [PATCH] fix farm tests --- dex/farm/tests/farm_multi_user_test.rs | 20 ++++++-------- dex/farm/tests/total_farm_position_test.rs | 26 ++++++++----------- .../farm-boosted-yields/src/lib.rs | 2 +- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/dex/farm/tests/farm_multi_user_test.rs b/dex/farm/tests/farm_multi_user_test.rs index d44439fba..b79e32a05 100644 --- a/dex/farm/tests/farm_multi_user_test.rs +++ b/dex/farm/tests/farm_multi_user_test.rs @@ -122,22 +122,20 @@ fn farm_with_boosted_yields_test() { farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); farm_setup.set_boosted_yields_factors(); - farm_setup.b_mock.set_block_epoch(2); - farm_setup - .b_mock - .set_block_timestamp(2 * TIMESTAMP_PER_EPOCH); + farm_setup.b_mock.set_block_epoch(0); + farm_setup.b_mock.set_block_timestamp(1); // first user enter farm let first_farm_token_amount = 100_000_000; let first_user = farm_setup.first_user.clone(); let third_user = farm_setup.third_user.clone(); - farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.set_user_energy(&first_user, 1_000, 0, 1); farm_setup.enter_farm(&first_user, first_farm_token_amount); // second user enter farm let second_farm_token_amount = 50_000_000; let second_user = farm_setup.second_user.clone(); - farm_setup.set_user_energy(&second_user, 4_000, 2, 1); + farm_setup.set_user_energy(&second_user, 4_000, 0, 1); farm_setup.enter_farm(&second_user, second_farm_token_amount); // users claim rewards to get their energy registered @@ -521,23 +519,21 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); farm_setup.set_boosted_yields_factors(); - farm_setup.b_mock.set_block_epoch(2); - farm_setup - .b_mock - .set_block_timestamp(3 * TIMESTAMP_PER_EPOCH - 1); + farm_setup.b_mock.set_block_epoch(0); + farm_setup.b_mock.set_block_timestamp(1); let third_user = farm_setup.third_user.clone(); // first user enter farm let first_farm_token_amount = 100_000_000; let first_user = farm_setup.first_user.clone(); - farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.set_user_energy(&first_user, 1_000, 0, 1); farm_setup.enter_farm(&first_user, first_farm_token_amount); // second user enter farm let second_farm_token_amount = 50_000_000; let second_user = farm_setup.second_user.clone(); - farm_setup.set_user_energy(&second_user, 4_000, 2, 1); + farm_setup.set_user_energy(&second_user, 4_000, 0, 1); farm_setup.enter_farm(&second_user, second_farm_token_amount); // users claim rewards to get their energy registered diff --git a/dex/farm/tests/total_farm_position_test.rs b/dex/farm/tests/total_farm_position_test.rs index 3887e9d54..88e0725fb 100644 --- a/dex/farm/tests/total_farm_position_test.rs +++ b/dex/farm/tests/total_farm_position_test.rs @@ -695,10 +695,8 @@ fn no_boosted_rewards_penalty_for_no_energy_test() { farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); farm_setup.set_boosted_yields_factors(); - farm_setup.b_mock.set_block_epoch(5); - farm_setup - .b_mock - .set_block_timestamp(6 * TIMESTAMP_PER_EPOCH - 1); + farm_setup.b_mock.set_block_epoch(0); + farm_setup.b_mock.set_block_timestamp(1); let temp_user = farm_setup.third_user.clone(); @@ -794,10 +792,8 @@ fn total_farm_position_owner_change_test() { farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); farm_setup.set_boosted_yields_factors(); - farm_setup.b_mock.set_block_epoch(2); - farm_setup - .b_mock - .set_block_timestamp(3 * TIMESTAMP_PER_EPOCH - 1); + farm_setup.b_mock.set_block_epoch(0); + farm_setup.b_mock.set_block_timestamp(1); // first user enters farm 6 times let farm_token_amount = 10_000_000; @@ -822,11 +818,11 @@ fn total_farm_position_owner_change_test() { assert_eq!(farm_setup.last_farm_token_nonce, 6); // First user transfers 5 position to second user - farm_setup.send_farm_position(&first_user, &second_user, 1, farm_token_amount, 0, 2); - farm_setup.send_farm_position(&first_user, &second_user, 2, farm_token_amount, 0, 2); - farm_setup.send_farm_position(&first_user, &second_user, 3, farm_token_amount, 0, 2); - farm_setup.send_farm_position(&first_user, &second_user, 4, farm_token_amount, 0, 2); - farm_setup.send_farm_position(&first_user, &second_user, 5, farm_token_amount, 0, 2); + farm_setup.send_farm_position(&first_user, &second_user, 1, farm_token_amount, 0, 0); + farm_setup.send_farm_position(&first_user, &second_user, 2, farm_token_amount, 0, 0); + farm_setup.send_farm_position(&first_user, &second_user, 3, farm_token_amount, 0, 0); + farm_setup.send_farm_position(&first_user, &second_user, 4, farm_token_amount, 0, 0); + farm_setup.send_farm_position(&first_user, &second_user, 5, farm_token_amount, 0, 0); // Total farm position unchanged as users only transfered the farm positions farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); @@ -893,7 +889,7 @@ fn total_farm_position_owner_change_test() { &rust_biguint!(half_token_amount), Some(&FarmTokenAttributes:: { reward_per_share: managed_biguint!(107142857), - entering_epoch: 2, + entering_epoch: 0, compounded_reward: managed_biguint!(0), current_farm_amount: managed_biguint!(half_token_amount), original_owner: managed_address!(&second_user), @@ -999,7 +995,7 @@ fn total_farm_position_owner_change_test() { &rust_biguint!(half_token_amount * 3), Some(&FarmTokenAttributes:: { reward_per_share: managed_biguint!(35714286), - entering_epoch: 2, + entering_epoch: 0, compounded_reward: managed_biguint!(0), current_farm_amount: managed_biguint!(half_token_amount * 3), original_owner: managed_address!(&second_user), diff --git a/energy-integration/farm-boosted-yields/src/lib.rs b/energy-integration/farm-boosted-yields/src/lib.rs index 10725e790..aced2c207 100644 --- a/energy-integration/farm-boosted-yields/src/lib.rs +++ b/energy-integration/farm-boosted-yields/src/lib.rs @@ -158,7 +158,7 @@ where return user_rewards; } - let week_timestamps = sc.get_week_start_and_end_timestamp(claim_progress.week + 1); + let week_timestamps = sc.get_week_start_and_end_timestamp(claim_progress.week); let new_user_reward = sc.limit_boosted_rewards_by_claim_time(user_reward, &week_timestamps, claim_progress); if new_user_reward == 0 {