-
Notifications
You must be signed in to change notification settings - Fork 19
/
keeper.go
94 lines (77 loc) · 3.01 KB
/
keeper.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
// Package keeper provides methods to initialize SDK keepers with local storage for test purposes
package keeper
import (
"testing"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
testkeeper "github.com/skip-mev/chaintestutil/keeper"
"github.com/stretchr/testify/require"
auctionkeeper "github.com/skip-mev/block-sdk/v2/x/auction/keeper"
auctiontypes "github.com/skip-mev/block-sdk/v2/x/auction/types"
)
// TestKeepers holds all keepers used during keeper tests for all modules
type TestKeepers struct {
testkeeper.TestKeepers
AuctionKeeper auctionkeeper.Keeper
}
// TestMsgServers holds all message servers used during keeper tests for all modules
type TestMsgServers struct {
testkeeper.TestMsgServers
AuctionMsgServer auctiontypes.MsgServer
}
var additionalMaccPerms = map[string][]string{
auctiontypes.ModuleName: nil,
}
// NewTestSetup returns initialized instances of all the keepers and message servers of the modules
func NewTestSetup(t testing.TB, options ...testkeeper.SetupOption) (sdk.Context, TestKeepers, TestMsgServers) {
options = append(options, testkeeper.WithAdditionalModuleAccounts(additionalMaccPerms))
_, tk, tms := testkeeper.NewTestSetup(t, options...)
// initialize extra keeper
auctionKeeper := Auction(tk.Initializer, tk.AccountKeeper, tk.BankKeeper, tk.DistrKeeper, tk.StakingKeeper)
require.NoError(t, tk.Initializer.LoadLatest())
// initialize msg servers
auctionMsgSrv := auctionkeeper.NewMsgServerImpl(auctionKeeper)
ctx := sdk.NewContext(tk.Initializer.StateStore, tmproto.Header{
Time: testkeeper.ExampleTimestamp,
Height: testkeeper.ExampleHeight,
}, false, log.NewNopLogger())
err := auctionKeeper.SetParams(ctx, auctiontypes.DefaultParams())
require.NoError(t, err)
testKeepers := TestKeepers{
TestKeepers: tk,
AuctionKeeper: auctionKeeper,
}
testMsgServers := TestMsgServers{
TestMsgServers: tms,
AuctionMsgServer: auctionMsgSrv,
}
return ctx, testKeepers, testMsgServers
}
// Auction initializes the auction module using the testkeepers intializer.
func Auction(
initializer *testkeeper.Initializer,
authKeeper authkeeper.AccountKeeper,
bankKeeper bankkeeper.Keeper,
distrKeeper distrkeeper.Keeper,
stakingKeeper *stakingkeeper.Keeper,
) auctionkeeper.Keeper {
storeKey := storetypes.NewKVStoreKey(auctiontypes.StoreKey)
initializer.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, initializer.DB)
return auctionkeeper.NewKeeper(
initializer.Codec,
storeKey,
authKeeper,
bankKeeper,
distrKeeper,
stakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
}