/
cfevesting.go
131 lines (112 loc) · 4.27 KB
/
cfevesting.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package keeper
import (
appparams "github.com/chain4energy/c4e-chain/app/params"
"testing"
"time"
testenv "github.com/chain4energy/c4e-chain/testutil/env"
cfevestingtestutils "github.com/chain4energy/c4e-chain/testutil/module/cfevesting"
"github.com/chain4energy/c4e-chain/x/cfevesting/keeper"
"github.com/chain4energy/c4e-chain/x/cfevesting/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"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"
)
type ExtendedC4eVestingKeeperUtils struct {
cfevestingtestutils.C4eVestingKeeperUtils
Cdc *codec.ProtoCodec
StoreKey *storetypes.KVStoreKey
ParamsStore typesparams.Subspace
}
func NewExtendedC4eVestingKeeperUtils(
t *testing.T,
helperCfevestingKeeper *keeper.Keeper,
cdc *codec.ProtoCodec,
storeKey *storetypes.KVStoreKey,
paramsStore typesparams.Subspace) ExtendedC4eVestingKeeperUtils {
return ExtendedC4eVestingKeeperUtils{
C4eVestingKeeperUtils: cfevestingtestutils.NewC4eVestingKeeperUtils(t, helperCfevestingKeeper),
Cdc: cdc,
StoreKey: storeKey,
ParamsStore: paramsStore,
}
}
type AdditionalVestingKeeperData struct {
*codec.ProtoCodec
*storetypes.KVStoreKey
typesparams.Subspace
}
func CfevestingKeeperWithBlockHeightAndTimeAndStore(t *testing.T, blockHeight int64, blockTime time.Time, db *tmdb.MemDB,
stateStore storetypes.CommitMultiStore) (*keeper.Keeper, sdk.Context, AdditionalVestingKeeperData) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())
registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"Cfevesting",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
nil,
nil,
nil,
nil,
nil,
appparams.GetAuthority(),
)
header := tmproto.Header{}
header.Height = blockHeight
header.Time = blockTime
ctx := sdk.NewContext(stateStore, header, false, log.NewNopLogger())
// Initialize params
k.SetParams(ctx, types.DefaultParams())
return k, ctx, AdditionalVestingKeeperData{
ProtoCodec: cdc,
KVStoreKey: storeKey,
Subspace: paramsSubspace,
}
}
func CfevestingKeeperWithBlockHeightAndTime(t *testing.T, blockHeight int64, blockTime time.Time) (*keeper.Keeper, sdk.Context) {
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
k, ctx, _ := CfevestingKeeperWithBlockHeightAndTimeAndStore(t, blockHeight, blockTime, db, stateStore)
return k, ctx
}
func CfevestingKeeperWithBlockHeight(t *testing.T, blockHeight int64) (*keeper.Keeper, sdk.Context) {
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
k, ctx, _ := CfevestingKeeperWithBlockHeightAndTimeAndStore(t, blockHeight, testenv.TestEnvTime, db, stateStore)
return k, ctx
}
func CfevestingKeeper(t *testing.T) (*keeper.Keeper, sdk.Context) {
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
k, ctx, _ := CfevestingKeeperWithBlockHeightAndTimeAndStore(t, 0, testenv.TestEnvTime, db, stateStore)
return k, ctx
}
func CfevestingKeeperTestUtil(t *testing.T) (*cfevestingtestutils.C4eVestingKeeperUtils, *keeper.Keeper, sdk.Context) {
k, ctx := CfevestingKeeper(t)
utils := cfevestingtestutils.NewC4eVestingKeeperUtils(t, k)
return &utils, k, ctx
}
func CfevestingKeeperTestUtilWithCdc(t *testing.T) (*ExtendedC4eVestingKeeperUtils, *keeper.Keeper, sdk.Context) {
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
k, ctx, additionalData := CfevestingKeeperWithBlockHeightAndTimeAndStore(t, 0, testenv.TestEnvTime, db, stateStore)
utils := NewExtendedC4eVestingKeeperUtils(t, k, additionalData.ProtoCodec, additionalData.KVStoreKey, additionalData.Subspace)
return &utils, k, ctx
}