2020-03-03 08:57:33 -08:00
|
|
|
package types_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/golang/mock/gomock"
|
2020-09-29 04:29:10 -07:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-03-03 08:57:33 -08:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/tests/mocks"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2020-09-29 04:29:10 -07:00
|
|
|
type handlerTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHandlerTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(handlerTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *handlerTestSuite) SetupSuite() {
|
|
|
|
s.T().Parallel()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *handlerTestSuite) TestChainAnteDecorators() {
|
2020-03-03 08:57:33 -08:00
|
|
|
// test panic
|
2020-09-29 04:29:10 -07:00
|
|
|
s.Require().Nil(sdk.ChainAnteDecorators([]sdk.AnteDecorator{}...))
|
2020-03-03 08:57:33 -08:00
|
|
|
|
|
|
|
ctx, tx := sdk.Context{}, sdk.Tx(nil)
|
2020-09-29 04:29:10 -07:00
|
|
|
mockCtrl := gomock.NewController(s.T())
|
2020-03-03 08:57:33 -08:00
|
|
|
mockAnteDecorator1 := mocks.NewMockAnteDecorator(mockCtrl)
|
|
|
|
mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1)
|
2021-05-25 02:18:59 -07:00
|
|
|
_, err := sdk.ChainAnteDecorators(mockAnteDecorator1)(ctx, tx, true)
|
|
|
|
s.Require().NoError(err)
|
2020-03-03 08:57:33 -08:00
|
|
|
|
|
|
|
mockAnteDecorator2 := mocks.NewMockAnteDecorator(mockCtrl)
|
2021-05-25 02:18:59 -07:00
|
|
|
// NOTE: we can't check that mockAnteDecorator2 is passed as the last argument because
|
|
|
|
// ChainAnteDecorators wraps the decorators into closures, so each decorator is
|
2021-09-20 05:02:15 -07:00
|
|
|
// receiving a closure.
|
2021-05-25 02:18:59 -07:00
|
|
|
mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1)
|
|
|
|
mockAnteDecorator2.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1)
|
|
|
|
|
|
|
|
_, err = sdk.ChainAnteDecorators(
|
|
|
|
mockAnteDecorator1,
|
|
|
|
mockAnteDecorator2)(ctx, tx, true)
|
|
|
|
s.Require().NoError(err)
|
2020-03-03 08:57:33 -08:00
|
|
|
}
|