/
mock_ibc.go
91 lines (78 loc) · 2.69 KB
/
mock_ibc.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)
// Connection is an IBC connection end associated to a connection ID
type Connection struct {
ConnID string
Conn connectiontypes.ConnectionEnd
}
// ConnectionMock represents a mocked IBC connection keeper used for test purposes
type ConnectionMock struct {
connections map[string]connectiontypes.ConnectionEnd
}
// NewConnectionMock initializes a new connection mock
func NewConnectionMock(conns []Connection) (c ConnectionMock) {
c.connections = make(map[string]connectiontypes.ConnectionEnd)
for _, conn := range conns {
c.connections[conn.ConnID] = conn.Conn
}
return
}
// GetConnection implements ConnectionKeeper
func (c ConnectionMock) GetConnection(_ sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, bool) {
conn, ok := c.connections[connectionID]
return conn, ok
}
// Channel is an IBC channel end associated to a channel ID
type Channel struct {
ChannelID string
Channel channeltypes.Channel
}
// ChannelMock represents a mocked IBC channel keeper used for test purposes
type ChannelMock struct {
channels map[string]channeltypes.Channel
}
// NewChannelMock initializes a new channel mock
func NewChannelMock(channels []Channel) (c ChannelMock) {
c.channels = make(map[string]channeltypes.Channel)
for _, channel := range channels {
c.channels[channel.ChannelID] = channel.Channel
}
return
}
// GetChannel implements ChannelKeeper
func (c ChannelMock) GetChannel(_ sdk.Context, _, channelID string) (channel channeltypes.Channel, found bool) {
channel, ok := c.channels[channelID]
return channel, ok
}
// GetNextSequenceSend implements ChannelKeeper
// returns true for all cases
func (c ChannelMock) GetNextSequenceSend(_ sdk.Context, _, _ string) (uint64, bool) {
return 0, true
}
// SendPacket implements ChannelKeeper
func (c ChannelMock) SendPacket(
_ sdk.Context,
_ *capabilitytypes.Capability,
_ string,
_ string,
_ clienttypes.Height,
_ uint64,
_ []byte,
) (uint64, error) {
return 0, nil
}
// WriteAcknowledgement implements ChannelKeeper
func (c ChannelMock) WriteAcknowledgement(_ sdk.Context, _ *capabilitytypes.Capability, _ exported.PacketI, _ exported.Acknowledgement) error {
return nil
}
// ChanCloseInit implements ChannelKeeper
func (c ChannelMock) ChanCloseInit(_ sdk.Context, _, _ string, _ *capabilitytypes.Capability) error {
return nil
}