/
globalfee.go
93 lines (81 loc) · 2.94 KB
/
globalfee.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
package keeper
import (
"context"
"testing"
"cosmossdk.io/store"
storetypes "cosmossdk.io/store/types"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
"github.com/public-awesome/stargaze/v14/app"
"github.com/public-awesome/stargaze/v14/x/globalfee/keeper"
"github.com/public-awesome/stargaze/v14/x/globalfee/types"
"github.com/stretchr/testify/require"
"cosmossdk.io/log"
storemetrics "cosmossdk.io/store/metrics"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
)
// GlobalFeeKeeper creates a testing keeper for the x/global module
func GlobalFeeKeeper(tb testing.TB) (keeper.Keeper, sdk.Context) {
tb.Helper()
storeKey := storetypes.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
tStoreKey := storetypes.NewTransientStoreKey("t_globalfee")
db := dbm.NewMemDB()
stateStore := store.NewCommitMultiStore(db, log.NewTestLogger(tb), storemetrics.NewNoOpMetrics())
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()
encoding := app.MakeEncodingConfig()
appCodec := encoding.Codec
paramsKeeper := paramskeeper.NewKeeper(appCodec, encoding.Amino, storeKey, tStoreKey)
paramsKeeper.Subspace(types.ModuleName).WithKeyTable(types.ParamKeyTable())
subspace, _ := paramsKeeper.GetSubspace(types.ModuleName)
wk := MockWasmKeeper{
HasContractInfoFn: func(_ context.Context, contractAddr sdk.AccAddress) bool {
switch contractAddr.String() {
case "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpjnp7du":
return true
case "cosmos1hfml4tzwlc3mvynsg6vtgywyx00wfkhrtpkx6t":
return true
case "cosmos144sh8vyv5nqfylmg4mlydnpe3l4w780jsrmf4k":
return true
}
return false
},
GetCodeInfoFn: func(_ context.Context, codeID uint64) *wasmtypes.CodeInfo {
if codeID == 1 {
return &wasmtypes.CodeInfo{
Creator: "cosmos144sh8vyv5nqfylmg4mlydnpe3l4w780jsrmf4k",
}
}
if codeID == 2 {
return &wasmtypes.CodeInfo{
Creator: "cosmos1hfml4tzwlc3mvynsg6vtgywyx00wfkhrtpkx6t",
}
}
if codeID == 3 {
return &wasmtypes.CodeInfo{
Creator: "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpjnp7du",
}
}
return nil
},
}
k := keeper.NewKeeper(
codec.NewProtoCodec(registry),
storeKey,
subspace,
wk,
"cosmos1a48wdtjn3egw7swhfkeshwdtjvs6hq9nlyrwut", // random addr for gov module
)
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
params := types.Params{PrivilegedAddresses: []string{}}
_ = k.SetParams(ctx, params)
return k, ctx
}