@@ -57,7 +57,7 @@ fn period_info_basic_checks() {
57
57
assert_eq ! ( info. subperiod, Subperiod :: Voting ) ;
58
58
assert_eq ! ( info. next_subperiod_start_era, next_subperiod_start_era) ;
59
59
60
- // Voting period checks
60
+ // Voting subperiod checks
61
61
assert ! ( !info. is_next_period( next_subperiod_start_era - 1 ) ) ;
62
62
assert ! ( !info. is_next_period( next_subperiod_start_era) ) ;
63
63
assert ! ( !info. is_next_period( next_subperiod_start_era + 1 ) ) ;
@@ -68,7 +68,7 @@ fn period_info_basic_checks() {
68
68
] {
69
69
assert ! (
70
70
!info. is_next_period( era) ,
71
- "Cannot trigger 'true' in the Voting period type."
71
+ "Cannot trigger 'true' in the Voting subperiod type."
72
72
) ;
73
73
}
74
74
@@ -520,7 +520,7 @@ fn account_ledger_add_stake_amount_basic_example_with_different_subperiods_works
520
520
assert ! ( acc_ledger. staked. is_empty( ) ) ;
521
521
assert ! ( acc_ledger. staked_future. is_none( ) ) ;
522
522
523
- // 1st scenario - stake some amount in Voting period , and ensure values are as expected.
523
+ // 1st scenario - stake some amount in Voting subperiod , and ensure values are as expected.
524
524
let era_1 = 1 ;
525
525
let period_1 = 1 ;
526
526
let period_info_1 = PeriodInfo {
@@ -1775,7 +1775,7 @@ fn era_info_stake_works() {
1775
1775
// Sanity check
1776
1776
assert ! ( era_info. total_locked. is_zero( ) ) ;
1777
1777
1778
- // Add some voting period stake
1778
+ // Add some voting subperiod stake
1779
1779
let vp_stake_amount = 7 ;
1780
1780
era_info. add_stake_amount ( vp_stake_amount, Subperiod :: Voting ) ;
1781
1781
assert_eq ! ( era_info. total_staked_amount_next_era( ) , vp_stake_amount) ;
@@ -2080,7 +2080,7 @@ fn singular_staking_info_unstake_during_voting_is_ok() {
2080
2080
let vote_stake_amount_1 = 11 ;
2081
2081
staking_info. stake ( vote_stake_amount_1, era_1, Subperiod :: Voting ) ;
2082
2082
2083
- // Unstake some amount during `Voting` period, loyalty should remain as expected.
2083
+ // 1. Unstake some amount during `Voting` period, loyalty should remain as expected.
2084
2084
let unstake_amount_1 = 5 ;
2085
2085
assert_eq ! (
2086
2086
staking_info. unstake( unstake_amount_1, era_1, Subperiod :: Voting ) ,
@@ -2097,7 +2097,7 @@ fn singular_staking_info_unstake_during_voting_is_ok() {
2097
2097
"Stake era should remain valid."
2098
2098
) ;
2099
2099
2100
- // Fully unstake, attempting to underflow, and ensure loyalty flag has been removed.
2100
+ // 2. Fully unstake, attempting to underflow, and ensure loyalty flag has been removed.
2101
2101
let era_2 = era_1 + 2 ;
2102
2102
let remaining_stake = staking_info. total_staked_amount ( ) ;
2103
2103
assert_eq ! (
@@ -2151,8 +2151,21 @@ fn singular_staking_info_unstake_during_bep_is_ok() {
2151
2151
"Stake era should remain valid."
2152
2152
) ;
2153
2153
2154
- // 2nd scenario - unstake all of the amount staked during B&E period, and then some more.
2155
- // The point is to take a chunk from the voting period stake too.
2154
+ // 2nd scenario - Ensure that staked amount is larger than the previous stake amount, and then
2155
+ // unstake enough to result in some overflow of the stake delta.
2156
+ let bep_stake_amount_2 = 13 ;
2157
+ staking_info. stake ( bep_stake_amount_2, era_1, Subperiod :: BuildAndEarn ) ;
2158
+ let delta = staking_info. staked . total ( ) - staking_info. previous_staked . total ( ) ;
2159
+ let overflow = 1 ;
2160
+ let unstake_2 = delta + overflow;
2161
+
2162
+ assert_eq ! (
2163
+ staking_info. unstake( unstake_2, era_1, Subperiod :: BuildAndEarn ) ,
2164
+ vec![ ( era_1, overflow) , ( era_1 + 1 , unstake_2) ]
2165
+ ) ;
2166
+
2167
+ // 3rd scenario - unstake all of the amount staked during B&E period, and then some more.
2168
+ // The point is to take a chunk from the voting subperiod stake too.
2156
2169
let current_total_stake = staking_info. total_staked_amount ( ) ;
2157
2170
let current_bep_stake = staking_info. staked_amount ( Subperiod :: BuildAndEarn ) ;
2158
2171
let voting_stake_overflow = 2 ;
@@ -2161,7 +2174,7 @@ fn singular_staking_info_unstake_during_bep_is_ok() {
2161
2174
2162
2175
assert_eq ! (
2163
2176
staking_info. unstake( unstake_2, era_2, Subperiod :: BuildAndEarn ) ,
2164
- // Both amounts are the same since current stake is less than the previous one
2177
+ // Both amounts are the same since previous staked era is less than last staked era - 1
2165
2178
vec![ ( era_2 - 1 , unstake_2) , ( era_2, unstake_2) ]
2166
2179
) ;
2167
2180
assert_eq ! (
@@ -2177,7 +2190,7 @@ fn singular_staking_info_unstake_during_bep_is_ok() {
2177
2190
. is_zero( ) ) ;
2178
2191
assert ! (
2179
2192
!staking_info. is_loyal( ) ,
2180
- "Loyalty flag should have been removed due to non-zero voting period unstake"
2193
+ "Loyalty flag should have been removed due to non-zero voting subperiod unstake"
2181
2194
) ;
2182
2195
assert_eq ! ( staking_info. era( ) , era_2) ;
2183
2196
}
0 commit comments