@@ -91,18 +91,18 @@ fn add_share_should_work() {
9191 ) ;
9292
9393 // 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 ) ) ;
9595
9696 assert_eq ! (
9797 RewardsModule :: pool_infos( DOT_POOL ) ,
9898 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( )
101101 }
102102 ) ;
103103 assert_eq ! (
104104 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( ) )
106106 ) ;
107107 } ) ;
108108}
@@ -663,3 +663,29 @@ fn minimal_share_should_be_enforced() {
663663 assert_ok ! ( RewardsModule :: transfer_share_and_rewards( & ALICE , & DOT_POOL , 5 , & BOB ) ) ;
664664 } ) ;
665665}
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