forked from Finschia/wasmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_keepers.go
120 lines (102 loc) · 4.28 KB
/
mock_keepers.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
package wasmtesting
import (
channeltypes "github.com/line/ibc-go/v3/modules/core/04-channel/types"
ibcexported "github.com/line/ibc-go/v3/modules/core/exported"
sdk "github.com/line/lbm-sdk/types"
capabilitytypes "github.com/line/lbm-sdk/x/capability/types"
"github.com/line/wasmd/x/wasm/types"
)
type MockChannelKeeper struct {
GetChannelFn func(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool)
GetNextSequenceSendFn func(ctx sdk.Context, portID, channelID string) (uint64, bool)
SendPacketFn func(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error
ChanCloseInitFn func(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error
GetAllChannelsFn func(ctx sdk.Context) []channeltypes.IdentifiedChannel
IterateChannelsFn func(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool)
SetChannelFn func(ctx sdk.Context, portID, channelID string, channel channeltypes.Channel)
}
func (m *MockChannelKeeper) GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) {
if m.GetChannelFn == nil {
panic("not supposed to be called!")
}
return m.GetChannelFn(ctx, srcPort, srcChan)
}
func (m *MockChannelKeeper) GetAllChannels(ctx sdk.Context) []channeltypes.IdentifiedChannel {
if m.GetAllChannelsFn == nil {
panic("not supposed to be called!")
}
return m.GetAllChannelsFn(ctx)
}
func (m *MockChannelKeeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) {
if m.GetNextSequenceSendFn == nil {
panic("not supposed to be called!")
}
return m.GetNextSequenceSendFn(ctx, portID, channelID)
}
func (m *MockChannelKeeper) SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error {
if m.SendPacketFn == nil {
panic("not supposed to be called!")
}
return m.SendPacketFn(ctx, channelCap, packet)
}
func (m *MockChannelKeeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error {
if m.ChanCloseInitFn == nil {
panic("not supposed to be called!")
}
return m.ChanCloseInitFn(ctx, portID, channelID, chanCap)
}
func (m *MockChannelKeeper) IterateChannels(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) {
if m.IterateChannelsFn == nil {
panic("not expected to be called")
}
m.IterateChannelsFn(ctx, cb)
}
func (m *MockChannelKeeper) SetChannel(ctx sdk.Context, portID, channelID string, channel channeltypes.Channel) {
if m.GetChannelFn == nil {
panic("not supposed to be called!")
}
m.SetChannelFn(ctx, portID, channelID, channel)
}
func MockChannelKeeperIterator(s []channeltypes.IdentifiedChannel) func(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) {
return func(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) {
for _, channel := range s {
stop := cb(channel)
if stop {
break
}
}
}
}
type MockCapabilityKeeper struct {
GetCapabilityFn func(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool)
ClaimCapabilityFn func(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error
AuthenticateCapabilityFn func(ctx sdk.Context, capability *capabilitytypes.Capability, name string) bool
}
func (m MockCapabilityKeeper) GetCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool) {
if m.GetCapabilityFn == nil {
panic("not supposed to be called!")
}
return m.GetCapabilityFn(ctx, name)
}
func (m MockCapabilityKeeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
if m.ClaimCapabilityFn == nil {
panic("not supposed to be called!")
}
return m.ClaimCapabilityFn(ctx, cap, name)
}
func (m MockCapabilityKeeper) AuthenticateCapability(ctx sdk.Context, capability *capabilitytypes.Capability, name string) bool {
if m.AuthenticateCapabilityFn == nil {
panic("not supposed to be called!")
}
return m.AuthenticateCapabilityFn(ctx, capability, name)
}
var _ types.ICS20TransferPortSource = &MockIBCTransferKeeper{}
type MockIBCTransferKeeper struct {
GetPortFn func(ctx sdk.Context) string
}
func (m MockIBCTransferKeeper) GetPort(ctx sdk.Context) string {
if m.GetPortFn == nil {
panic("not expected to be called")
}
return m.GetPortFn(ctx)
}