github.com/Finschia/finschia-sdk@v0.48.1/types/handler_test.go (about) 1 package types_test 2 3 import ( 4 "testing" 5 6 "github.com/golang/mock/gomock" 7 "github.com/stretchr/testify/suite" 8 9 "github.com/Finschia/finschia-sdk/tests/mocks" 10 sdk "github.com/Finschia/finschia-sdk/types" 11 ) 12 13 type handlerTestSuite struct { 14 suite.Suite 15 } 16 17 func TestHandlerTestSuite(t *testing.T) { 18 suite.Run(t, new(handlerTestSuite)) 19 } 20 21 func (s *handlerTestSuite) SetupSuite() { 22 s.T().Parallel() 23 } 24 25 func (s *handlerTestSuite) TestChainAnteDecorators() { 26 // test panic 27 s.Require().Nil(sdk.ChainAnteDecorators([]sdk.AnteDecorator{}...)) 28 29 ctx, tx := sdk.Context{}, sdk.Tx(nil) 30 mockCtrl := gomock.NewController(s.T()) 31 mockAnteDecorator1 := mocks.NewMockAnteDecorator(mockCtrl) 32 mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1) 33 _, err := sdk.ChainAnteDecorators(mockAnteDecorator1)(ctx, tx, true) 34 s.Require().NoError(err) 35 36 mockAnteDecorator2 := mocks.NewMockAnteDecorator(mockCtrl) 37 // NOTE: we can't check that mockAnteDecorator2 is passed as the last argument because 38 // ChainAnteDecorators wraps the decorators into closures, so each decorator is 39 // receiving a closure. 40 mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1) 41 mockAnteDecorator2.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1) 42 43 _, err = sdk.ChainAnteDecorators( 44 mockAnteDecorator1, 45 mockAnteDecorator2)(ctx, tx, true) 46 s.Require().NoError(err) 47 }