diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index 98b248cb36..82399afa10 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -163,7 +163,7 @@ func AuthModule() ModuleOption { Bech32Prefix: "cosmos", ModuleAccountPermissions: []*authmodulev1.ModuleAccountPermission{ {Account: "fee_collector"}, - {Account: testutil.DistributionModuleName}, + {Account: testutil.DistributionModuleName, Permissions: []string{"minter"}}, {Account: testutil.MintModuleName, Permissions: []string{"minter"}}, {Account: "bonded_tokens_pool", Permissions: []string{"burner", testutil.StakingModuleName}}, {Account: "not_bonded_tokens_pool", Permissions: []string{"burner", testutil.StakingModuleName}}, @@ -178,6 +178,18 @@ func AuthModule() ModuleOption { } } +func AuthModuleWithMaccPerms(maccPerms []*authmodulev1.ModuleAccountPermission) ModuleOption { + return func(config *Config) { + config.ModuleConfigs[testutil.AuthModuleName] = &appv1alpha1.ModuleConfig{ + Name: testutil.AuthModuleName, + Config: appconfig.WrapAny(&authmodulev1.Module{ + Bech32Prefix: "cosmos", + ModuleAccountPermissions: maccPerms, + }), + } + } +} + func ParamsModule() ModuleOption { return func(config *Config) { config.ModuleConfigs[testutil.ParamsModuleName] = &appv1alpha1.ModuleConfig{ diff --git a/testutil/sims/address_helpers.go b/testutil/sims/address_helpers.go index 0f6d85e275..6e3c672e5f 100644 --- a/testutil/sims/address_helpers.go +++ b/testutil/sims/address_helpers.go @@ -2,6 +2,7 @@ package sims import ( "bytes" + "context" "encoding/hex" "fmt" "strconv" @@ -20,7 +21,7 @@ const mintModuleName = "mint" type GenerateAccountStrategy func(int) []sdk.AccAddress // AddTestAddrsFromPubKeys adds the addresses into the SimApp providing only the public keys. -func AddTestAddrsFromPubKeys(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx sdk.Context, pubKeys []cryptotypes.PubKey, accAmt math.Int) { +func AddTestAddrsFromPubKeys(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx context.Context, pubKeys []cryptotypes.PubKey, accAmt math.Int) { bondDenom, err := stakingKeeper.BondDenom(ctx) if err != nil { panic(err) @@ -34,16 +35,16 @@ func AddTestAddrsFromPubKeys(bankKeeper BankKeeper, stakingKeeper StakingKeeper, // AddTestAddrs constructs and returns accNum amount of accounts with an // initial balance of accAmt in random order -func AddTestAddrs(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress { +func AddTestAddrs(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx context.Context, accNum int, accAmt math.Int) []sdk.AccAddress { return addTestAddrs(bankKeeper, stakingKeeper, ctx, accNum, accAmt, CreateRandomAccounts) } // AddTestAddrsIncremental constructs and returns accNum amount of accounts with an initial balance of accAmt in random order -func AddTestAddrsIncremental(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress { +func AddTestAddrsIncremental(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx context.Context, accNum int, accAmt math.Int) []sdk.AccAddress { return addTestAddrs(bankKeeper, stakingKeeper, ctx, accNum, accAmt, CreateIncrementalAccounts) } -func addTestAddrs(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx sdk.Context, accNum int, accAmt math.Int, strategy GenerateAccountStrategy) []sdk.AccAddress { +func addTestAddrs(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx context.Context, accNum int, accAmt math.Int, strategy GenerateAccountStrategy) []sdk.AccAddress { testAddrs := strategy(accNum) bondDenom, err := stakingKeeper.BondDenom(ctx) if err != nil { @@ -58,7 +59,7 @@ func addTestAddrs(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx sdk.Co return testAddrs } -func initAccountWithCoins(bankKeeper BankKeeper, ctx sdk.Context, addr sdk.AccAddress, coins sdk.Coins) { +func initAccountWithCoins(bankKeeper BankKeeper, ctx context.Context, addr sdk.AccAddress, coins sdk.Coins) { if err := bankKeeper.MintCoins(ctx, mintModuleName, coins); err != nil { panic(err) } diff --git a/x/staking/testutil/helpers.go b/x/staking/testutil/helpers.go index 8976c6a684..bd5b56c42c 100644 --- a/x/staking/testutil/helpers.go +++ b/x/staking/testutil/helpers.go @@ -23,14 +23,14 @@ type Helper struct { msgSrvr stakingtypes.MsgServer k *keeper.Keeper - Ctx sdk.Context + Ctx context.Context Commission stakingtypes.CommissionRates // Coin Denomination Denom string } // NewHelper creates a new instance of Helper. -func NewHelper(t *testing.T, ctx sdk.Context, k *keeper.Keeper) *Helper { +func NewHelper(t *testing.T, ctx context.Context, k *keeper.Keeper) *Helper { t.Helper() return &Helper{t, keeper.NewMsgServerImpl(k), k, ctx, ZeroCommission(), sdk.DefaultBondDenom} } @@ -125,20 +125,22 @@ func (sh *Helper) CheckValidator(addr sdk.ValAddress, status stakingtypes.BondSt } // TurnBlock calls EndBlocker and updates the block time -func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context { - sh.Ctx = sh.Ctx.WithHeaderInfo(header.Info{Time: newTime}) +func (sh *Helper) TurnBlock(newTime time.Time) context.Context { + sdkCtx := sdk.UnwrapSDKContext(sh.Ctx) + sh.Ctx = sdkCtx.WithHeaderInfo(header.Info{Time: newTime}) _, err := sh.k.EndBlocker(sh.Ctx) require.NoError(sh.t, err) - return sh.Ctx + return sdkCtx } // TurnBlockTimeDiff calls EndBlocker and updates the block time by adding the // duration to the current block time -func (sh *Helper) TurnBlockTimeDiff(diff time.Duration) sdk.Context { - sh.Ctx = sh.Ctx.WithHeaderInfo(header.Info{Time: sh.Ctx.HeaderInfo().Time.Add(diff)}) +func (sh *Helper) TurnBlockTimeDiff(diff time.Duration) context.Context { + sdkCtx := sdk.UnwrapSDKContext(sh.Ctx) + sh.Ctx = sdkCtx.WithHeaderInfo(header.Info{Time: sdkCtx.HeaderInfo().Time.Add(diff)}) _, err := sh.k.EndBlocker(sh.Ctx) require.NoError(sh.t, err) - return sh.Ctx + return sdkCtx } // ZeroCommission constructs a commission rates with all zeros.