@@ -326,9 +326,9 @@ func TestValidatorPayouts(t *testing.T) {
326
326
totalReserve := sdkmath .NewInt (1000000000 ).ToLegacyDec ()
327
327
328
328
blockReward := mgr .calcBlockReward (ctx , totalReserve , emissionCurve , blocksPerYear , valCycle )
329
-
330
329
require .Equal (t , blockReward .Amount .RoundInt64 (), int64 (2000000 ))
331
330
331
+ // Setup validators
332
332
pks := simtestutil .CreateTestPubKeys (3 )
333
333
pk1 , err := common .NewPubKeyFromCrypto (pks [0 ])
334
334
require .NoError (t , err )
@@ -345,10 +345,11 @@ func TestValidatorPayouts(t *testing.T) {
345
345
346
346
valAddrs := simtestutil .ConvertAddrsToValAddrs ([]cosmos.AccAddress {acc1 , acc2 , acc3 })
347
347
348
+ // Create validators with their shares
348
349
val1 , err := stakingtypes .NewValidator (valAddrs [0 ].String (), pks [0 ], stakingtypes.Description {})
349
350
require .NoError (t , err )
350
351
val1 .Tokens = cosmos .NewInt (100 )
351
- val1 .DelegatorShares = cosmos .NewDec (130 ) // Validator + Delegations
352
+ val1 .DelegatorShares = cosmos .NewDec (130 )
352
353
val1 .Status = stakingtypes .Bonded
353
354
val1 .Commission = stakingtypes .NewCommission (cosmos .NewDecWithPrec (1 , 1 ), cosmos .ZeroDec (), cosmos .ZeroDec ())
354
355
@@ -373,14 +374,17 @@ func TestValidatorPayouts(t *testing.T) {
373
374
require .NoError (t , sk .SetNewValidatorByPowerIndex (ctx , val ))
374
375
}
375
376
377
+ // Setup delegations
376
378
delAcc1 := types .GetRandomBech32Addr ()
377
379
delAcc2 := types .GetRandomBech32Addr ()
378
380
delAcc3 := types .GetRandomBech32Addr ()
379
381
382
+ // Set validator self-delegations
380
383
require .NoError (t , sk .SetDelegation (ctx , stakingtypes .NewDelegation (acc1 .String (), valAddrs [0 ].String (), cosmos .NewDec (100 ))))
381
384
require .NoError (t , sk .SetDelegation (ctx , stakingtypes .NewDelegation (acc2 .String (), valAddrs [1 ].String (), cosmos .NewDec (200 ))))
382
385
require .NoError (t , sk .SetDelegation (ctx , stakingtypes .NewDelegation (acc3 .String (), valAddrs [2 ].String (), cosmos .NewDec (500 ))))
383
386
387
+ // Set other delegations
384
388
del1 := stakingtypes .NewDelegation (delAcc1 .String (), valAddrs [0 ].String (), cosmos .NewDec (10 ))
385
389
del2 := stakingtypes .NewDelegation (delAcc2 .String (), valAddrs [1 ].String (), cosmos .NewDec (20 ))
386
390
del3 := stakingtypes .NewDelegation (delAcc3 .String (), valAddrs [2 ].String (), cosmos .NewDec (20 ))
@@ -407,36 +411,41 @@ func TestValidatorPayouts(t *testing.T) {
407
411
}
408
412
}
409
413
414
+ // Check initial module balance
410
415
moduleBalance := k .GetBalanceOfModule (ctx , types .ReserveName , configs .Denom )
411
416
require .Equal (t , moduleBalance .Int64 (), int64 (20000000000000 ))
412
417
418
+ // Get reserve supply and execute validator payout
413
419
reserveSupply , err := mgr .reserveSupply (ctx )
414
420
require .NoError (t , err )
415
-
416
421
require .NoError (t , mgr .ValidatorPayout (ctx , votes , reserveSupply ))
417
422
418
- totalBal := cosmos .ZeroInt ()
423
+ // Calculate expected total shares and rewards
424
+ totalShares := val1 .DelegatorShares .Add (val2 .DelegatorShares ).Add (val3 .DelegatorShares )
419
425
426
+ // Check rewards for each validator
427
+ expectedVal1Reward := common .GetSafeShare (val1 .DelegatorShares , totalShares , reserveSupply .Amount )
428
+ expectedVal2Reward := common .GetSafeShare (val2 .DelegatorShares , totalShares , reserveSupply .Amount )
429
+ expectedVal3Reward := common .GetSafeShare (val3 .DelegatorShares , totalShares , reserveSupply .Amount )
430
+
431
+ // Verify rewards
420
432
rewardsAcc1 , err := k .GetValidatorRewards (ctx , acc1 .Bytes ())
421
433
require .NoError (t , err )
422
- require .Equal (t , rewardsAcc1 .Rewards .AmountOf (configs .Denom ).RoundInt (), sdkmath .NewInt (2588235294117 ))
423
- totalBal = totalBal .Add (rewardsAcc1 .Rewards .AmountOf (configs .Denom ).RoundInt ())
434
+ require .Equal (t , rewardsAcc1 .Rewards .AmountOf (configs .Denom ).TruncateInt (), expectedVal1Reward .TruncateInt ())
424
435
425
436
rewardsAcc2 , err := k .GetValidatorRewards (ctx , acc2 .Bytes ())
426
437
require .NoError (t , err )
427
- require .Equal (t , rewardsAcc2 .Rewards .AmountOf (configs .Denom ).RoundInt (), sdkmath .NewInt (5176470588234 ))
428
- totalBal = totalBal .Add (rewardsAcc2 .Rewards .AmountOf (configs .Denom ).RoundInt ())
438
+ require .Equal (t , rewardsAcc2 .Rewards .AmountOf (configs .Denom ).TruncateInt (), expectedVal2Reward .TruncateInt ())
429
439
430
440
rewardsAcc3 , err := k .GetValidatorRewards (ctx , acc3 .Bytes ())
431
441
require .NoError (t , err )
432
- require .Equal (t , rewardsAcc3 .Rewards .AmountOf (configs .Denom ).RoundInt (), sdkmath .NewInt (12235294117646 ))
433
- totalBal = totalBal .Add (rewardsAcc3 .Rewards .AmountOf (configs .Denom ).RoundInt ())
434
-
435
- require .Equal (t , totalBal .ToLegacyDec (), sdkmath .LegacyNewDec (19999999999997 ))
442
+ require .Equal (t , rewardsAcc3 .Rewards .AmountOf (configs .Denom ).TruncateInt (), expectedVal3Reward .TruncateInt ())
436
443
444
+ // Verify module balances
437
445
moduleBalance = k .GetBalanceOfModule (ctx , types .ReserveName , configs .Denom )
438
- require .Equal (t , moduleBalance .ToLegacyDec ().RoundInt64 (), int64 (0 ))
439
- p , err := k .GetCommunityPool (ctx )
446
+ require .Equal (t , moduleBalance .Int64 (), int64 (0 ))
447
+ // Check community pool for remainder
448
+ pool , err := k .GetCommunityPool (ctx )
440
449
require .NoError (t , err )
441
- require .Equal (t , p .CommunityPool .AmountOf (configs .Denom ), sdkmath . LegacyNewDec ( 10003 ))
450
+ require .True (t , pool .CommunityPool .AmountOf (configs .Denom ). GT ( cosmos . ZeroDec () ))
442
451
}
0 commit comments