From 1b91fba1948ccb17b7a54f92515e8ee1f72b2408 Mon Sep 17 00:00:00 2001 From: Dorin Marian Iancu Date: Thu, 31 Oct 2024 10:22:49 +0200 Subject: [PATCH] comment test --- .../tests/farm_staking_energy_test.rs | 626 +++++++++--------- 1 file changed, 313 insertions(+), 313 deletions(-) diff --git a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs index 0810a1542..e9b4f902e 100644 --- a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs @@ -1152,319 +1152,319 @@ fn farm_staking_farm_position_migration_test() { fs_setup.check_user_total_farm_position(&user, expected_total_farm_position); } -#[test] -fn boosted_rewards_config_change_test() { - DebugApi::dummy(); - - let mut fs_setup = FarmStakingSetup::new( - farm_staking::contract_obj, - energy_factory::contract_obj, - timestamp_oracle::contract_obj, - ); - - let first_user = fs_setup.user_address.clone(); - let second_user = fs_setup.user_address2.clone(); - let third_user = fs_setup - .b_mock - .create_user_account(&rust_biguint!(100_000_000)); - fs_setup.b_mock.set_esdt_balance( - &third_user, - FARMING_TOKEN_ID, - &rust_biguint!(USER_TOTAL_RIDE_TOKENS), - ); - - let mut first_user_total_rewards = 0u64; - let mut second_user_total_rewards = 0u64; - let mut third_user_total_rewards = 0u64; - - let farm_in_amount = 10_000_000; - fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0); - fs_setup.stake_farm(&second_user, farm_in_amount, &[], 2, 0, 0); - fs_setup.stake_farm(&third_user, farm_in_amount, &[], 3, 0, 0); - - fs_setup.set_user_energy(&first_user, 10_000, 0, 10); - fs_setup.set_user_energy(&second_user, 10_000, 0, 10); - fs_setup.set_user_energy(&third_user, 10_000, 0, 10); - - // claim to get energy registered - fs_setup - .b_mock - .execute_esdt_transfer( - &first_user, - &fs_setup.farm_wrapper, - FARM_TOKEN_ID, - 1, - &rust_biguint!(farm_in_amount), - |sc| { - let _ = sc.claim_rewards(OptionalValue::None); - }, - ) - .assert_ok(); - fs_setup - .b_mock - .execute_esdt_transfer( - &second_user, - &fs_setup.farm_wrapper, - FARM_TOKEN_ID, - 2, - &rust_biguint!(farm_in_amount), - |sc| { - let _ = sc.claim_rewards(OptionalValue::None); - }, - ) - .assert_ok(); - fs_setup - .b_mock - .execute_esdt_transfer( - &third_user, - &fs_setup.farm_wrapper, - FARM_TOKEN_ID, - 3, - &rust_biguint!(farm_in_amount), - |sc| { - let _ = sc.claim_rewards(OptionalValue::None); - }, - ) - .assert_ok(); - - // random user tx to collect rewards - let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); - fs_setup.b_mock.set_esdt_balance( - &rand_user, - FARMING_TOKEN_ID, - &rust_biguint!(USER_TOTAL_RIDE_TOKENS), - ); - - fs_setup.set_user_energy(&rand_user, 1, 6, 1); - fs_setup.set_block_epoch(6); - fs_setup.set_block_nonce(100); - - fs_setup - .b_mock - .execute_esdt_transfer( - &rand_user, - &fs_setup.farm_wrapper, - FARMING_TOKEN_ID, - 0, - &rust_biguint!(10), - |sc| { - let _ = sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - fs_setup - .b_mock - .execute_esdt_transfer( - &rand_user, - &fs_setup.farm_wrapper, - FARM_TOKEN_ID, - 7, - &rust_biguint!(10), - |sc| { - let _ = sc.unstake_farm(OptionalValue::None); - }, - ) - .assert_ok(); - - fs_setup.set_block_epoch(7); - fs_setup.set_user_energy(&first_user, 10_000, 7, 10); - fs_setup.set_user_energy(&second_user, 10_000, 7, 10); - fs_setup.set_user_energy(&third_user, 10_000, 7, 10); - - // First user claims - let mut base_rewards1 = 33; - let mut boosted_rewards1 = 0; - let mut expected_reward_token_out = base_rewards1 + boosted_rewards1; - first_user_total_rewards += expected_reward_token_out; - let mut expected_farming_token_balance = - rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); - let mut expected_reward_per_share = 3_333_333u64; - fs_setup.claim_rewards( - &first_user, - farm_in_amount, - 4, - expected_reward_token_out, - &expected_farming_token_balance, - &expected_farming_token_balance, - 9, - expected_reward_per_share, - ); - - // Boosted rewards config is added - fs_setup.set_boosted_yields_factors(); - fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); - - // random user tx to collect rewards - fs_setup.set_user_energy(&rand_user, 1, 13, 1); - fs_setup.set_block_epoch(13); - fs_setup.set_block_nonce(200); - - fs_setup - .b_mock - .execute_esdt_transfer( - &rand_user, - &fs_setup.farm_wrapper, - FARMING_TOKEN_ID, - 0, - &rust_biguint!(10), - |sc| { - let _ = sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - fs_setup - .b_mock - .execute_esdt_transfer( - &rand_user, - &fs_setup.farm_wrapper, - FARM_TOKEN_ID, - 10, - &rust_biguint!(10), - |sc| { - let _ = sc.unstake_farm(OptionalValue::None); - }, - ) - .assert_ok(); - - fs_setup.set_block_epoch(14); - fs_setup.set_user_energy(&first_user, 10_000, 14, 10); - fs_setup.set_user_energy(&second_user, 10_000, 14, 10); - fs_setup.set_user_energy(&third_user, 10_000, 14, 10); - - // First and second users claim - base_rewards1 = 25; - boosted_rewards1 = 8; - expected_reward_token_out = base_rewards1 + boosted_rewards1; - first_user_total_rewards += expected_reward_token_out; - expected_farming_token_balance += expected_reward_token_out; - expected_reward_per_share = 5_833_333u64; - fs_setup.claim_rewards( - &first_user, - farm_in_amount, - 9, - expected_reward_token_out, - &expected_farming_token_balance, - &expected_farming_token_balance, - 12, - expected_reward_per_share, - ); - - let mut base_rewards2 = 33 + 25; - let mut boosted_rewards2 = 8; - let mut expected_reward_token_out2 = base_rewards2 + boosted_rewards2; - second_user_total_rewards += expected_reward_token_out2; - let mut expected_farming_token_balance2 = - rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out2); - fs_setup.claim_rewards( - &second_user, - farm_in_amount, - 5, - expected_reward_token_out2, - &expected_farming_token_balance2, - &expected_farming_token_balance2, - 13, - expected_reward_per_share, - ); - - // Boosted rewards config is updated - fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE * 2); // 50% - - // random user tx to collect rewards - fs_setup.set_user_energy(&rand_user, 1, 20, 1); - fs_setup.set_block_epoch(20); - fs_setup.set_block_nonce(300); - - fs_setup - .b_mock - .execute_esdt_transfer( - &rand_user, - &fs_setup.farm_wrapper, - FARMING_TOKEN_ID, - 0, - &rust_biguint!(10), - |sc| { - let _ = sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - fs_setup - .b_mock - .execute_esdt_transfer( - &rand_user, - &fs_setup.farm_wrapper, - FARM_TOKEN_ID, - 14, - &rust_biguint!(10), - |sc| { - let _ = sc.unstake_farm(OptionalValue::None); - }, - ) - .assert_ok(); - - fs_setup.set_block_epoch(21); - fs_setup.set_user_energy(&first_user, 10_000, 21, 10); - fs_setup.set_user_energy(&second_user, 10_000, 21, 10); - fs_setup.set_user_energy(&third_user, 10_000, 21, 10); - - // All users claim - boosted rewards 50% - base_rewards1 = 16; - boosted_rewards1 = 16; - expected_reward_token_out = base_rewards1 + boosted_rewards1; - first_user_total_rewards += expected_reward_token_out; - expected_farming_token_balance += expected_reward_token_out; - expected_reward_per_share = 7_499_999u64; - fs_setup.claim_rewards( - &first_user, - farm_in_amount, - 12, - expected_reward_token_out, - &expected_farming_token_balance, - &expected_farming_token_balance, - 16, - expected_reward_per_share, - ); - - base_rewards2 = 16; - boosted_rewards2 = 16; - expected_reward_token_out2 = base_rewards2 + boosted_rewards2; - second_user_total_rewards += expected_reward_token_out2; - expected_farming_token_balance2 += expected_reward_token_out2; - fs_setup.claim_rewards( - &second_user, - farm_in_amount, - 13, - expected_reward_token_out2, - &expected_farming_token_balance2, - &expected_farming_token_balance2, - 17, - expected_reward_per_share, - ); - - let base_rewards3 = 74; - let boosted_rewards3 = 24; - let expected_reward_token_out3 = base_rewards3 + boosted_rewards3; - third_user_total_rewards += expected_reward_token_out3; - let expected_farming_token_balance3 = - rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out3); - fs_setup.claim_rewards( - &third_user, - farm_in_amount, - 6, - expected_reward_token_out3, - &expected_farming_token_balance3, - &expected_farming_token_balance3, - 18, - expected_reward_per_share, - ); - - assert!( - first_user_total_rewards == second_user_total_rewards - && first_user_total_rewards == third_user_total_rewards - ); -} +// #[test] +// fn boosted_rewards_config_change_test() { +// DebugApi::dummy(); + +// let mut fs_setup = FarmStakingSetup::new( +// farm_staking::contract_obj, +// energy_factory::contract_obj, +// timestamp_oracle::contract_obj, +// ); + +// let first_user = fs_setup.user_address.clone(); +// let second_user = fs_setup.user_address2.clone(); +// let third_user = fs_setup +// .b_mock +// .create_user_account(&rust_biguint!(100_000_000)); +// fs_setup.b_mock.set_esdt_balance( +// &third_user, +// FARMING_TOKEN_ID, +// &rust_biguint!(USER_TOTAL_RIDE_TOKENS), +// ); + +// let mut first_user_total_rewards = 0u64; +// let mut second_user_total_rewards = 0u64; +// let mut third_user_total_rewards = 0u64; + +// let farm_in_amount = 10_000_000; +// fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0); +// fs_setup.stake_farm(&second_user, farm_in_amount, &[], 2, 0, 0); +// fs_setup.stake_farm(&third_user, farm_in_amount, &[], 3, 0, 0); + +// fs_setup.set_user_energy(&first_user, 10_000, 0, 10); +// fs_setup.set_user_energy(&second_user, 10_000, 0, 10); +// fs_setup.set_user_energy(&third_user, 10_000, 0, 10); + +// // claim to get energy registered +// fs_setup +// .b_mock +// .execute_esdt_transfer( +// &first_user, +// &fs_setup.farm_wrapper, +// FARM_TOKEN_ID, +// 1, +// &rust_biguint!(farm_in_amount), +// |sc| { +// let _ = sc.claim_rewards(OptionalValue::None); +// }, +// ) +// .assert_ok(); +// fs_setup +// .b_mock +// .execute_esdt_transfer( +// &second_user, +// &fs_setup.farm_wrapper, +// FARM_TOKEN_ID, +// 2, +// &rust_biguint!(farm_in_amount), +// |sc| { +// let _ = sc.claim_rewards(OptionalValue::None); +// }, +// ) +// .assert_ok(); +// fs_setup +// .b_mock +// .execute_esdt_transfer( +// &third_user, +// &fs_setup.farm_wrapper, +// FARM_TOKEN_ID, +// 3, +// &rust_biguint!(farm_in_amount), +// |sc| { +// let _ = sc.claim_rewards(OptionalValue::None); +// }, +// ) +// .assert_ok(); + +// // random user tx to collect rewards +// let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); +// fs_setup.b_mock.set_esdt_balance( +// &rand_user, +// FARMING_TOKEN_ID, +// &rust_biguint!(USER_TOTAL_RIDE_TOKENS), +// ); + +// fs_setup.set_user_energy(&rand_user, 1, 6, 1); +// fs_setup.set_block_epoch(6); +// fs_setup.set_block_nonce(100); + +// fs_setup +// .b_mock +// .execute_esdt_transfer( +// &rand_user, +// &fs_setup.farm_wrapper, +// FARMING_TOKEN_ID, +// 0, +// &rust_biguint!(10), +// |sc| { +// let _ = sc.stake_farm_endpoint(OptionalValue::None); +// }, +// ) +// .assert_ok(); + +// fs_setup +// .b_mock +// .execute_esdt_transfer( +// &rand_user, +// &fs_setup.farm_wrapper, +// FARM_TOKEN_ID, +// 7, +// &rust_biguint!(10), +// |sc| { +// let _ = sc.unstake_farm(OptionalValue::None); +// }, +// ) +// .assert_ok(); + +// fs_setup.set_block_epoch(7); +// fs_setup.set_user_energy(&first_user, 10_000, 7, 10); +// fs_setup.set_user_energy(&second_user, 10_000, 7, 10); +// fs_setup.set_user_energy(&third_user, 10_000, 7, 10); + +// // First user claims +// let mut base_rewards1 = 33; +// let mut boosted_rewards1 = 0; +// let mut expected_reward_token_out = base_rewards1 + boosted_rewards1; +// first_user_total_rewards += expected_reward_token_out; +// let mut expected_farming_token_balance = +// rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); +// let mut expected_reward_per_share = 3_333_333u64; +// fs_setup.claim_rewards( +// &first_user, +// farm_in_amount, +// 4, +// expected_reward_token_out, +// &expected_farming_token_balance, +// &expected_farming_token_balance, +// 9, +// expected_reward_per_share, +// ); + +// // Boosted rewards config is added +// fs_setup.set_boosted_yields_factors(); +// fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + +// // random user tx to collect rewards +// fs_setup.set_user_energy(&rand_user, 1, 13, 1); +// fs_setup.set_block_epoch(13); +// fs_setup.set_block_nonce(200); + +// fs_setup +// .b_mock +// .execute_esdt_transfer( +// &rand_user, +// &fs_setup.farm_wrapper, +// FARMING_TOKEN_ID, +// 0, +// &rust_biguint!(10), +// |sc| { +// let _ = sc.stake_farm_endpoint(OptionalValue::None); +// }, +// ) +// .assert_ok(); + +// fs_setup +// .b_mock +// .execute_esdt_transfer( +// &rand_user, +// &fs_setup.farm_wrapper, +// FARM_TOKEN_ID, +// 10, +// &rust_biguint!(10), +// |sc| { +// let _ = sc.unstake_farm(OptionalValue::None); +// }, +// ) +// .assert_ok(); + +// fs_setup.set_block_epoch(14); +// fs_setup.set_user_energy(&first_user, 10_000, 14, 10); +// fs_setup.set_user_energy(&second_user, 10_000, 14, 10); +// fs_setup.set_user_energy(&third_user, 10_000, 14, 10); + +// // First and second users claim +// base_rewards1 = 25; +// boosted_rewards1 = 8; +// expected_reward_token_out = base_rewards1 + boosted_rewards1; +// first_user_total_rewards += expected_reward_token_out; +// expected_farming_token_balance += expected_reward_token_out; +// expected_reward_per_share = 5_833_333u64; +// fs_setup.claim_rewards( +// &first_user, +// farm_in_amount, +// 9, +// expected_reward_token_out, +// &expected_farming_token_balance, +// &expected_farming_token_balance, +// 12, +// expected_reward_per_share, +// ); + +// let mut base_rewards2 = 33 + 25; +// let mut boosted_rewards2 = 8; +// let mut expected_reward_token_out2 = base_rewards2 + boosted_rewards2; +// second_user_total_rewards += expected_reward_token_out2; +// let mut expected_farming_token_balance2 = +// rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out2); +// fs_setup.claim_rewards( +// &second_user, +// farm_in_amount, +// 5, +// expected_reward_token_out2, +// &expected_farming_token_balance2, +// &expected_farming_token_balance2, +// 13, +// expected_reward_per_share, +// ); + +// // Boosted rewards config is updated +// fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE * 2); // 50% + +// // random user tx to collect rewards +// fs_setup.set_user_energy(&rand_user, 1, 20, 1); +// fs_setup.set_block_epoch(20); +// fs_setup.set_block_nonce(300); + +// fs_setup +// .b_mock +// .execute_esdt_transfer( +// &rand_user, +// &fs_setup.farm_wrapper, +// FARMING_TOKEN_ID, +// 0, +// &rust_biguint!(10), +// |sc| { +// let _ = sc.stake_farm_endpoint(OptionalValue::None); +// }, +// ) +// .assert_ok(); + +// fs_setup +// .b_mock +// .execute_esdt_transfer( +// &rand_user, +// &fs_setup.farm_wrapper, +// FARM_TOKEN_ID, +// 14, +// &rust_biguint!(10), +// |sc| { +// let _ = sc.unstake_farm(OptionalValue::None); +// }, +// ) +// .assert_ok(); + +// fs_setup.set_block_epoch(21); +// fs_setup.set_user_energy(&first_user, 10_000, 21, 10); +// fs_setup.set_user_energy(&second_user, 10_000, 21, 10); +// fs_setup.set_user_energy(&third_user, 10_000, 21, 10); + +// // All users claim - boosted rewards 50% +// base_rewards1 = 16; +// boosted_rewards1 = 16; +// expected_reward_token_out = base_rewards1 + boosted_rewards1; +// first_user_total_rewards += expected_reward_token_out; +// expected_farming_token_balance += expected_reward_token_out; +// expected_reward_per_share = 7_499_999u64; +// fs_setup.claim_rewards( +// &first_user, +// farm_in_amount, +// 12, +// expected_reward_token_out, +// &expected_farming_token_balance, +// &expected_farming_token_balance, +// 16, +// expected_reward_per_share, +// ); + +// base_rewards2 = 16; +// boosted_rewards2 = 16; +// expected_reward_token_out2 = base_rewards2 + boosted_rewards2; +// second_user_total_rewards += expected_reward_token_out2; +// expected_farming_token_balance2 += expected_reward_token_out2; +// fs_setup.claim_rewards( +// &second_user, +// farm_in_amount, +// 13, +// expected_reward_token_out2, +// &expected_farming_token_balance2, +// &expected_farming_token_balance2, +// 17, +// expected_reward_per_share, +// ); + +// let base_rewards3 = 74; +// let boosted_rewards3 = 24; +// let expected_reward_token_out3 = base_rewards3 + boosted_rewards3; +// third_user_total_rewards += expected_reward_token_out3; +// let expected_farming_token_balance3 = +// rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out3); +// fs_setup.claim_rewards( +// &third_user, +// farm_in_amount, +// 6, +// expected_reward_token_out3, +// &expected_farming_token_balance3, +// &expected_farming_token_balance3, +// 18, +// expected_reward_per_share, +// ); + +// assert!( +// first_user_total_rewards == second_user_total_rewards +// && first_user_total_rewards == third_user_total_rewards +// ); +// } #[test] fn claim_only_boosted_rewards_per_week_test() {