forked from evmos/evmos
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodule_test.go
207 lines (189 loc) · 6.88 KB
/
module_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package ibc
import (
"testing"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)
var _ porttypes.IBCModule = &MockIBCModule{}
// MockIBCModule defines a mocked object that implements the IBCModule
// interface. It's used on tests to abstract the complexity of IBC callbacks.
type MockIBCModule struct {
mock.Mock
}
// OnChanOpenInit implements the Module interface
// It calls the underlying app's OnChanOpenInit callback.
//
// and escaping revive for unused parameters which are okay since they indicate the expected mocked interface
//
//nolint:all // escaping govet since we can copy locks here as it is a test
func (m MockIBCModule) OnChanOpenInit(
ctx sdk.Context,
order channeltypes.Order,
connectionHops []string,
portID string,
channelID string,
chanCap *capabilitytypes.Capability,
counterparty channeltypes.Counterparty,
version string,
) (string, error) {
args := m.Called()
return version, args.Error(0)
}
// OnChanOpenTry implements the Module interface.
// It calls the underlying app's OnChanOpenTry callback.
//
// and escaping revive for unused parameters which are okay since they indicate the expected mocked interface
//
//nolint:all // escaping govet since we can copy locks here as it is a test
func (m MockIBCModule) OnChanOpenTry(
ctx sdk.Context,
order channeltypes.Order,
connectionHops []string,
portID,
channelID string,
chanCap *capabilitytypes.Capability,
counterparty channeltypes.Counterparty,
counterpartyVersion string,
) (version string, err error) {
args := m.Called()
return args.String(0), args.Error(1)
}
// OnChanOpenAck implements the Module interface.
// It calls the underlying app's OnChanOpenAck callback.
//
// and escaping revive for unused parameters which are okay since they indicate the expected mocked interface
//
//nolint:all // escaping govet since we can copy locks here as it is a test
func (m MockIBCModule) OnChanOpenAck(
ctx sdk.Context,
portID,
channelID,
counterpartyChannelID,
counterpartyVersion string,
) error {
args := m.Called()
return args.Error(0)
}
// OnChanOpenConfirm implements the Module interface.
// It calls the underlying app's OnChanOpenConfirm callback.
//
// and escaping revive for unused parameters which are okay since they indicate the expected mocked interface
//
//nolint:all // escaping govet since we can copy locks here as it is a test
func (m MockIBCModule) OnChanOpenConfirm(
ctx sdk.Context,
portID,
channelID string,
) error {
args := m.Called()
return args.Error(0)
}
// OnChanCloseInit implements the Module interface
// It calls the underlying app's OnChanCloseInit callback.
//
// and escaping revive for unused parameters which are okay since they indicate the expected mocked interface
//
//nolint:all // escaping govet since we can copy locks here as it is a test
func (m MockIBCModule) OnChanCloseInit(
ctx sdk.Context,
portID,
channelID string,
) error {
args := m.Called()
return args.Error(0)
}
// OnChanCloseConfirm implements the Module interface.
// It calls the underlying app's OnChanCloseConfirm callback.
//
// and escaping revive for unused parameters which are okay since they indicate the expected mocked interface
//
//nolint:all // escaping govet since we can copy locks here as it is a test
func (m MockIBCModule) OnChanCloseConfirm(
ctx sdk.Context,
portID,
channelID string,
) error {
args := m.Called()
return args.Error(0)
}
// OnRecvPacket implements the Module interface.
// It calls the underlying app's OnRecvPacket callback.
//
// and escaping revive for unused parameters which are okay since they indicate the expected mocked interface
//
//nolint:all // escaping govet since we can copy locks here as it is a test
func (m MockIBCModule) OnRecvPacket(
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
) exported.Acknowledgement {
args := m.Called()
return args.Get(0).(exported.Acknowledgement)
}
// OnAcknowledgementPacket implements the Module interface.
// It calls the underlying app's OnAcknowledgementPacket callback.
//
// and escaping revive for unused parameters which are okay since they indicate the expected mocked interface
//
//nolint:all // escaping govet since we can copy locks here as it is a test
func (m MockIBCModule) OnAcknowledgementPacket(
ctx sdk.Context,
packet channeltypes.Packet,
acknowledgement []byte,
relayer sdk.AccAddress,
) error {
args := m.Called()
return args.Error(0)
}
// OnTimeoutPacket implements the Module interface.
// It calls the underlying app's OnTimeoutPacket callback.
//
// and escaping revive for unused parameters which are okay since they indicate the expected mocked interface
//
//nolint:all // escaping govet since we can copy locks here as it is a test
func (m MockIBCModule) OnTimeoutPacket(
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
) error {
args := m.Called()
return args.Error(0)
}
func TestModule(t *testing.T) {
mockModule := &MockIBCModule{}
mockModule.On("OnChanOpenInit").Return(nil)
mockModule.On("OnChanOpenTry").Return("", nil)
mockModule.On("OnChanOpenAck").Return(nil)
mockModule.On("OnChanOpenConfirm").Return(nil)
mockModule.On("OnChanCloseInit").Return(nil)
mockModule.On("OnChanCloseConfirm").Return(nil)
mockModule.On("OnRecvPacket").Return(channeltypes.NewResultAcknowledgement([]byte("ack")))
mockModule.On("OnAcknowledgementPacket").Return(nil)
mockModule.On("OnTimeoutPacket").Return(nil)
module := NewModule(mockModule)
// mock calls for abstraction
_, err := module.OnChanOpenInit(sdk.Context{}, channeltypes.ORDERED, nil, transfertypes.PortID, "channel-0", &capabilitytypes.Capability{}, channeltypes.Counterparty{}, "")
require.NoError(t, err)
_, err = module.OnChanOpenTry(sdk.Context{}, channeltypes.ORDERED, nil, transfertypes.PortID, "channel-0", &capabilitytypes.Capability{}, channeltypes.Counterparty{}, "")
require.NoError(t, err)
err = module.OnChanOpenAck(sdk.Context{}, transfertypes.PortID, "channel-0", "channel-0", "")
require.NoError(t, err)
err = module.OnChanOpenConfirm(sdk.Context{}, transfertypes.PortID, "channel-0")
require.NoError(t, err)
err = module.OnChanCloseInit(sdk.Context{}, transfertypes.PortID, "channel-0")
require.NoError(t, err)
err = module.OnChanCloseConfirm(sdk.Context{}, transfertypes.PortID, "channel-0")
require.NoError(t, err)
ack := module.OnRecvPacket(sdk.Context{}, channeltypes.Packet{}, nil)
require.NotNil(t, ack)
err = module.OnAcknowledgementPacket(sdk.Context{}, channeltypes.Packet{}, nil, nil)
require.NoError(t, err)
err = module.OnTimeoutPacket(sdk.Context{}, channeltypes.Packet{}, nil)
require.NoError(t, err)
}