forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.go
47 lines (37 loc) · 1.41 KB
/
handler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package types_test
import (
"testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/tests/mocks"
sdk "github.com/cosmos/cosmos-sdk/types"
)
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() {
// test panic
s.Require().Nil(sdk.ChainAnteDecorators([]sdk.AnteDecorator{}...))
ctx, tx := sdk.Context{}, sdk.Tx(nil)
mockCtrl := gomock.NewController(s.T())
mockAnteDecorator1 := mocks.NewMockAnteDecorator(mockCtrl)
mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1)
_, err := sdk.ChainAnteDecorators(mockAnteDecorator1)(ctx, tx, true)
s.Require().NoError(err)
mockAnteDecorator2 := mocks.NewMockAnteDecorator(mockCtrl)
// NOTE: we can't check that mockAnteDecorator2 is passed as the last argument because
// ChainAnteDecorators wraps the decorators into closures, so each decorator is
// receiving a closure.
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)
}