Skip to content

Commit

Permalink
Refactored provider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Jul 17, 2021
1 parent c57779d commit 90bffeb
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 163 deletions.
4 changes: 4 additions & 0 deletions x/provider/expected/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ type AccountKeeper interface {
GetAccount(ctx sdk.Context, address sdk.AccAddress) authtypes.AccountI
}

type BankKeeper interface {
SpendableCoins(ctx sdk.Context, address sdk.AccAddress) sdk.Coins
}

type DistributionKeeper interface {
FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error
}
5 changes: 4 additions & 1 deletion x/provider/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, state *types.GenesisState) {
}

func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return types.NewGenesisState(k.GetProviders(ctx, 0, 0), k.GetParams(ctx))
return types.NewGenesisState(
k.GetProviders(ctx, 0, 0),
k.GetParams(ctx),
)
}
6 changes: 0 additions & 6 deletions x/provider/keeper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

// AccountKeeper Wrapper
func (k *Keeper) GetAccount(ctx sdk.Context, address sdk.AccAddress) authtypes.AccountI {
return k.account.GetAccount(ctx, address)
}

func (k *Keeper) FundCommunityPool(ctx sdk.Context, from sdk.AccAddress, coin sdk.Coin) error {
return k.distribution.FundCommunityPool(ctx, sdk.NewCoins(coin), from)
}
5 changes: 0 additions & 5 deletions x/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Keeper struct {
key sdk.StoreKey
params paramstypes.Subspace
distribution expected.DistributionKeeper
account expected.AccountKeeper
}

func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, params paramstypes.Subspace) Keeper {
Expand All @@ -33,10 +32,6 @@ func (k *Keeper) WithDistributionKeeper(keeper expected.DistributionKeeper) {
k.distribution = keeper
}

func (k *Keeper) WithAccountKeeper(keeper expected.AccountKeeper) {
k.account = keeper
}

func (k *Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
}
Expand Down
10 changes: 5 additions & 5 deletions x/provider/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/kv"

"github.com/sentinel-official/hub/x/provider/types"
)

func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string {
decoderFn := func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
if bytes.Equal(kvA.Key[:1], types.ProviderKeyPrefix) {
var providerA, providerB types.Provider
cdc.MustUnmarshalBinaryBare(kvA.Value, &providerA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &providerB)
return fmt.Sprintf("%s\n%s", providerA, providerB)

return fmt.Sprintf("%v\n%v", providerA, providerB)
}

panic(fmt.Sprintf("invalid provider key prefix: %X", kvA.Key[:1]))
panic(fmt.Sprintf("invalid key prefix %X", kvA.Key[:1]))
}

return decoderFn
}
39 changes: 23 additions & 16 deletions x/provider/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/sentinel-official/hub/x/provider/types"
)

func RandomizedGenesisState(simState *module.SimulationState) *types.GenesisState {

var deposit sdk.Coin

depositSim := func(r *rand.Rand) {
deposit = getRandomDeposit(r)
}

simState.AppParams.GetOrGenerate(simState.Cdc, string(types.KeyDeposit), &deposit, simState.Rand, depositSim)

params := types.NewParams(deposit)
providers := getRandomProviders(simState.Rand)

state := types.NewGenesisState(providers, params)

return state
func RandomizedGenesisState(state *module.SimulationState) *types.GenesisState {
var (
deposit sdk.Coin
)

state.AppParams.GetOrGenerate(
state.Cdc,
string(types.KeyDeposit),
&deposit,
state.Rand,
func(r *rand.Rand) {
deposit = sdk.NewInt64Coin(
sdk.DefaultBondDenom,
r.Int63n(MaxDepositAmount),
)
},
)

return types.NewGenesisState(
RandomProviders(state.Rand, state.Accounts),
types.NewParams(deposit),
)
}
Loading

0 comments on commit 90bffeb

Please sign in to comment.