Skip to content

Commit

Permalink
fix: depinject issue with authority
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Jul 23, 2024
1 parent 0695900 commit 041b1fd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ debug_container.dot
build/

go.work.sum
debug_*.*
4 changes: 4 additions & 0 deletions keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (k *Keeper) SetTestAccountKeeper(ak AccountKeeper) {
k.accountKeeper = ak
}

func (k *Keeper) SetTestAuthority(addr string) {
k.authority = addr
}

func (k Keeper) GetAdmin(ctx context.Context) string {
return k.authority
}
Expand Down
12 changes: 9 additions & 3 deletions module/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"cosmossdk.io/depinject"
"cosmossdk.io/log"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/strangelove-ventures/poa"
modulev1 "github.com/strangelove-ventures/poa/api/module/v1"
"github.com/strangelove-ventures/poa/keeper"
Expand All @@ -38,15 +40,14 @@ type ModuleInputs struct {
depinject.In

Cdc codec.Codec
Config *modulev1.Module
StoreService store.KVStoreService
AddressCodec address.Codec

StakingKeeper keeper.StakingKeeper
SlashingKeeper keeper.SlashingKeeper
BankKeeper keeper.BankKeeper
AccountKeeper keeper.AccountKeeper // for testing

Authority string
}

type ModuleOutputs struct {
Expand All @@ -57,7 +58,12 @@ type ModuleOutputs struct {
}

func ProvideModule(in ModuleInputs) ModuleOutputs {
k := keeper.NewKeeper(in.Cdc, in.StoreService, in.StakingKeeper, in.SlashingKeeper, in.BankKeeper, log.NewLogger(os.Stderr), in.Authority)
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
if len(in.Config.Admins) > 0 && in.Config.Admins[0] != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Admins[0])
}

k := keeper.NewKeeper(in.Cdc, in.StoreService, in.StakingKeeper, in.SlashingKeeper, in.BankKeeper, log.NewLogger(os.Stderr), authority.String())
k.SetTestAccountKeeper(in.AccountKeeper) // for testing
m := NewAppModule(in.Cdc, k)

Expand Down
4 changes: 3 additions & 1 deletion simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func SimulateMsgCreateValidator(txGen client.TxConfig, k keeper.Keeper) simtypes

// Generate a random self-delegation amount between 1 and balance
amount := sdkmath.NewInt(r.Int63n(balance.Amount.Int64()-1) + 1)
if err != nil {
if amount.IsNegative() {
return simtypes.NoOpMsg(poatypes.ModuleName, msgType, "unable to generate positive amount"), nil, err
}

Expand Down Expand Up @@ -196,6 +196,8 @@ func SimulateMsgRemoveValidator(txGen client.TxConfig, k keeper.Keeper) simtypes
func SimulateMsgSetPower(txGen client.TxConfig, k keeper.Keeper) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
k.SetTestAuthority(accs[0].Address.String())

msgType := sdk.MsgTypeURL(&poatypes.MsgSetPower{})

validators, err := k.GetStakingKeeper().GetAllValidators(ctx)
Expand Down

0 comments on commit 041b1fd

Please sign in to comment.