Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport/fix epoching ante handler (#385) #386

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
of the block in `TallyBlocks` function
- [#378](https://github.com/babylonlabs-io/babylon/pull/378) Fix give out rewards
with gaps of unfinalized blocks
- [#385](https://github.com/babylonlabs-io/babylon/pull/385) Fix epoching module
ante handler to return from antehandler chain only in case of error

## v1.0.0-rc2

Expand Down
5 changes: 3 additions & 2 deletions x/epoching/keeper/drop_validator_msg_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func (qmd DropValidatorMsgDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
}
// after genesis, if validator-related message, reject msg
for _, msg := range tx.GetMsgs() {
err := qmd.ValidateMsg(msg)
return ctx, err
if err := qmd.ValidateMsg(msg); err != nil {
return sdk.Context{}, err
}
}

return next(ctx, tx, simulate)
Expand Down
45 changes: 45 additions & 0 deletions x/epoching/keeper/drop_validator_msg_decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"testing"

appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/x/epoching/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authz "github.com/cosmos/cosmos-sdk/x/authz"
Expand Down Expand Up @@ -55,3 +56,47 @@ func TestDropValidatorMsgDecorator(t *testing.T) {
}
}
}

func TestReturnNilErrorNotCallNext(t *testing.T) {
decorator := NewDropValidatorMsgDecorator(&Keeper{})
ctx := sdk.Context{}.WithBlockHeight(1)
createValidatorMsg := &stakingtypes.MsgCreateValidator{}
encCfg := appparams.DefaultEncodingConfig()

builder := encCfg.TxConfig.NewTxBuilder()
builder.SetMsgs(createValidatorMsg)
tx := builder.GetTx()

nextAnteHandlerCalled := false
next := func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
nextAnteHandlerCalled = true
return ctx, nil
}

ctx, err := decorator.AnteHandle(ctx, tx, false, next)
require.Error(t, err)
require.Equal(t, sdk.Context{}, ctx)
require.False(t, nextAnteHandlerCalled)
}

func TestReturnSuccessCallNext(t *testing.T) {
decorator := NewDropValidatorMsgDecorator(&Keeper{})
ctx := sdk.Context{}.WithBlockHeight(1)
createValidatorMsg := &stakingtypes.MsgEditValidator{}
encCfg := appparams.DefaultEncodingConfig()

builder := encCfg.TxConfig.NewTxBuilder()
builder.SetMsgs(createValidatorMsg)
tx := builder.GetTx()
nextAnteHandlerCalled := false

next := func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
nextAnteHandlerCalled = true
return ctx, nil
}

ctx, err := decorator.AnteHandle(ctx, tx, false, next)
require.NoError(t, err)
require.Equal(t, ctx, ctx)
require.True(t, nextAnteHandlerCalled)
}
Loading