From 3bfc280c3c6b6fe4041e4d3bd5abd9b55f57c22e Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Fri, 13 Dec 2024 15:03:38 +0700 Subject: [PATCH 1/3] use context.Context --- testutil/sims/address_helpers.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testutil/sims/address_helpers.go b/testutil/sims/address_helpers.go index 0f6d85e275cc..57a851ba9d18 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" @@ -34,7 +35,7 @@ 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) } @@ -43,7 +44,7 @@ func AddTestAddrsIncremental(bankKeeper BankKeeper, stakingKeeper StakingKeeper, 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) } From a27c7c21180ddff37347071dfbc5ea78961c3dca Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Fri, 13 Dec 2024 15:10:49 +0700 Subject: [PATCH 2/3] more backport --- testutil/configurator/configurator.go | 2 +- testutil/sims/address_helpers.go | 4 ++-- x/staking/testutil/helpers.go | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index 98b248cb361b..17f44d72747b 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}}, diff --git a/testutil/sims/address_helpers.go b/testutil/sims/address_helpers.go index 57a851ba9d18..6e3c672e5f82 100644 --- a/testutil/sims/address_helpers.go +++ b/testutil/sims/address_helpers.go @@ -21,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) @@ -40,7 +40,7 @@ func AddTestAddrs(bankKeeper BankKeeper, stakingKeeper StakingKeeper, ctx contex } // 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) } diff --git a/x/staking/testutil/helpers.go b/x/staking/testutil/helpers.go index 8976c6a684b5..bd5b56c42c1d 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. From 7b27caf5fa75b555a2c7eda5971d1e692b5692ac Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Fri, 13 Dec 2024 15:15:10 +0700 Subject: [PATCH 3/3] more backport --- testutil/configurator/configurator.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index 17f44d72747b..82399afa10bd 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -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{