@@ -91,18 +91,18 @@ fn add_share_should_work() {
91
91
) ;
92
92
93
93
// overflow occurs when saturating calculation
94
- assert_ok ! ( RewardsModule :: add_share( & ALICE , & DOT_POOL , u64 :: MAX ) ) ;
94
+ assert_ok ! ( RewardsModule :: add_share( & ALICE , & DOT_POOL , u128 :: MAX ) ) ;
95
95
96
96
assert_eq ! (
97
97
RewardsModule :: pool_infos( DOT_POOL ) ,
98
98
PoolInfo {
99
- total_shares: u64 :: MAX ,
100
- rewards: vec![ ( NATIVE_COIN , ( u64 :: MAX , u64 :: MAX ) ) ] . into_iter( ) . collect( )
99
+ total_shares: u128 :: MAX ,
100
+ rewards: vec![ ( NATIVE_COIN , ( u128 :: MAX , u128 :: MAX ) ) ] . into_iter( ) . collect( )
101
101
}
102
102
) ;
103
103
assert_eq ! (
104
104
RewardsModule :: shares_and_withdrawn_rewards( DOT_POOL , ALICE ) ,
105
- ( u64 :: MAX , vec![ ( NATIVE_COIN , u64 :: MAX ) ] . into_iter( ) . collect( ) )
105
+ ( u128 :: MAX , vec![ ( NATIVE_COIN , u128 :: MAX ) ] . into_iter( ) . collect( ) )
106
106
) ;
107
107
} ) ;
108
108
}
@@ -663,3 +663,29 @@ fn minimal_share_should_be_enforced() {
663
663
assert_ok ! ( RewardsModule :: transfer_share_and_rewards( & ALICE , & DOT_POOL , 5 , & BOB ) ) ;
664
664
} ) ;
665
665
}
666
+
667
+ #[ test]
668
+ fn overflow_should_work ( ) {
669
+ ExtBuilder :: default ( ) . build ( ) . execute_with ( || {
670
+ assert_ok ! ( RewardsModule :: add_share( & ALICE , & DOT_POOL , 10 ) ) ;
671
+
672
+ // The DOT pool accumulate 21 rewards in the NATIVE COIN
673
+ assert_ok ! ( RewardsModule :: accumulate_reward( & DOT_POOL , NATIVE_COIN , 21 ) ) ;
674
+ assert_eq ! (
675
+ RewardsModule :: pool_infos( DOT_POOL ) ,
676
+ PoolInfo {
677
+ total_shares: 10 ,
678
+ rewards: vec![ ( NATIVE_COIN , ( 21 , 0 ) ) ] . into_iter( ) . collect( )
679
+ }
680
+ ) ;
681
+
682
+ assert_ok ! ( RewardsModule :: add_share( & ALICE , & DOT_POOL , u128 :: MAX ) ) ;
683
+ assert_eq ! (
684
+ RewardsModule :: pool_infos( DOT_POOL ) ,
685
+ PoolInfo {
686
+ total_shares: u128 :: MAX ,
687
+ rewards: vec![ ( NATIVE_COIN , ( u128 :: MAX , u128 :: MAX ) ) ] . into_iter( ) . collect( )
688
+ }
689
+ ) ;
690
+ } ) ;
691
+ }
0 commit comments