File tree 2 files changed +24
-4
lines changed
pallets/dapp-staking-v3/src/test
2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -86,9 +86,9 @@ impl MemorySnapshot {
86
86
/// Returns locked balance in dApp staking for the specified account.
87
87
/// In case no balance is locked, returns zero.
88
88
pub fn locked_balance ( & self , account : & AccountId ) -> Balance {
89
- self . ledger
90
- . get ( & account )
91
- . map_or ( Balance :: zero ( ) , |ledger| ledger . active_locked_amount ( ) )
89
+ self . ledger . get ( & account ) . map_or ( Balance :: zero ( ) , |ledger| {
90
+ ledger . locked + ledger . unlocking . iter ( ) . fold ( 0 , |acc , x| acc + x . amount )
91
+ } )
92
92
}
93
93
}
94
94
@@ -240,10 +240,15 @@ pub(crate) fn assert_lock(account: AccountId, amount: Balance) {
240
240
"Total locked balance should be increased by the amount locked."
241
241
) ;
242
242
243
+ let post_frozen_balance = Balances :: balance_frozen ( & FreezeReason :: DAppStaking . into ( ) , & account) ;
243
244
assert_eq ! (
244
245
init_frozen_balance + expected_lock_amount,
245
- Balances :: balance_frozen ( & FreezeReason :: DAppStaking . into ( ) , & account )
246
+ post_frozen_balance
246
247
) ;
248
+ assert ! (
249
+ Balances :: total_balance( & account) >= post_frozen_balance,
250
+ "Total balance should never be less than frozen balance."
251
+ )
247
252
}
248
253
249
254
/// Start the unlocking process for locked funds and assert success.
Original file line number Diff line number Diff line change @@ -3358,3 +3358,18 @@ fn fix_account_scenarios_work() {
3358
3358
) ;
3359
3359
} )
3360
3360
}
3361
+
3362
+ fn lock_correctly_considers_unlocking_amount ( ) {
3363
+ ExtBuilder :: build ( ) . execute_with ( || {
3364
+ // Lock the entire amount & immediately start the unlocking process
3365
+ let ( staker, unlock_amount) = ( 1 , 13 ) ;
3366
+ let total_balance = Balances :: total_balance ( & staker) ;
3367
+ assert_lock ( staker, total_balance) ;
3368
+ assert_unlock ( staker, unlock_amount) ;
3369
+
3370
+ assert_noop ! (
3371
+ DappStaking :: lock( RuntimeOrigin :: signed( staker) , 1 ) ,
3372
+ Error :: <Test >:: ZeroAmount
3373
+ ) ;
3374
+ } )
3375
+ }
You can’t perform that action at this time.
0 commit comments