From 228653e0fc004fe81e8de02f39bfac1cec9a67cd Mon Sep 17 00:00:00 2001 From: Dino Pacandi Date: Wed, 19 Jun 2024 15:29:35 +0200 Subject: [PATCH] Additonal UT --- .../dapp-staking-v3/src/test/tests_types.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/pallets/dapp-staking-v3/src/test/tests_types.rs b/pallets/dapp-staking-v3/src/test/tests_types.rs index 4c8ae64b2..0ceaa3dc1 100644 --- a/pallets/dapp-staking-v3/src/test/tests_types.rs +++ b/pallets/dapp-staking-v3/src/test/tests_types.rs @@ -2242,6 +2242,59 @@ fn singular_staking_info_unstake_during_bep_is_ok() { assert_eq!(staking_info.previous_staked.era, era_2 - 1); } +#[test] +fn singular_staking_info_unstake_era_amount_pairs_are_ok() { + let period_number = 1; + let subperiod = Subperiod::BuildAndEarn; + + // 1. Unstake only reduces the amount from a the future era + { + let era = 3; + let stake_amount = 13; + let unstake_amount = 3; + let mut staking_info = SingularStakingInfo::new(period_number, subperiod); + staking_info.stake(stake_amount, era, Subperiod::BuildAndEarn); + + assert_eq!( + staking_info.unstake(unstake_amount, era, Subperiod::BuildAndEarn), + vec![(era + 1, unstake_amount)] + ); + } + + // 2. Unstake reduces the amount from the current & next era. + { + let era = 3; + let stake_amount = 17; + let unstake_amount = 5; + let mut staking_info = SingularStakingInfo::new(period_number, subperiod); + staking_info.stake(stake_amount, era, Subperiod::BuildAndEarn); + + assert_eq!( + staking_info + .clone() + .unstake(unstake_amount, era + 1, Subperiod::BuildAndEarn), + vec![(era + 1, unstake_amount), (era + 2, unstake_amount)] + ); + } + + // 3. Unstake reduces the amount from the current & next era. + // Unlike the previous example, entries are not aligned with the current era + { + let era = 3; + let stake_amount = 17; + let unstake_amount = 5; + let mut staking_info = SingularStakingInfo::new(period_number, subperiod); + staking_info.stake(stake_amount, era, Subperiod::BuildAndEarn); + + assert_eq!( + staking_info + .clone() + .unstake(unstake_amount, era + 2, Subperiod::BuildAndEarn), + vec![(era + 2, unstake_amount), (era + 3, unstake_amount)] + ); + } +} + #[test] fn contract_stake_amount_basic_get_checks_work() { // Sanity checks for empty struct