-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit test for unstake endpoint
- Loading branch information
1 parent
c2a140a
commit abf386a
Showing
10 changed files
with
1,255 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
legacy-contracts/farm-staking-proxy-legacy/tests/constants/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Pair constants | ||
|
||
pub const PAIR_WASM_PATH: &'static str = "pair/output/pair.wasm"; | ||
Check warning on line 3 in legacy-contracts/farm-staking-proxy-legacy/tests/constants/mod.rs GitHub Actions / clippy[clippy] legacy-contracts/farm-staking-proxy-legacy/tests/constants/mod.rs#L3
Raw output
|
||
pub const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-abcdef"; | ||
pub const RIDE_TOKEN_ID: &[u8] = b"RIDE-abcdef"; | ||
pub const LP_TOKEN_ID: &[u8] = b"LPTOK-abcdef"; // also farming token ID for LP farm | ||
|
||
pub const USER_TOTAL_WEGLD_TOKENS: u64 = 2_000_000_000; | ||
pub const USER_TOTAL_RIDE_TOKENS: u64 = 2_000_000_000; | ||
pub const USER_TOTAL_LP_TOKENS: u64 = 1_001_000_000; | ||
|
||
pub const BLOCK_NONCE_FIRST_ADD_LIQ: u64 = 5; | ||
pub const BLOCK_NONCE_SECOND_ADD_LIQ: u64 = 6; | ||
pub const BLOCK_NONCE_AFTER_PAIR_SETUP: u64 = 100; | ||
|
||
// LP farm constants | ||
|
||
pub const FARM_WASM_PATH: &'static str = "farm/output/farm.wasm"; | ||
Check warning on line 18 in legacy-contracts/farm-staking-proxy-legacy/tests/constants/mod.rs GitHub Actions / clippy[clippy] legacy-contracts/farm-staking-proxy-legacy/tests/constants/mod.rs#L18
Raw output
|
||
pub const LP_FARM_TOKEN_ID: &[u8] = b"LPFARM-abcdef"; | ||
pub const DIVISION_SAFETY_CONSTANT: u64 = 1_000_000_000_000; | ||
pub const MIN_FARMING_EPOCHS: u8 = 2; | ||
pub const PENALTY_PERCENT: u64 = 10; | ||
pub const LP_FARM_PER_BLOCK_REWARD_AMOUNT: u64 = 5_000; | ||
|
||
// Energy factory constants | ||
|
||
pub const EPOCHS_IN_YEAR: u64 = 360; | ||
pub static MEX_TOKEN_ID: &[u8] = b"MEX-123456"; | ||
pub static LOCKED_TOKEN_ID: &[u8] = b"LOCKED-123456"; | ||
pub static LEGACY_LOCKED_TOKEN_ID: &[u8] = b"LEGACY-123456"; | ||
pub static LOCK_OPTIONS: &[u64] = &[EPOCHS_IN_YEAR, 5 * EPOCHS_IN_YEAR, 10 * EPOCHS_IN_YEAR]; // 1, 5 or 10 years | ||
pub static PENALTY_PERCENTAGES: &[u64] = &[4_000, 6_000, 8_000]; | ||
|
||
// Staking farm constants | ||
|
||
pub const STAKING_FARM_WASM_PATH: &str = "farm-staking/output/farm-staking.wasm"; | ||
pub const STAKING_REWARD_TOKEN_ID: &[u8] = RIDE_TOKEN_ID; | ||
pub const STAKING_TOKEN_ID: &[u8] = RIDE_TOKEN_ID; | ||
pub const STAKING_FARM_TOKEN_ID: &[u8] = b"STKFARM-abcdef"; | ||
pub const MAX_APR: u64 = 5_000; // 50% | ||
pub const UNBOND_EPOCHS: u64 = 10; | ||
pub const STAKING_FARM_PER_BLOCK_REWARD_AMOUNT: u64 = 1_000; | ||
pub const REWARD_CAPACITY: u64 = 1_000_000_000_000; | ||
|
||
// Proxy constants | ||
|
||
pub const PROXY_WASM_PATH: &str = "farm-staking-proxy/output/farm-staking-proxy"; | ||
pub const DUAL_YIELD_TOKEN_ID: &[u8] = b"DYIELD-abcdef"; |
149 changes: 149 additions & 0 deletions
149
legacy-contracts/farm-staking-proxy-legacy/tests/staking_farm_with_lp.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#![allow(deprecated)] | ||
|
||
pub mod constants; | ||
pub mod staking_farm_with_lp_external_contracts; | ||
pub mod staking_farm_with_lp_staking_contract_interactions; | ||
pub mod staking_farm_with_lp_staking_contract_setup; | ||
|
||
multiversx_sc::imports!(); | ||
|
||
use common_structs::FarmTokenAttributes; | ||
use constants::*; | ||
use farm_staking_proxy_legacy::dual_yield_token::DualYieldTokenAttributes; | ||
|
||
use farm_staking::stake_farm::StakeFarmModule; | ||
use farm_with_locked_rewards::Farm; | ||
use multiversx_sc_scenario::{ | ||
imports::TxTokenTransfer, managed_address, managed_biguint, rust_biguint, DebugApi, | ||
}; | ||
use pair::pair_actions::add_liq::AddLiquidityModule; | ||
use staking_farm_with_lp_staking_contract_interactions::*; | ||
|
||
#[test] | ||
fn test_all_setup() { | ||
let _ = FarmStakingSetup::new( | ||
pair::contract_obj, | ||
farm_with_locked_rewards::contract_obj, | ||
energy_factory::contract_obj, | ||
farm_staking::contract_obj, | ||
farm_staking_proxy_legacy::contract_obj, | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_unstake_from_legacy_proxy() { | ||
let mut setup = FarmStakingSetup::new( | ||
pair::contract_obj, | ||
farm_with_locked_rewards::contract_obj, | ||
energy_factory::contract_obj, | ||
farm_staking::contract_obj, | ||
farm_staking_proxy_legacy::contract_obj, | ||
); | ||
|
||
DebugApi::dummy(); | ||
setup | ||
.b_mock | ||
.set_block_nonce(BLOCK_NONCE_AFTER_PAIR_SETUP + 20); | ||
setup.b_mock.set_block_epoch(20); | ||
|
||
let token_amount = 1_000_000_000u64; | ||
|
||
let payments = vec![ | ||
TxTokenTransfer { | ||
token_identifier: WEGLD_TOKEN_ID.to_vec(), | ||
nonce: 0, | ||
value: rust_biguint!(token_amount), | ||
}, | ||
TxTokenTransfer { | ||
token_identifier: RIDE_TOKEN_ID.to_vec(), | ||
nonce: 0, | ||
value: rust_biguint!(token_amount), | ||
}, | ||
]; | ||
setup | ||
.b_mock | ||
.execute_esdt_multi_transfer(&setup.user_addr, &setup.pair_wrapper, &payments, |sc| { | ||
sc.add_liquidity(managed_biguint!(1u64), managed_biguint!(1u64)); | ||
}) | ||
.assert_ok(); | ||
|
||
setup | ||
.b_mock | ||
.execute_esdt_transfer( | ||
&setup.user_addr, | ||
&setup.lp_farm_wrapper, | ||
LP_TOKEN_ID, | ||
0, | ||
&rust_biguint!(token_amount), | ||
|sc| { | ||
sc.enter_farm_endpoint(OptionalValue::None); | ||
}, | ||
) | ||
.assert_ok(); | ||
|
||
// Simulate enter proxy staking contract | ||
let lp_farm_token_attributes: FarmTokenAttributes<DebugApi> = FarmTokenAttributes { | ||
reward_per_share: managed_biguint!(0), | ||
entering_epoch: 20, | ||
compounded_reward: managed_biguint!(0), | ||
current_farm_amount: managed_biguint!(token_amount), | ||
original_owner: managed_address!(&setup.user_addr), | ||
}; | ||
setup.b_mock.set_nft_balance( | ||
setup.proxy_wrapper.address_ref(), | ||
LP_FARM_TOKEN_ID, | ||
1, | ||
&rust_biguint!(token_amount), | ||
&lp_farm_token_attributes, | ||
); | ||
setup.b_mock.set_esdt_balance( | ||
setup.proxy_wrapper.address_ref(), | ||
RIDE_TOKEN_ID, | ||
&rust_biguint!(token_amount), | ||
); | ||
|
||
setup | ||
.b_mock | ||
.execute_tx( | ||
setup.proxy_wrapper.address_ref(), | ||
&setup.staking_farm_wrapper, | ||
&rust_biguint!(0u64), | ||
|sc| { | ||
sc.stake_farm_through_proxy( | ||
managed_biguint!(token_amount), | ||
managed_address!(&setup.user_addr), | ||
); | ||
}, | ||
) | ||
.assert_ok(); | ||
|
||
let dual_yield_token_amount = token_amount; | ||
let dual_yield_token_attributes: DualYieldTokenAttributes<DebugApi> = | ||
DualYieldTokenAttributes { | ||
lp_farm_token_nonce: 1, | ||
lp_farm_token_amount: managed_biguint!(dual_yield_token_amount), | ||
staking_farm_token_nonce: 1, | ||
staking_farm_token_amount: managed_biguint!(dual_yield_token_amount), | ||
}; | ||
setup.b_mock.set_nft_balance( | ||
&setup.user_addr, | ||
DUAL_YIELD_TOKEN_ID, | ||
1, | ||
&rust_biguint!(dual_yield_token_amount), | ||
&dual_yield_token_attributes, | ||
); | ||
|
||
let expected_token_amount = 990_000_000u64; | ||
setup.unstake_proxy( | ||
1, | ||
dual_yield_token_amount, | ||
expected_token_amount, | ||
0, | ||
0, | ||
expected_token_amount, | ||
30, | ||
); | ||
|
||
setup.b_mock.set_block_epoch(30); | ||
setup.unbond_proxy(2, expected_token_amount, expected_token_amount); | ||
} |
Oops, something went wrong.