/
keeper.go
88 lines (74 loc) · 3.03 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
// Package keeper provides methods to initialize SDK keepers with local storage for test purposes
package keeper
import (
"testing"
"time"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
claimkeeper "github.com/ignite/modules/x/claim/keeper"
claimtypes "github.com/ignite/modules/x/claim/types"
)
var (
// ExampleTimestamp is a timestamp used as the current time for the context of the keepers returned from the package
ExampleTimestamp = time.Date(2020, time.January, 1, 12, 0, 0, 0, time.UTC)
// ExampleHeight is a block height used as the current block height for the context of test keeper
ExampleHeight = int64(1111)
)
// TestKeepers holds all keepers used during keeper tests for all modules
type TestKeepers struct {
T testing.TB
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
DistrKeeper distrkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
ClaimKeeper *claimkeeper.Keeper
}
// TestMsgServers holds all message servers used during keeper tests for all modules
type TestMsgServers struct {
T testing.TB
ClaimSrv claimtypes.MsgServer
}
// NewTestSetup returns initialized instances of all the keepers and message servers of the modules
func NewTestSetup(t testing.TB) (sdk.Context, TestKeepers, TestMsgServers) {
initializer := newInitializer()
paramKeeper := initializer.Param()
authKeeper := initializer.Auth()
bankKeeper := initializer.Bank(authKeeper)
stakingKeeper := initializer.Staking(authKeeper, bankKeeper)
distrKeeper := initializer.Distribution(authKeeper, bankKeeper, stakingKeeper)
claimKeeper := initializer.Claim(paramKeeper, authKeeper, distrKeeper, bankKeeper)
require.NoError(t, initializer.StateStore.LoadLatestVersion())
// Create a context using a custom timestamp
ctx := sdk.NewContext(initializer.StateStore, tmproto.Header{
Time: ExampleTimestamp,
Height: ExampleHeight,
}, false, log.NewNopLogger())
// Initialize community pool
distrKeeper.SetFeePool(ctx, distrtypes.InitialFeePool())
// Initialize params
err := distrKeeper.SetParams(ctx, distrtypes.DefaultParams())
require.NoError(t, err)
err = stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams())
require.NoError(t, err)
claimKeeper.SetParams(ctx, claimtypes.DefaultParams())
claimSrv := claimkeeper.NewMsgServerImpl(*claimKeeper)
return ctx, TestKeepers{
T: t,
AccountKeeper: authKeeper,
BankKeeper: bankKeeper,
DistrKeeper: distrKeeper,
StakingKeeper: stakingKeeper,
ClaimKeeper: claimKeeper,
}, TestMsgServers{
T: t,
ClaimSrv: claimSrv,
}
}