@@ -17,7 +17,7 @@ use crate as collator_staking;
1717use crate :: {
1818 mock:: * , AutoCompoundSettings , CandidacyBondRelease , CandidacyBondReleaseReason ,
1919 CandidacyBondReleases , CandidateInfo , CandidateStake , CandidateStakeInfo , Candidates ,
20- ClaimableRewards , CollatorRewardPercentage , Config , Counters , CurrentSession ,
20+ ClaimableRewards , CollatorRewardPercentage , Config , Counter , Counters , CurrentSession ,
2121 DesiredCandidates , Error , Event , ExtraReward , IdentityCollator , Invulnerables ,
2222 LastAuthoredBlock , Layer , MinCandidacyBond , MinStake , NextSystemOperation , Operation ,
2323 ProducedBlocks , ReleaseQueues , ReleaseRequest , SessionRemovedCandidates , StakeTarget ,
@@ -3453,8 +3453,14 @@ mod collator_rewards {
34533453 )
34543454 } ) ) ;
34553455 assert_eq ! ( CollatorStaking :: calculate_unclaimed_rewards( & 4 ) , 15 ) ;
3456+ assert_eq ! ( Counters :: <Test >:: get( 4 ) . pending_claims, 1 ) ;
34563457 assert_ok ! ( CollatorStaking :: do_claim_rewards( & 4 ) ) ;
3457- assert_eq ! ( CandidateStake :: <Test >:: get( 4 , 4 ) . checkpoint, Counters :: <Test >:: get( 4 ) ) ;
3458+ // The candidate 4 left the candidacy, so the counter got erased.
3459+ assert_eq ! (
3460+ Counters :: <Test >:: get( 4 ) ,
3461+ Counter { value: FixedU128 :: zero( ) , pending_claims: 0 }
3462+ ) ;
3463+ assert ! ( !Counters :: <Test >:: contains_key( 4 ) ) ;
34583464 assert_eq ! ( ClaimableRewards :: <Test >:: get( ) , 0 ) ;
34593465 // Now we can see the reward.
34603466 System :: assert_has_event ( RuntimeEvent :: CollatorStaking ( Event :: StakingRewardReceived {
@@ -3565,7 +3571,10 @@ mod collator_rewards {
35653571 // Reward for staker when claiming.
35663572 assert_eq ! ( CollatorStaking :: calculate_unclaimed_rewards( & 4 ) , 28 ) ;
35673573 assert_ok ! ( CollatorStaking :: do_claim_rewards( & 4 ) ) ;
3568- assert_eq ! ( CandidateStake :: <Test >:: get( 4 , 4 ) . checkpoint, Counters :: <Test >:: get( 4 ) ) ;
3574+ assert_eq ! (
3575+ Counters :: <Test >:: get( 4 ) ,
3576+ Counter { value: CandidateStake :: <Test >:: get( 4 , 4 ) . checkpoint, pending_claims: 0 }
3577+ ) ;
35693578 assert_eq ! ( ClaimableRewards :: <Test >:: get( ) , 0 ) ;
35703579 System :: assert_has_event ( RuntimeEvent :: CollatorStaking ( Event :: StakingRewardReceived {
35713580 account : 4 ,
@@ -3677,7 +3686,10 @@ mod collator_rewards {
36773686 // Reward for staker.
36783687 assert_eq ! ( CollatorStaking :: calculate_unclaimed_rewards( & 4 ) , 15 ) ;
36793688 assert_ok ! ( CollatorStaking :: do_claim_rewards( & 4 ) ) ;
3680- assert_eq ! ( CandidateStake :: <Test >:: get( 4 , 4 ) . checkpoint, Counters :: <Test >:: get( 4 ) ) ;
3689+ assert_eq ! (
3690+ Counters :: <Test >:: get( 4 ) ,
3691+ Counter { value: CandidateStake :: <Test >:: get( 4 , 4 ) . checkpoint, pending_claims: 0 }
3692+ ) ;
36813693 assert_eq ! ( ClaimableRewards :: <Test >:: get( ) , 0 ) ;
36823694 System :: assert_has_event ( RuntimeEvent :: CollatorStaking ( Event :: StakingRewardReceived {
36833695 account : 4 ,
@@ -3814,15 +3826,21 @@ mod collator_rewards {
38143826 } ) ) ;
38153827 assert_eq ! ( CollatorStaking :: calculate_unclaimed_rewards( & 2 ) , 12 ) ;
38163828 assert_ok ! ( CollatorStaking :: do_claim_rewards( & 2 ) ) ;
3817- assert_eq ! ( CandidateStake :: <Test >:: get( 4 , 2 ) . checkpoint, Counters :: <Test >:: get( 4 ) ) ;
3829+ assert_eq ! (
3830+ Counters :: <Test >:: get( 4 ) ,
3831+ Counter { value: CandidateStake :: <Test >:: get( 4 , 2 ) . checkpoint, pending_claims: 1 }
3832+ ) ;
38183833 assert_eq ! ( ClaimableRewards :: <Test >:: get( ) , 16 ) ; // this remains to staker 3.
38193834 System :: assert_has_event ( RuntimeEvent :: CollatorStaking ( Event :: StakingRewardReceived {
38203835 account : 2 ,
38213836 amount : 12 ,
38223837 } ) ) ;
38233838 assert_eq ! ( CollatorStaking :: calculate_unclaimed_rewards( & 3 ) , 15 ) ;
38243839 assert_ok ! ( CollatorStaking :: do_claim_rewards( & 3 ) ) ;
3825- assert_eq ! ( CandidateStake :: <Test >:: get( 4 , 3 ) . checkpoint, Counters :: <Test >:: get( 4 ) ) ;
3840+ assert_eq ! (
3841+ Counters :: <Test >:: get( 4 ) ,
3842+ Counter { value: CandidateStake :: <Test >:: get( 4 , 3 ) . checkpoint, pending_claims: 0 }
3843+ ) ;
38263844 assert_eq ! ( ClaimableRewards :: <Test >:: get( ) , 1 ) ; // rounding issue
38273845 System :: assert_has_event ( RuntimeEvent :: CollatorStaking ( Event :: StakingRewardReceived {
38283846 account : 3 ,
@@ -3916,7 +3934,10 @@ mod collator_rewards {
39163934
39173935 // Check the collator's counter and staker's checkpoint. Both should be zero, as no
39183936 // rewards were distributed.
3919- assert_eq ! ( Counters :: <Test >:: get( 3 ) , FixedU128 :: zero( ) ) ;
3937+ assert_eq ! (
3938+ Counters :: <Test >:: get( 3 ) ,
3939+ Counter { value: FixedU128 :: zero( ) , pending_claims: 0 }
3940+ ) ;
39203941 assert_eq ! ( CandidateStake :: <Test >:: get( 3 , 4 ) . checkpoint, FixedU128 :: zero( ) ) ;
39213942
39223943 // Skip session 0, as there are no rewards for this session.
@@ -3934,7 +3955,10 @@ mod collator_rewards {
39343955 // Now we have 10 units of rewards being distributed. 20% goes to the collator, and 80%
39353956 // goes to stakers, so total 8 for stakers. The collator's counter should be the ratio
39363957 // between the rewards obtained and the total stake deposited in it.
3937- assert_eq ! ( Counters :: <Test >:: get( 4 ) , FixedU128 :: from_rational( 8 , 40 ) ) ;
3958+ assert_eq ! (
3959+ Counters :: <Test >:: get( 4 ) ,
3960+ Counter { value: FixedU128 :: from_rational( 8 , 40 ) , pending_claims: 1 }
3961+ ) ;
39383962
39393963 // The current checkpoint does not vary, as the staker did not claim the rewards yet.
39403964 assert_eq ! ( CandidateStake :: <Test >:: get( 4 , 3 ) . checkpoint, FixedU128 :: zero( ) ) ;
@@ -3962,7 +3986,10 @@ mod collator_rewards {
39623986 ) ) ;
39633987
39643988 // The checkpoint should be equal to the candidate's current counter.
3965- assert_eq ! ( Counters :: <Test >:: get( 4 ) , FixedU128 :: from_rational( 8 , 40 ) ) ;
3989+ assert_eq ! (
3990+ Counters :: <Test >:: get( 4 ) ,
3991+ Counter { value: FixedU128 :: from_rational( 8 , 40 ) , pending_claims: 0 }
3992+ ) ;
39663993 assert_eq ! (
39673994 CandidateStake :: <Test >:: get( 4 , 5 ) . checkpoint,
39683995 FixedU128 :: from_rational( 8 , 40 )
@@ -4369,7 +4396,12 @@ mod claim_rewards_other {
43694396
43704397 // Check the collator's counter and staker's checkpoint. Both should be zero, as no
43714398 // rewards were distributed.
4372- assert_eq ! ( Counters :: <Test >:: get( 4 ) , FixedU128 :: zero( ) ) ;
4399+ assert_eq ! (
4400+ Counters :: <Test >:: get( 4 ) ,
4401+ Counter { value: FixedU128 :: zero( ) , pending_claims: 0 }
4402+ ) ;
4403+ // Which implies the counter should not exist yet.
4404+ assert ! ( !Counters :: <Test >:: contains_key( 4 ) ) ;
43734405 assert_eq ! ( CandidateStake :: <Test >:: get( 4 , 3 ) . checkpoint, FixedU128 :: zero( ) ) ;
43744406
43754407 // Skip session 0, as there are no rewards for this session
@@ -4392,7 +4424,10 @@ mod claim_rewards_other {
43924424 // At this point, rewards from session 1 should have been calculated
43934425 // Check counter is updated as expected with 20% to collator, 80% to stakers
43944426 let expected_checkpoint = FixedU128 :: from_rational ( 80 , 40 ) ;
4395- assert_eq ! ( Counters :: <Test >:: get( 4 ) , expected_checkpoint) ;
4427+ assert_eq ! (
4428+ Counters :: <Test >:: get( 4 ) ,
4429+ Counter { value: expected_checkpoint, pending_claims: 1 }
4430+ ) ;
43964431
43974432 // The checkpoint should still be zero, as rewards aren't claimed
43984433 // or distributed yet
@@ -4402,8 +4437,7 @@ mod claim_rewards_other {
44024437 let weight = Weight :: from_parts ( u64:: MAX , u64:: MAX ) ;
44034438 CollatorStaking :: on_idle ( 21 , weight) ;
44044439
4405- // The checkpoint should now be updated to match the counter as
4406- // rewards have been distributed
4440+ // The checkpoint should now be zero, since all stakers claimed
44074441 assert_eq ! ( CandidateStake :: <Test >:: get( 4 , 3 ) . checkpoint, expected_checkpoint) ;
44084442
44094443 // The stake should have increased by the reward amount (40 * 80/40 = 80)
0 commit comments