/
protocols.go
100 lines (81 loc) · 3.04 KB
/
protocols.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
package keeper
import (
"testing"
"github.com/bitbadges/bitbadgeschain/x/protocols/keeper"
"github.com/bitbadges/bitbadgeschain/x/protocols/types"
tmdb "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/stretchr/testify/require"
)
// protocolsChannelKeeper is a stub of cosmosibckeeper.ChannelKeeper.
type protocolsChannelKeeper struct{}
func (protocolsChannelKeeper) GetChannel(ctx sdk.Context, portID, channelID string) (channeltypes.Channel, bool) {
return channeltypes.Channel{}, false
}
func (protocolsChannelKeeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) {
return 0, false
}
func (protocolsChannelKeeper) SendPacket(
ctx sdk.Context,
channelCap *capabilitytypes.Capability,
sourcePort string,
sourceChannel string,
timeoutHeight clienttypes.Height,
timeoutTimestamp uint64,
data []byte,
) (uint64, error) {
return 0, nil
}
func (protocolsChannelKeeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error {
return nil
}
// protocolsportKeeper is a stub of cosmosibckeeper.PortKeeper
type protocolsPortKeeper struct{}
func (protocolsPortKeeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability {
return &capabilitytypes.Capability{}
}
func ProtocolsKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
logger := log.NewNopLogger()
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())
registry := codectypes.NewInterfaceRegistry()
appCodec := codec.NewProtoCodec(registry)
capabilityKeeper := capabilitykeeper.NewKeeper(appCodec, storeKey, memStoreKey)
badgesKeeper, _ := BadgesKeeper(t)
paramsSubspace := typesparams.NewSubspace(appCodec,
types.Amino,
storeKey,
memStoreKey,
"ProtocolsParams",
)
k := keeper.NewKeeper(
appCodec,
storeKey,
memStoreKey,
paramsSubspace,
protocolsChannelKeeper{},
protocolsPortKeeper{},
capabilityKeeper.ScopeToModule("ProtocolsScopedKeeper"),
badgesKeeper,
)
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, logger)
// Initialize params
k.SetParams(ctx, types.DefaultParams())
return k, ctx
}