@@ -341,3 +341,35 @@ fn accumulate_reward_should_work() {
341
341
) ;
342
342
} ) ;
343
343
}
344
+
345
+ #[ test]
346
+ fn share_to_zero_removes_storage ( ) {
347
+ ExtBuilder :: default ( ) . build ( ) . execute_with ( || {
348
+ assert_eq ! ( ShareAndWithdrawnReward :: <Runtime >:: contains_key( DOT_POOL , ALICE ) , false ) ;
349
+ RewardsModule :: add_share ( & ALICE , & DOT_POOL , 100 ) ;
350
+ RewardsModule :: add_share ( & BOB , & DOT_POOL , 100 ) ;
351
+ Pools :: < Runtime > :: mutate ( DOT_POOL , |pool_info| {
352
+ pool_info. total_rewards += 10000 ;
353
+ } ) ;
354
+
355
+ assert_eq ! (
356
+ RewardsModule :: pools( DOT_POOL ) ,
357
+ PoolInfo {
358
+ total_shares: 200 ,
359
+ total_rewards: 10000 ,
360
+ total_withdrawn_rewards: 0 ,
361
+ }
362
+ ) ;
363
+
364
+ // chescks if key is removed
365
+ assert_eq ! ( ShareAndWithdrawnReward :: <Runtime >:: contains_key( DOT_POOL , ALICE ) , true ) ;
366
+ RewardsModule :: remove_share ( & ALICE , & DOT_POOL , 100 ) ;
367
+ assert_eq ! ( ShareAndWithdrawnReward :: <Runtime >:: contains_key( DOT_POOL , ALICE ) , false ) ;
368
+
369
+ RewardsModule :: remove_share ( & BOB , & DOT_POOL , 50 ) ;
370
+ assert_eq ! ( ShareAndWithdrawnReward :: <Runtime >:: contains_key( DOT_POOL , BOB ) , true ) ;
371
+
372
+ RewardsModule :: remove_share ( & BOB , & DOT_POOL , 100 ) ;
373
+ assert_eq ! ( ShareAndWithdrawnReward :: <Runtime >:: contains_key( DOT_POOL , BOB ) , false ) ;
374
+ } ) ;
375
+ }
0 commit comments