refactor(x/auth/ante): don't use simulate bool in ante handler (#19586)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
coderabbitai[bot]
parent
0a801e1c03
commit
975ddc1d31
+13
-13
@@ -6,23 +6,23 @@ package types
|
||||
// is required for the remainder of the AnteHandler execution, a new Context should
|
||||
// be created off of the provided Context and returned as <newCtx>.
|
||||
//
|
||||
// The simulate argument is provided to indicate if the AnteHandler is being executed
|
||||
// in simulation mode, which attempts to estimate a gas cost for the tx. Any state
|
||||
// modifications made will be discarded if simulate is true.
|
||||
type AnteHandler func(ctx Context, tx Tx, simulate bool) (newCtx Context, err error)
|
||||
// When exec module is in simulation mode (ctx.ExecMode() == ExecModeSimulate), it indicates if the AnteHandler is
|
||||
// being executed in simulation mode, which attempts to estimate a gas cost for the tx.
|
||||
// Any state modifications made will be discarded in simulation mode.
|
||||
type AnteHandler func(ctx Context, tx Tx, _ bool) (newCtx Context, err error)
|
||||
|
||||
// PostHandler like AnteHandler but it executes after RunMsgs. Runs on success
|
||||
// or failure and enables use cases like gas refunding.
|
||||
type PostHandler func(ctx Context, tx Tx, simulate, success bool) (newCtx Context, err error)
|
||||
type PostHandler func(ctx Context, tx Tx, _, success bool) (newCtx Context, err error)
|
||||
|
||||
// AnteDecorator wraps the next AnteHandler to perform custom pre-processing.
|
||||
type AnteDecorator interface {
|
||||
AnteHandle(ctx Context, tx Tx, simulate bool, next AnteHandler) (newCtx Context, err error)
|
||||
AnteHandle(ctx Context, tx Tx, _ bool, next AnteHandler) (newCtx Context, err error)
|
||||
}
|
||||
|
||||
// PostDecorator wraps the next PostHandler to perform custom post-processing.
|
||||
type PostDecorator interface {
|
||||
PostHandle(ctx Context, tx Tx, simulate, success bool, next PostHandler) (newCtx Context, err error)
|
||||
PostHandle(ctx Context, tx Tx, _, success bool, next PostHandler) (newCtx Context, err error)
|
||||
}
|
||||
|
||||
// ChainAnteDecorators ChainDecorator chains AnteDecorators together with each AnteDecorator
|
||||
@@ -46,13 +46,13 @@ func ChainAnteDecorators(chain ...AnteDecorator) AnteHandler {
|
||||
|
||||
handlerChain := make([]AnteHandler, len(chain)+1)
|
||||
// set the terminal AnteHandler decorator
|
||||
handlerChain[len(chain)] = func(ctx Context, tx Tx, simulate bool) (Context, error) {
|
||||
handlerChain[len(chain)] = func(ctx Context, tx Tx, _ bool) (Context, error) {
|
||||
return ctx, nil
|
||||
}
|
||||
for i := 0; i < len(chain); i++ {
|
||||
ii := i
|
||||
handlerChain[ii] = func(ctx Context, tx Tx, simulate bool) (Context, error) {
|
||||
return chain[ii].AnteHandle(ctx, tx, simulate, handlerChain[ii+1])
|
||||
handlerChain[ii] = func(ctx Context, tx Tx, _ bool) (Context, error) {
|
||||
return chain[ii].AnteHandle(ctx, tx, ctx.ExecMode() == ExecModeSimulate, handlerChain[ii+1])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,13 +74,13 @@ func ChainPostDecorators(chain ...PostDecorator) PostHandler {
|
||||
|
||||
handlerChain := make([]PostHandler, len(chain)+1)
|
||||
// set the terminal PostHandler decorator
|
||||
handlerChain[len(chain)] = func(ctx Context, tx Tx, simulate, success bool) (Context, error) {
|
||||
handlerChain[len(chain)] = func(ctx Context, tx Tx, _, success bool) (Context, error) {
|
||||
return ctx, nil
|
||||
}
|
||||
for i := 0; i < len(chain); i++ {
|
||||
ii := i
|
||||
handlerChain[ii] = func(ctx Context, tx Tx, simulate, success bool) (Context, error) {
|
||||
return chain[ii].PostHandle(ctx, tx, simulate, success, handlerChain[ii+1])
|
||||
handlerChain[ii] = func(ctx Context, tx Tx, _, success bool) (Context, error) {
|
||||
return chain[ii].PostHandle(ctx, tx, ctx.ExecMode() == ExecModeSimulate, success, handlerChain[ii+1])
|
||||
}
|
||||
}
|
||||
return handlerChain[0]
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestChainAnteDecorators(t *testing.T) {
|
||||
// test panic
|
||||
require.Nil(t, sdk.ChainAnteDecorators([]sdk.AnteDecorator{}...))
|
||||
|
||||
ctx, tx := sdk.Context{}, sdk.Tx(nil)
|
||||
ctx, tx := sdk.Context{}.WithExecMode(sdk.ExecModeSimulate), sdk.Tx(nil)
|
||||
mockCtrl := gomock.NewController(t)
|
||||
mockAnteDecorator1 := mock.NewMockAnteDecorator(mockCtrl)
|
||||
mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1)
|
||||
@@ -39,7 +39,7 @@ func TestChainPostDecorators(t *testing.T) {
|
||||
require.Nil(t, sdk.ChainPostDecorators([]sdk.PostDecorator{}...))
|
||||
|
||||
// Create empty context as well as transaction
|
||||
ctx := sdk.Context{}
|
||||
ctx := sdk.Context{}.WithExecMode(sdk.ExecModeSimulate)
|
||||
tx := sdk.Tx(nil)
|
||||
|
||||
// Create mocks
|
||||
|
||||
Reference in New Issue
Block a user