Skip to content

Commit

Permalink
update hook
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Oct 4, 2024
1 parent 90924e9 commit f997632
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions x/observer/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ type Hooks struct {
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) error {
err := h.k.CleanObservers(ctx, valAddr)
if err != nil {
return err
ctx.Logger().Error("Error cleaning observer set", "error", err)
}
return nil
}

func (h Hooks) AfterValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) error {
err := h.k.CheckAndCleanObserver(ctx, valAddr)
if err != nil {
return err
ctx.Logger().Error("Error cleaning observer set", "error", err)
}
return nil
}

func (h Hooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
err := h.k.CheckAndCleanObserverDelegator(ctx, valAddr, delAddr)
if err != nil {
return err
ctx.Logger().Error("Error cleaning observer set", "error", err)
}
return nil
}

func (h Hooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec) error {
err := h.k.CleanSlashedValidator(ctx, valAddr, fraction)
if err != nil {
return err
ctx.Logger().Error("Error cleaning observer set", "error", err)
}
return nil
}
Expand Down
9 changes: 7 additions & 2 deletions x/observer/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,20 @@ func TestKeeper_AfterDelegationModified(t *testing.T) {
}

func TestKeeper_BeforeValidatorSlashed(t *testing.T) {
t.Run("should error if validator not found", func(t *testing.T) {
t.Run("should not error if validator not found", func(t *testing.T) {
k, ctx, _, _ := keepertest.ObserverKeeper(t)

r := rand.New(rand.NewSource(9))
validator := sample.Validator(t, r)
os := sample.ObserverSet(10)
k.SetObserverSet(ctx, os)

hooks := k.Hooks()
err := hooks.BeforeValidatorSlashed(ctx, validator.GetOperator(), sdk.NewDec(1))
require.Error(t, err)
require.NoError(t, err)
storedOs, found := k.GetObserverSet(ctx)
require.True(t, found)
require.Equal(t, os, storedOs)
})

t.Run("should not error if observer set not found", func(t *testing.T) {
Expand Down

0 comments on commit f997632

Please sign in to comment.