Skip to content

Commit

Permalink
fix farm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dorin-iancu committed Oct 31, 2024
1 parent 27a7b86 commit 6fdcde1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
20 changes: 8 additions & 12 deletions dex/farm/tests/farm_multi_user_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 11 additions & 15 deletions dex/farm/tests/total_farm_position_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -893,7 +889,7 @@ fn total_farm_position_owner_change_test() {
&rust_biguint!(half_token_amount),
Some(&FarmTokenAttributes::<DebugApi> {
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),
Expand Down Expand Up @@ -999,7 +995,7 @@ fn total_farm_position_owner_change_test() {
&rust_biguint!(half_token_amount * 3),
Some(&FarmTokenAttributes::<DebugApi> {
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),
Expand Down
2 changes: 1 addition & 1 deletion energy-integration/farm-boosted-yields/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6fdcde1

Please sign in to comment.