/
gateway.go
59 lines (48 loc) · 1.91 KB
/
gateway.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
package keeper
import (
"context"
"testing"
"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
mocks "github.com/pokt-network/poktroll/testutil/gateway/mocks"
"github.com/pokt-network/poktroll/x/gateway/keeper"
"github.com/pokt-network/poktroll/x/gateway/types"
)
func GatewayKeeper(t testing.TB) (keeper.Keeper, context.Context) {
t.Helper()
storeKey := storetypes.NewKVStoreKey(types.StoreKey)
db := dbm.NewMemDB()
stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
require.NoError(t, stateStore.LoadLatestVersion())
registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
ctrl := gomock.NewController(t)
mockBankKeeper := mocks.NewMockBankKeeper(ctrl)
mockBankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), types.ModuleName, gomock.Any()).AnyTimes()
mockBankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, gomock.Any(), gomock.Any()).AnyTimes()
k := keeper.NewKeeper(
cdc,
runtime.NewKVStoreService(storeKey),
log.NewNopLogger(),
authority.String(),
mockBankKeeper,
)
ctx := sdk.NewContext(stateStore, cmtproto.Header{}, false, log.NewNopLogger())
// Initialize params
require.NoError(t, k.SetParams(ctx, types.DefaultParams()))
return k, ctx
}