Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Mar 8, 2024
1 parent d841d56 commit 941db31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 15 additions & 9 deletions x/emissions/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
observerRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).ObserverEmissionPercentage).Mul(blockRewards).TruncateInt()
tssSignerRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).TssSignerEmissionPercentage).Mul(blockRewards).TruncateInt()

// TODO : Replace hardcoded slash amount with a parameter
// https://github.com/zeta-chain/node/pull/1861
slashAmount, ok := sdkmath.NewIntFromString(types.ObserverSlashAmount)
if !ok {
ctx.Logger().Error(fmt.Sprintf("Error while parsing observer slash amount %s", types.ObserverSlashAmount))
return

Check warning on line 30 in x/emissions/abci.go

View check run for this annotation

Codecov / codecov/patch

x/emissions/abci.go#L29-L30

Added lines #L29 - L30 were not covered by tests
}

// Use a tmpCtx, which is a cache-wrapped context to avoid writing to the store
// We commit only if all three distributions are successful, if not the funds stay in the emission pool
tmpCtx, commit := ctx.CacheContext()
Expand All @@ -30,7 +38,7 @@ func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
ctx.Logger().Error(fmt.Sprintf("Error while distributing validator rewards %s", err))
return
}
err = DistributeObserverRewards(tmpCtx, observerRewards, keeper)
err = DistributeObserverRewards(tmpCtx, observerRewards, keeper, slashAmount)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Error while distributing observer rewards %s", err))
return
Expand Down Expand Up @@ -63,7 +71,12 @@ func DistributeValidatorRewards(ctx sdk.Context, amount sdkmath.Int, bankKeeper
// NotVoted or Unsuccessful votes are slashed
// rewards given or slashed amounts are in azeta

func DistributeObserverRewards(ctx sdk.Context, amount sdkmath.Int, keeper keeper.Keeper) error {
func DistributeObserverRewards(
ctx sdk.Context,
amount sdkmath.Int,
keeper keeper.Keeper,
slashAmount sdkmath.Int,
) error {

rewardsDistributer := map[string]int64{}
totalRewardsUnits := int64(0)
Expand Down Expand Up @@ -114,13 +127,6 @@ func DistributeObserverRewards(ctx sdk.Context, amount sdkmath.Int, keeper keepe
}
if observerRewardUnits < 0 {

// TODO : Replace hardcoded slash amount with a parameter
// https://github.com/zeta-chain/node/pull/1861
slashAmount, ok := sdkmath.NewIntFromString(types.ObserverSlashAmount)
if !ok {
continue
}

keeper.SlashObserverEmission(ctx, observerAddress.String(), slashAmount)
finalDistributionList = append(finalDistributionList, &types.ObserverEmission{
EmissionType: types.EmissionType_Slash,
Expand Down
4 changes: 3 additions & 1 deletion x/emissions/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func TestBeginBlocker(t *testing.T) {
}

func TestDistributeObserverRewards(t *testing.T) {
keepertest.SetConfig(false)
observerSet := sample.ObserverSet(4)

tt := []struct {
Expand Down Expand Up @@ -286,8 +287,9 @@ func TestDistributeObserverRewards(t *testing.T) {
ctx = ctx.WithBlockHeight(100)

// Distribute the rewards and check if the rewards are distributed correctly
err = emissionsModule.DistributeObserverRewards(ctx, tc.totalRewardsForBlock, *k)
err = emissionsModule.DistributeObserverRewards(ctx, tc.totalRewardsForBlock, *k, tc.slashAmount)
require.NoError(t, err)

for i, observer := range observerSet.ObserverList {
observerEmission, found := k.GetWithdrawableEmission(ctx, observer)
require.True(t, found, "withdrawable emission not found for observer %d", i)
Expand Down

0 comments on commit 941db31

Please sign in to comment.