forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (cosmos#5742)
* 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: cosmos#5741 * Append Terminator to non-terminated chains. * Fix test case
- Loading branch information
Alessio Treglia
authored
Mar 3, 2020
1 parent
3349c97
commit bfac2a9
Showing
3 changed files
with
35 additions
and
6 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, gomock.Any()).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) | ||
} |