-
Notifications
You must be signed in to change notification settings - Fork 82
/
cron.go
109 lines (93 loc) · 3.62 KB
/
cron.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
package keeper
import (
"testing"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/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"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
"github.com/public-awesome/stargaze/v13/x/cron/keeper"
"github.com/public-awesome/stargaze/v13/x/cron/types"
"github.com/stretchr/testify/require"
)
// CronKeeper creates a testing keeper for the x/cron module
func CronKeeper(tb testing.TB) (keeper.Keeper, sdk.Context) {
tb.Helper()
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
tStoreKey := storetypes.NewTransientStoreKey("t_cron")
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
stateStore.MountStoreWithDB(tStoreKey, storetypes.StoreTypeTransient, db)
require.NoError(tb, stateStore.LoadLatestVersion())
registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
paramsKeeper := paramskeeper.NewKeeper(cdc, types.Amino, storeKey, tStoreKey)
paramsKeeper.Subspace(types.ModuleName).WithKeyTable(types.ParamKeyTable())
subspace, _ := paramsKeeper.GetSubspace(types.ModuleName)
wk := MockWasmKeeper{
HasContractInfoFn: func(_ sdk.Context, contractAddr sdk.AccAddress) bool {
switch contractAddr.String() {
case "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpjnp7du":
return true
case "cosmos1hfml4tzwlc3mvynsg6vtgywyx00wfkhrtpkx6t":
return true
case "cosmos144sh8vyv5nqfylmg4mlydnpe3l4w780jsrmf4k":
return true
}
return false
},
SudoFn: func(_ sdk.Context, _ sdk.AccAddress, _ []byte) ([]byte, error) {
return nil, nil
},
}
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
subspace,
wk,
"cosmos1a48wdtjn3egw7swhfkeshwdtjvs6hq9nlyrwut", // random addr for gov module
)
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
params := types.Params{AdminAddresses: []string{}}
_ = k.SetParams(ctx, params)
return k, ctx
}
type MockWasmKeeper struct {
HasContractInfoFn func(ctx sdk.Context, contractAddr sdk.AccAddress) bool
SudoFn func(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error)
GetCodeInfoFn func(ctx sdk.Context, codeID uint64) *wasmtypes.CodeInfo
GetContractInfoFn func(ctx sdk.Context, contractAddress sdk.AccAddress) *wasmtypes.ContractInfo
}
func (k MockWasmKeeper) HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool {
if k.HasContractInfoFn == nil {
panic("not supposed to be called!")
}
return k.HasContractInfoFn(ctx, contractAddress)
}
func (k MockWasmKeeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) {
if k.SudoFn == nil {
panic("not supposed to be called!")
}
return k.SudoFn(ctx, contractAddress, msg)
}
func (k MockWasmKeeper) GetCodeInfo(ctx sdk.Context, codeID uint64) *wasmtypes.CodeInfo {
if k.GetCodeInfoFn == nil {
panic("not supposed to be called!")
}
return k.GetCodeInfoFn(ctx, codeID)
}
func (k MockWasmKeeper) GetContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) *wasmtypes.ContractInfo {
if k.GetContractInfoFn == nil {
panic("not supposed to be called!")
}
return k.GetContractInfoFn(ctx, contractAddress)
}