-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix types.ChainAnteDecorators() panic
ChainAnteDecorators() panics when no arguments are supplied. This change its behaviour and the function now returns a nil AnteHandler in case no AnteDecorator instances are supplied. Closes: #5741
- Loading branch information
Alessio Treglia
committed
Mar 3, 2020
1 parent
3349c97
commit 3d8dc52
Showing
3 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/tests/mocks" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func TestChainAnteDecorators(t *testing.T) { | ||
t.Parallel() | ||
// test panic | ||
require.Nil(t, sdk.ChainAnteDecorators([]sdk.AnteDecorator{}...)) | ||
|
||
ctx, tx := sdk.Context{}, sdk.Tx(nil) | ||
mockCtrl := gomock.NewController(t) | ||
mockAnteDecorator1 := mocks.NewMockAnteDecorator(mockCtrl) | ||
mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, nil).Times(1) | ||
sdk.ChainAnteDecorators(mockAnteDecorator1)(ctx, tx, true) | ||
|
||
mockAnteDecorator2 := mocks.NewMockAnteDecorator(mockCtrl) | ||
mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, mockAnteDecorator2).Times(1) | ||
mockAnteDecorator2.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, nil).Times(1) | ||
sdk.ChainAnteDecorators(mockAnteDecorator1, mockAnteDecorator2) | ||
} |