-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
646270c
commit e9592d3
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package keeper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/keeper" | ||
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/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" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/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" | ||
) | ||
|
||
func FeeburnKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { | ||
storeKey := sdk.NewKVStoreKey(types.StoreKey) | ||
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) | ||
|
||
db := tmdb.NewMemDB() | ||
stateStore := store.NewCommitMultiStore(db) | ||
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) | ||
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) | ||
require.NoError(t, stateStore.LoadLatestVersion()) | ||
|
||
registry := codectypes.NewInterfaceRegistry() | ||
cdc := codec.NewProtoCodec(registry) | ||
|
||
k := keeper.NewKeeper( | ||
cdc, | ||
storeKey, | ||
memStoreKey, | ||
authtypes.NewModuleAddress(govtypes.ModuleName), | ||
) | ||
|
||
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) | ||
|
||
// Initialize params | ||
_ = k.SetParams(ctx, types.DefaultParams()) | ||
|
||
return k, ctx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Package nullify provides methods to init nil values structs for test assertion. | ||
package nullify | ||
|
||
import ( | ||
"reflect" | ||
"unsafe" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
var ( | ||
coinType = reflect.TypeOf(sdk.Coin{}) | ||
coinsType = reflect.TypeOf(sdk.Coins{}) | ||
) | ||
|
||
// Fill analyze all struct fields and slices with | ||
// reflection and initialize the nil and empty slices, | ||
// structs, and pointers. | ||
func Fill(x interface{}) interface{} { | ||
v := reflect.Indirect(reflect.ValueOf(x)) | ||
switch v.Kind() { | ||
case reflect.Slice: | ||
for i := 0; i < v.Len(); i++ { | ||
obj := v.Index(i) | ||
objPt := reflect.NewAt(obj.Type(), unsafe.Pointer(obj.UnsafeAddr())).Interface() | ||
objPt = Fill(objPt) | ||
obj.Set(reflect.ValueOf(objPt)) | ||
} | ||
case reflect.Struct: | ||
for i := 0; i < v.NumField(); i++ { | ||
f := reflect.Indirect(v.Field(i)) | ||
if !f.CanSet() { | ||
continue | ||
} | ||
switch f.Kind() { | ||
case reflect.Slice: | ||
f.Set(reflect.MakeSlice(f.Type(), 0, 0)) | ||
case reflect.Struct: | ||
switch f.Type() { | ||
case coinType: | ||
coin := reflect.New(coinType).Interface() | ||
s := reflect.ValueOf(coin).Elem() | ||
f.Set(s) | ||
case coinsType: | ||
coins := reflect.New(coinsType).Interface() | ||
s := reflect.ValueOf(coins).Elem() | ||
f.Set(s) | ||
default: | ||
objPt := reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Interface() | ||
s := Fill(objPt) | ||
f.Set(reflect.ValueOf(s)) | ||
} | ||
} | ||
} | ||
} | ||
return reflect.Indirect(v).Interface() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package sample | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// AccAddress returns a sample account address | ||
func AccAddress() string { | ||
pk := ed25519.GenPrivKey().PubKey() | ||
addr := pk.Address() | ||
return sdk.AccAddress(addr).String() | ||
} |