github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/wasm/keeper/wasmtesting/mock_keepers.go (about) 1 package wasmtesting 2 3 import ( 4 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/baseapp" 5 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 6 capabilitytypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/capability/types" 7 channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 8 ibcexported "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/exported" 9 10 "github.com/fibonacci-chain/fbc/x/wasm/types" 11 ) 12 13 type MockChannelKeeper struct { 14 GetChannelFn func(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) 15 GetNextSequenceSendFn func(ctx sdk.Context, portID, channelID string) (uint64, bool) 16 SendPacketFn func(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error 17 ChanCloseInitFn func(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error 18 GetAllChannelsFn func(ctx sdk.Context) []channeltypes.IdentifiedChannel 19 IterateChannelsFn func(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) 20 SetChannelFn func(ctx sdk.Context, portID, channelID string, channel channeltypes.Channel) 21 } 22 23 func (m *MockChannelKeeper) GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) { 24 if m.GetChannelFn == nil { 25 panic("not supposed to be called!") 26 } 27 return m.GetChannelFn(ctx, srcPort, srcChan) 28 } 29 30 func (m *MockChannelKeeper) GetAllChannels(ctx sdk.Context) []channeltypes.IdentifiedChannel { 31 if m.GetAllChannelsFn == nil { 32 panic("not supposed to be called!") 33 } 34 return m.GetAllChannelsFn(ctx) 35 } 36 37 func (m *MockChannelKeeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) { 38 if m.GetNextSequenceSendFn == nil { 39 panic("not supposed to be called!") 40 } 41 return m.GetNextSequenceSendFn(ctx, portID, channelID) 42 } 43 44 func (m *MockChannelKeeper) SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error { 45 if m.SendPacketFn == nil { 46 panic("not supposed to be called!") 47 } 48 return m.SendPacketFn(ctx, channelCap, packet) 49 } 50 51 func (m *MockChannelKeeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error { 52 if m.ChanCloseInitFn == nil { 53 panic("not supposed to be called!") 54 } 55 return m.ChanCloseInitFn(ctx, portID, channelID, chanCap) 56 } 57 58 func (m *MockChannelKeeper) IterateChannels(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) { 59 if m.IterateChannelsFn == nil { 60 panic("not expected to be called") 61 } 62 m.IterateChannelsFn(ctx, cb) 63 } 64 65 func (m *MockChannelKeeper) SetChannel(ctx sdk.Context, portID, channelID string, channel channeltypes.Channel) { 66 if m.GetChannelFn == nil { 67 panic("not supposed to be called!") 68 } 69 m.SetChannelFn(ctx, portID, channelID, channel) 70 } 71 72 func MockChannelKeeperIterator(s []channeltypes.IdentifiedChannel) func(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) { 73 return func(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) { 74 for _, channel := range s { 75 stop := cb(channel) 76 if stop { 77 break 78 } 79 } 80 } 81 } 82 83 type MockCapabilityKeeper struct { 84 GetCapabilityFn func(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool) 85 ClaimCapabilityFn func(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error 86 AuthenticateCapabilityFn func(ctx sdk.Context, capability *capabilitytypes.Capability, name string) bool 87 } 88 89 func (m MockCapabilityKeeper) GetCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool) { 90 if m.GetCapabilityFn == nil { 91 panic("not supposed to be called!") 92 } 93 return m.GetCapabilityFn(ctx, name) 94 } 95 96 func (m MockCapabilityKeeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { 97 if m.ClaimCapabilityFn == nil { 98 panic("not supposed to be called!") 99 } 100 return m.ClaimCapabilityFn(ctx, cap, name) 101 } 102 103 func (m MockCapabilityKeeper) AuthenticateCapability(ctx sdk.Context, capability *capabilitytypes.Capability, name string) bool { 104 if m.AuthenticateCapabilityFn == nil { 105 panic("not supposed to be called!") 106 } 107 return m.AuthenticateCapabilityFn(ctx, capability, name) 108 } 109 110 var _ types.ICS20TransferPortSource = &MockIBCTransferKeeper{} 111 112 type MockIBCTransferKeeper struct { 113 GetPortFn func(ctx sdk.Context) string 114 } 115 116 func (m MockIBCTransferKeeper) Handler(methodName string) baseapp.MsgServiceHandler { 117 panic("implement me") 118 } 119 120 func (m MockIBCTransferKeeper) GetPort(ctx sdk.Context) string { 121 if m.GetPortFn == nil { 122 panic("not expected to be called") 123 } 124 return m.GetPortFn(ctx) 125 }