From fc7bb6e117046c045122dbb943d32df13df879bb Mon Sep 17 00:00:00 2001 From: Dorin Marian Iancu Date: Thu, 31 Oct 2024 11:03:27 +0200 Subject: [PATCH] fix proxy dex tests --- Cargo.lock | 1 + locked-asset/proxy_dex/Cargo.toml | 3 + .../tests/proxy_dex_test_setup/mod.rs | 63 ++- .../proxy_dex/tests/proxy_farm_test.rs | 517 +++++++++--------- locked-asset/proxy_dex/tests/proxy_lp_test.rs | 9 + 5 files changed, 335 insertions(+), 258 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ab4a6a68..d53d04fa9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1610,6 +1610,7 @@ dependencies = [ "rewards", "sc_whitelist_module", "simple-lock", + "timestamp-oracle", "token_merge_helper", "token_send", "utils", diff --git a/locked-asset/proxy_dex/Cargo.toml b/locked-asset/proxy_dex/Cargo.toml index e5023a79d..f75ae8c71 100644 --- a/locked-asset/proxy_dex/Cargo.toml +++ b/locked-asset/proxy_dex/Cargo.toml @@ -88,3 +88,6 @@ path = "../../common/modules/farm/rewards" [dev-dependencies.farm-boosted-yields] path = "../../energy-integration/farm-boosted-yields" + +[dev-dependencies.timestamp-oracle] +path = "../../energy-integration/timestamp-oracle" diff --git a/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs b/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs index 7b5c64d67..64fb27a0d 100644 --- a/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs +++ b/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs @@ -1,10 +1,15 @@ #![allow(dead_code)] -use common_structs::{LockedAssetTokenAttributesEx, UnlockMilestoneEx, UnlockScheduleEx}; +use common_structs::{ + LockedAssetTokenAttributesEx, Timestamp, UnlockMilestoneEx, UnlockScheduleEx, +}; use config::ConfigModule; use energy_factory::{locked_token_transfer::LockedTokenTransferModule, SimpleLockEnergy}; use energy_query::EnergyQueryModule; -use farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule; +use farm_boosted_yields::{ + boosted_yields_factors::BoostedYieldsFactorsModule, + custom_reward_logic::CustomRewardLogicModule, +}; use farm_token::FarmTokenModule; use farm_with_locked_rewards::Farm as FarmLocked; use locking_module::lock_with_energy_module::LockWithEnergyModule; @@ -27,6 +32,7 @@ use proxy_dex::{ }; use sc_whitelist_module::SCWhitelistModule; use simple_lock::locked_token::{LockedTokenAttributes, LockedTokenModule}; +use timestamp_oracle::{epoch_to_timestamp::EpochToTimestampModule, TimestampOracle}; // General pub static MEX_TOKEN_ID: &[u8] = b"MEX-123456"; @@ -57,12 +63,20 @@ pub static PENALTY_PERCENTAGES: &[u64] = &[4_000, 6_000, 8_000]; pub static WRAPPED_LP_TOKEN_ID: &[u8] = b"WPLP-123456"; pub static WRAPPED_FARM_TOKEN_ID: &[u8] = b"WPFARM-123456"; -pub struct ProxySetup -where +pub const TIMESTAMP_PER_EPOCH: Timestamp = 24 * 60 * 60; + +pub struct ProxySetup< + ProxyObjBuilder, + PairObjBuilder, + FarmLockedObjBuilder, + SimpleLockObjBuilder, + TimestampOracleObjBuilder, +> where ProxyObjBuilder: 'static + Copy + Fn() -> proxy_dex::ContractObj, PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmLockedObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, SimpleLockObjBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, + TimestampOracleObjBuilder: 'static + Copy + Fn() -> timestamp_oracle::ContractObj, { pub b_mock: BlockchainStateWrapper, pub owner: Address, @@ -74,21 +88,37 @@ where ContractObjWrapper, FarmLockedObjBuilder>, pub simple_lock_wrapper: ContractObjWrapper, SimpleLockObjBuilder>, + pub timestamp_oracle_wrapper: + ContractObjWrapper, TimestampOracleObjBuilder>, } -impl - ProxySetup +impl< + ProxyObjBuilder, + PairObjBuilder, + FarmLockedObjBuilder, + SimpleLockObjBuilder, + TimestampOracleObjBuilder, + > + ProxySetup< + ProxyObjBuilder, + PairObjBuilder, + FarmLockedObjBuilder, + SimpleLockObjBuilder, + TimestampOracleObjBuilder, + > where ProxyObjBuilder: 'static + Copy + Fn() -> proxy_dex::ContractObj, PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmLockedObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, SimpleLockObjBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, + TimestampOracleObjBuilder: 'static + Copy + Fn() -> timestamp_oracle::ContractObj, { pub fn new( proxy_builder: ProxyObjBuilder, pair_builder: PairObjBuilder, farm_locked_builder: FarmLockedObjBuilder, simple_lock_builder: SimpleLockObjBuilder, + timestamp_oracle_builder: TimestampOracleObjBuilder, ) -> Self { DebugApi::dummy(); @@ -99,6 +129,23 @@ where let second_user = b_mock.create_user_account(&rust_zero); b_mock.set_block_epoch(1); + b_mock.set_block_timestamp(TIMESTAMP_PER_EPOCH); + + let timestamp_oracle_wrapper = b_mock.create_sc_account( + &rust_zero, + Some(&owner), + timestamp_oracle_builder, + "timestamp oracle", + ); + b_mock + .execute_tx(&owner, ×tamp_oracle_wrapper, &rust_zero, |sc| { + sc.init(0); + + for i in 0..=100 { + sc.set_start_timestamp_for_epoch(i, i * TIMESTAMP_PER_EPOCH + 1); + } + }) + .assert_ok(); let pair_wrapper = setup_pair(&mut b_mock, &owner, pair_builder); let simple_lock_wrapper = setup_simple_lock(&mut b_mock, &owner, simple_lock_builder); @@ -107,6 +154,7 @@ where &owner, farm_locked_builder, simple_lock_wrapper.address_ref(), + timestamp_oracle_wrapper.address_ref(), ); let proxy_wrapper = setup_proxy( &mut b_mock, @@ -230,6 +278,7 @@ where pair_wrapper, farm_locked_wrapper, simple_lock_wrapper, + timestamp_oracle_wrapper, } } } @@ -290,6 +339,7 @@ fn setup_farm_locked( owner: &Address, farm_builder: FarmLockedObjBuilder, simple_lock_addr: &Address, + timestamp_oracle_addr: &Address, ) -> ContractObjWrapper, FarmLockedObjBuilder> where FarmLockedObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, @@ -336,6 +386,7 @@ where sc.set_lock_epochs(EPOCHS_IN_YEAR); sc.energy_factory_address() .set(managed_address!(simple_lock_addr)); + sc.set_timestamp_oracle_address(managed_address!(timestamp_oracle_addr)); }) .assert_ok(); diff --git a/locked-asset/proxy_dex/tests/proxy_farm_test.rs b/locked-asset/proxy_dex/tests/proxy_farm_test.rs index 46d74f486..7359f6f1b 100644 --- a/locked-asset/proxy_dex/tests/proxy_farm_test.rs +++ b/locked-asset/proxy_dex/tests/proxy_farm_test.rs @@ -17,6 +17,7 @@ use proxy_dex::{ proxy_farm::ProxyFarmModule, proxy_pair::ProxyPairModule, wrapped_farm_attributes::WrappedFarmTokenAttributes, wrapped_farm_token_merge::WrappedFarmTokenMerge, + wrapped_lp_attributes::WrappedLpTokenAttributes, }; use proxy_dex_test_setup::*; use simple_lock::locked_token::LockedTokenAttributes; @@ -28,6 +29,7 @@ fn farm_proxy_setup_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); } @@ -38,6 +40,7 @@ fn farm_proxy_actions_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -258,258 +261,255 @@ fn farm_proxy_actions_test() { ); } -// TODO: Fix later - -// #[test] -// fn farm_with_wrapped_lp_test() { -// let mut setup = ProxySetup::new( -// proxy_dex::contract_obj, -// pair::contract_obj, -// farm_with_locked_rewards::contract_obj, -// energy_factory::contract_obj, -// ); - -// setup -// .b_mock -// .execute_tx( -// &setup.owner, -// &setup.farm_locked_wrapper, -// &rust_biguint!(0), -// |sc| { -// sc.farming_token_id().set(&managed_token_id!(LP_TOKEN_ID)); - -// // set produce rewards to false for easier calculation -// sc.produce_rewards_enabled().set(false); -// }, -// ) -// .assert_ok(); - -// setup.b_mock.set_esdt_local_roles( -// setup.farm_locked_wrapper.address_ref(), -// LP_TOKEN_ID, -// &[EsdtLocalRole::Burn], -// ); - -// let first_user = setup.first_user.clone(); -// let locked_token_amount = rust_biguint!(1_000_000_000); -// let other_token_amount = rust_biguint!(500_000_000); -// let expected_lp_token_amount = rust_biguint!(499_999_000); - -// // set the price to 1 EGLD = 2 MEX -// let payments = vec![ -// TxTokenTransfer { -// token_identifier: LOCKED_TOKEN_ID.to_vec(), -// nonce: 1, -// value: locked_token_amount.clone(), -// }, -// TxTokenTransfer { -// token_identifier: WEGLD_TOKEN_ID.to_vec(), -// nonce: 0, -// value: other_token_amount.clone(), -// }, -// ]; - -// // add liquidity -// let pair_addr = setup.pair_wrapper.address_ref().clone(); -// setup -// .b_mock -// .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { -// sc.add_liquidity_proxy( -// managed_address!(&pair_addr), -// managed_biguint!(locked_token_amount.to_u64().unwrap()), -// managed_biguint!(other_token_amount.to_u64().unwrap()), -// ); -// }) -// .assert_ok(); - -// setup.b_mock.check_nft_balance( -// &first_user, -// WRAPPED_LP_TOKEN_ID, -// 1, -// &expected_lp_token_amount, -// Some(&WrappedLpTokenAttributes:: { -// locked_tokens: EsdtTokenPayment { -// token_identifier: managed_token_id!(LOCKED_TOKEN_ID), -// token_nonce: 1, -// amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), -// }, -// lp_token_id: managed_token_id!(LP_TOKEN_ID), -// lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), -// }), -// ); - -// let block_epoch = 1u64; -// let user_balance = USER_BALANCE; -// setup -// .b_mock -// .execute_query(&setup.simple_lock_wrapper, |sc| { -// let unlock_epoch = LOCK_OPTIONS[0]; -// let lock_epochs = unlock_epoch - block_epoch; -// let expected_energy_amount = -// BigInt::from((user_balance) as i64) * BigInt::from(lock_epochs as i64); -// let expected_energy = Energy::new( -// expected_energy_amount, -// block_epoch, -// managed_biguint!(user_balance), -// ); -// let actual_energy = -// sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); -// assert_eq!(expected_energy, actual_energy); -// }) -// .assert_ok(); - -// let farm_locked_addr = setup.farm_locked_wrapper.address_ref().clone(); - -// //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// - -// let mut current_epoch = 5; -// setup.b_mock.set_block_epoch(current_epoch); - -// setup -// .b_mock -// .execute_esdt_transfer( -// &first_user, -// &setup.proxy_wrapper, -// WRAPPED_LP_TOKEN_ID, -// 1, -// &expected_lp_token_amount, -// |sc| { -// sc.enter_farm_proxy_endpoint( -// managed_address!(&farm_locked_addr), -// OptionalValue::None, -// ); -// }, -// ) -// .assert_ok(); - -// let expected_energy = rust_biguint!(LOCK_OPTIONS[0] - current_epoch) * USER_BALANCE; -// setup -// .b_mock -// .execute_query(&setup.simple_lock_wrapper, |sc| { -// let managed_result = sc.get_energy_amount_for_user(managed_address!(&first_user)); -// let result = to_rust_biguint(managed_result); -// assert_eq!(result, expected_energy); -// }) -// .assert_ok(); - -// // check user balance -// setup.b_mock.check_nft_balance( -// &first_user, -// WRAPPED_FARM_TOKEN_ID, -// 1, -// &expected_lp_token_amount, -// Some(&WrappedFarmTokenAttributes:: { -// proxy_farming_token: EsdtTokenPayment { -// token_identifier: managed_token_id!(WRAPPED_LP_TOKEN_ID), -// token_nonce: 1, -// amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), -// }, -// farm_token: EsdtTokenPayment { -// token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), -// token_nonce: 1, -// amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), -// }, -// }), -// ); - -// // check proxy balance -// setup -// .b_mock -// .check_nft_balance::>( -// setup.proxy_wrapper.address_ref(), -// FARM_LOCKED_TOKEN_ID, -// 1, -// &expected_lp_token_amount, -// None, -// ); - -// // check farm balance -// setup.b_mock.check_esdt_balance( -// setup.farm_locked_wrapper.address_ref(), -// LP_TOKEN_ID, -// &expected_lp_token_amount, -// ); - -// current_epoch += 1; // applies penalty on exit -// setup.b_mock.set_block_epoch(current_epoch); -// setup.b_mock.set_block_nonce(100); - -// ////////////////////////////////////////////// EXIT FARM ///////////////////////////////////// -// // exit with partial amount -// setup -// .b_mock -// .execute_esdt_transfer( -// &first_user, -// &setup.proxy_wrapper, -// WRAPPED_FARM_TOKEN_ID, -// 1, -// &(expected_lp_token_amount.clone() / rust_biguint!(2)), -// |sc| { -// sc.exit_farm_proxy(managed_address!(&farm_locked_addr), OptionalValue::None); -// }, -// ) -// .assert_ok(); - -// let penalty_amount = rust_biguint!(0); //&expected_lp_token_amount / 2u64 * DEFAULT_PENALTY_PERCENT / MAX_PERCENT; - -// // check proxy received only part of LP tokens back -// setup.b_mock.check_esdt_balance( -// setup.proxy_wrapper.address_ref(), -// LP_TOKEN_ID, -// &(&expected_lp_token_amount / 2u64 - &penalty_amount), -// ); - -// // check user received half of the farm tokens back, and another new wrapped LP token -// setup.b_mock.check_nft_balance::( -// &first_user, -// WRAPPED_FARM_TOKEN_ID, -// 1, -// &(&expected_lp_token_amount / 2u64), -// None, -// ); - -// let locked_token_after_exit = rust_biguint!(500_000_000); -// setup.b_mock.check_nft_balance( -// &first_user, -// WRAPPED_LP_TOKEN_ID, -// 1, -// &(&expected_lp_token_amount / 2u64 - &penalty_amount), -// Some(&WrappedLpTokenAttributes:: { -// locked_tokens: EsdtTokenPayment::new( -// managed_token_id!(LOCKED_TOKEN_ID), -// 1, -// managed_biguint!(locked_token_after_exit.to_u64().unwrap()), -// ), -// lp_token_id: managed_token_id!(LP_TOKEN_ID), -// lp_token_amount: managed_biguint!( -// expected_lp_token_amount.to_u64().unwrap() // / 2u64 -// - penalty_amount.to_u64().unwrap() -// ), -// }), -// ); - -// // check user's energy -// setup -// .b_mock -// .execute_query(&setup.simple_lock_wrapper, |sc| { -// let new_user_balance = managed_biguint!(USER_BALANCE) -// - locked_token_amount.to_u64().unwrap() / 2u64 -// + locked_token_after_exit.to_u64().unwrap(); -// let expected_energy_amount = -// managed_biguint!(LOCK_OPTIONS[0] - current_epoch) * &new_user_balance; - -// let expected_energy = Energy::new( -// BigInt::from(expected_energy_amount), -// current_epoch, -// new_user_balance, -// ); -// let actual_energy = -// sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); - -// assert_eq!(actual_energy, expected_energy); -// }) -// .assert_ok(); -// } +#[test] +fn farm_with_wrapped_lp_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + timestamp_oracle::contract_obj, + ); + + setup + .b_mock + .execute_tx( + &setup.owner, + &setup.farm_locked_wrapper, + &rust_biguint!(0), + |sc| { + sc.farming_token_id().set(&managed_token_id!(LP_TOKEN_ID)); + + // set produce rewards to false for easier calculation + sc.produce_rewards_enabled().set(false); + }, + ) + .assert_ok(); + + setup.b_mock.set_esdt_local_roles( + setup.farm_locked_wrapper.address_ref(), + LP_TOKEN_ID, + &[EsdtLocalRole::Burn], + ); + + let first_user = setup.first_user.clone(); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap()), + managed_biguint!(other_token_amount.to_u64().unwrap()), + ); + }) + .assert_ok(); + + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + let block_epoch = 1u64; + let user_balance = USER_BALANCE; + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let unlock_epoch = LOCK_OPTIONS[0]; + let lock_epochs = unlock_epoch - block_epoch; + let expected_energy_amount = + BigInt::from((user_balance) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(user_balance), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + let farm_locked_addr = setup.farm_locked_wrapper.address_ref().clone(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + let mut current_epoch = 5; + setup.b_mock.set_block_epoch(current_epoch); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + let expected_energy = rust_biguint!(LOCK_OPTIONS[0] - current_epoch) * USER_BALANCE; + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let managed_result = sc.get_energy_amount_for_user(managed_address!(&first_user)); + let result = to_rust_biguint(managed_result); + assert_eq!(result, expected_energy); + }) + .assert_ok(); + + // check user balance + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 1, + &expected_lp_token_amount, + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(WRAPPED_LP_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }, + }), + ); + + // check proxy balance + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + FARM_LOCKED_TOKEN_ID, + 1, + &expected_lp_token_amount, + None, + ); + + // check farm balance + setup.b_mock.check_esdt_balance( + setup.farm_locked_wrapper.address_ref(), + LP_TOKEN_ID, + &expected_lp_token_amount, + ); + + current_epoch += 1; // applies penalty on exit + setup.b_mock.set_block_epoch(current_epoch); + setup.b_mock.set_block_nonce(100); + + ////////////////////////////////////////////// EXIT FARM ///////////////////////////////////// + // exit with partial amount + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 1, + &(expected_lp_token_amount.clone() / rust_biguint!(2)), + |sc| { + sc.exit_farm_proxy(managed_address!(&farm_locked_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + let penalty_amount = rust_biguint!(0); //&expected_lp_token_amount / 2u64 * DEFAULT_PENALTY_PERCENT / MAX_PERCENT; + + // check proxy received only part of LP tokens back + setup.b_mock.check_esdt_balance( + setup.proxy_wrapper.address_ref(), + LP_TOKEN_ID, + &(&expected_lp_token_amount / 2u64 - &penalty_amount), + ); + + // check user received half of the farm tokens back, and another new wrapped LP token + setup.b_mock.check_nft_balance::( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 1, + &(&expected_lp_token_amount / 2u64), + None, + ); + + let locked_token_after_exit = rust_biguint!(1_000_000_000); + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / 2u64 - &penalty_amount), + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment::new( + managed_token_id!(LOCKED_TOKEN_ID), + 1, + managed_biguint!(locked_token_after_exit.to_u64().unwrap()), + ), + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!( + expected_lp_token_amount.to_u64().unwrap() // / 2u64 + - penalty_amount.to_u64().unwrap() + ), + }), + ); + + // check user's energy + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let new_user_balance = managed_biguint!(USER_BALANCE); + let expected_energy_amount = + managed_biguint!(LOCK_OPTIONS[0] - current_epoch) * &new_user_balance; + + let expected_energy = Energy::new( + BigInt::from(expected_energy_amount), + current_epoch, + new_user_balance, + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + + assert_eq!(actual_energy, expected_energy); + }) + .assert_ok(); +} #[test] fn farm_proxy_claim_energy_test() { @@ -518,6 +518,7 @@ fn farm_proxy_claim_energy_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_locked_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -656,6 +657,7 @@ fn farm_proxy_partial_exit_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_locked_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -834,6 +836,7 @@ fn farm_proxy_partial_exit_with_penalty_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_locked_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -1016,6 +1019,7 @@ fn different_farm_locked_token_nonce_merging_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -1185,6 +1189,7 @@ fn total_farm_mechanism_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -1416,6 +1421,7 @@ fn increase_proxy_farm_lkmex_energy() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -1497,6 +1503,7 @@ fn increase_proxy_farm_proxy_lp_energy() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); setup @@ -1737,6 +1744,7 @@ fn increase_proxy_farm_proxy_lp_energy_unlocked_tokens() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); setup @@ -1982,6 +1990,7 @@ fn increase_proxy_farm_proxy_lp_energy_partially_unlocked_tokens() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); setup @@ -2224,6 +2233,7 @@ fn original_caller_negative_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -2328,6 +2338,7 @@ fn total_farm_position_migration_through_proxy_dex_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -2463,6 +2474,7 @@ fn increase_proxy_farm_legacy_token_energy_negative_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); @@ -2506,6 +2518,7 @@ fn total_farm_position_migration_mechanism_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); diff --git a/locked-asset/proxy_dex/tests/proxy_lp_test.rs b/locked-asset/proxy_dex/tests/proxy_lp_test.rs index 17572d758..510e5e92f 100644 --- a/locked-asset/proxy_dex/tests/proxy_lp_test.rs +++ b/locked-asset/proxy_dex/tests/proxy_lp_test.rs @@ -25,6 +25,7 @@ fn setup_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); } @@ -35,6 +36,7 @@ fn add_remove_liquidity_proxy_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let full_balance = rust_biguint!(USER_BALANCE); @@ -232,6 +234,7 @@ fn tripple_add_liquidity_proxy_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let full_balance = rust_biguint!(USER_BALANCE); @@ -503,6 +506,7 @@ fn wrapped_same_nonce_lp_token_merge_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let locked_token_amount = rust_biguint!(1_000_000_000); @@ -629,6 +633,7 @@ fn wrapped_different_nonce_lp_token_merge_test() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let user = setup.first_user.clone(); let user_balance = rust_biguint!(USER_BALANCE); @@ -806,6 +811,7 @@ fn increase_proxy_lp_token_energy() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let full_balance = rust_biguint!(USER_BALANCE); @@ -962,6 +968,7 @@ fn increase_proxy_lp_token_energy_unlocked_tokens() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let full_balance = rust_biguint!(USER_BALANCE); @@ -1126,6 +1133,7 @@ fn increase_proxy_lp_token_energy_partially_unlocked_tokens() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let full_balance = rust_biguint!(USER_BALANCE); @@ -1302,6 +1310,7 @@ fn increase_proxy_lp_legacy_token_energy() { pair::contract_obj, farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, + timestamp_oracle::contract_obj, ); let first_user = setup.first_user.clone(); let full_balance = rust_biguint!(USER_BALANCE);