1
1
use super :: { mock:: * , testing_utils:: * } ;
2
2
use crate :: { BalanceOf , CapacityDetails , Error , Event , StakingAccountDetails } ;
3
3
use common_primitives:: {
4
- capacity:: { Nontransferable , StakingType , StakingType :: MaximumCapacity } ,
4
+ capacity:: {
5
+ Nontransferable , StakingType ,
6
+ StakingType :: { MaximumCapacity , ProviderBoost } ,
7
+ } ,
5
8
msa:: MessageSourceId ,
6
9
} ;
7
- use frame_benchmarking:: AnalysisChoice :: Max ;
8
10
use frame_support:: { assert_noop, assert_ok, traits:: WithdrawReasons } ;
9
11
use sp_runtime:: ArithmeticError ;
10
12
11
13
#[ test]
12
- fn stake_works ( ) {
14
+ fn stake_max_capacity_works ( ) {
13
15
new_test_ext ( ) . execute_with ( || {
14
16
let account = 200 ;
15
17
let target: MessageSourceId = 1 ;
@@ -53,6 +55,35 @@ fn stake_works() {
53
55
} ) ;
54
56
}
55
57
58
+ #[ test]
59
+ fn stake_rewards_works ( ) {
60
+ new_test_ext ( ) . execute_with ( || {
61
+ let account = 200 ;
62
+ let target: MessageSourceId = 1 ;
63
+ let amount = 50 ;
64
+ let capacity = 5 ;
65
+ register_provider ( target, String :: from ( "Foo" ) ) ;
66
+ assert_ok ! ( Capacity :: stake( RuntimeOrigin :: signed( account) , target, amount, ProviderBoost ) ) ;
67
+
68
+ // Check that StakingAccountLedger is updated.
69
+ let staking_account: StakingAccountDetails < Test > =
70
+ Capacity :: get_staking_account_for ( account) . unwrap ( ) ;
71
+
72
+ assert_eq ! ( staking_account. total, 50 ) ;
73
+ assert_eq ! ( staking_account. active, 50 ) ;
74
+ assert_eq ! ( staking_account. unlocking. len( ) , 0 ) ;
75
+ assert_eq ! ( staking_account. staking_type, ProviderBoost ) ;
76
+ assert_eq ! ( staking_account. last_rewards_claimed_at, None ) ;
77
+ assert_eq ! ( staking_account. stake_change_unlocking. len( ) , 0 ) ;
78
+
79
+ let events = staking_events ( ) ;
80
+ assert_eq ! ( events. first( ) . unwrap( ) , & Event :: Staked { account, target, amount, capacity } ) ;
81
+
82
+ assert_eq ! ( Balances :: locks( & account) [ 0 ] . amount, amount) ;
83
+ assert_eq ! ( Balances :: locks( & account) [ 0 ] . reasons, WithdrawReasons :: all( ) . into( ) ) ;
84
+ } ) ;
85
+ }
86
+
56
87
#[ test]
57
88
fn stake_errors_invalid_target_when_target_is_not_registered_provider ( ) {
58
89
new_test_ext ( ) . execute_with ( || {
@@ -331,7 +362,7 @@ fn ensure_can_stake_errors_with_zero_amount_not_allowed() {
331
362
let target: MessageSourceId = 1 ;
332
363
let amount = 0 ;
333
364
assert_noop ! (
334
- Capacity :: ensure_can_stake( & account, target, amount, MaximumCapacity ) ,
365
+ Capacity :: ensure_can_stake( & account, target, amount, & MaximumCapacity ) ,
335
366
Error :: <Test >:: ZeroAmountNotAllowed
336
367
) ;
337
368
} ) ;
@@ -369,7 +400,7 @@ fn ensure_can_stake_errors_invalid_target() {
369
400
let amount = 1 ;
370
401
371
402
assert_noop ! (
372
- Capacity :: ensure_can_stake( & account, target, amount, MaximumCapacity ) ,
403
+ Capacity :: ensure_can_stake( & account, target, amount, & MaximumCapacity ) ,
373
404
Error :: <Test >:: InvalidTarget
374
405
) ;
375
406
} ) ;
@@ -384,7 +415,7 @@ fn ensure_can_stake_errors_insufficient_staking_amount() {
384
415
register_provider ( target, String :: from ( "Foo" ) ) ;
385
416
386
417
assert_noop ! (
387
- Capacity :: ensure_can_stake( & account, target, amount, MaximumCapacity ) ,
418
+ Capacity :: ensure_can_stake( & account, target, amount, & MaximumCapacity ) ,
388
419
Error :: <Test >:: InsufficientStakingAmount
389
420
) ;
390
421
} ) ;
@@ -400,7 +431,7 @@ fn ensure_can_stake_is_successful() {
400
431
401
432
let staking_details = StakingAccountDetails :: < Test > :: default ( ) ;
402
433
assert_ok ! (
403
- Capacity :: ensure_can_stake( & account, target, amount, MaximumCapacity ) ,
434
+ Capacity :: ensure_can_stake( & account, target, amount, & MaximumCapacity ) ,
404
435
( staking_details, BalanceOf :: <Test >:: from( 10u64 ) )
405
436
) ;
406
437
} ) ;
0 commit comments