diff --git a/Makefile b/Makefile index bcc1db4fc8..3c139f0daf 100644 --- a/Makefile +++ b/Makefile @@ -384,7 +384,7 @@ benchmark: ### Linting ### ############################################################################### -golangci_version=v1.55.0 +golangci_version=v1.56.2 #? setup-pre-commit: Set pre-commit git hook setup-pre-commit: diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 1ea61de023..8001d48d07 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -176,7 +176,6 @@ func TestAppImportExport(t *testing.T) { ctxA := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()}) ctxB := newApp.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()}) _, err = newApp.ModuleManager.InitGenesis(ctxB, app.AppCodec(), genesisState) - if err != nil { if strings.Contains(err.Error(), "validator set is empty after InitGenesis") { logger.Info("Skipping simulation as all validators have been unbonded") diff --git a/x/slashing/keeper/slash_redelegation_test.go b/tests/integration/slashing/keeper/slash_redelegation_test.go similarity index 81% rename from x/slashing/keeper/slash_redelegation_test.go rename to tests/integration/slashing/keeper/slash_redelegation_test.go index cc32f9ebdf..d50a012765 100644 --- a/x/slashing/keeper/slash_redelegation_test.go +++ b/tests/integration/slashing/keeper/slash_redelegation_test.go @@ -1,41 +1,52 @@ package keeper_test import ( + "context" "fmt" "testing" "time" + "github.com/stretchr/testify/require" + "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/math" + authkeeper "cosmossdk.io/x/auth/keeper" bankkeeper "cosmossdk.io/x/bank/keeper" banktestutil "cosmossdk.io/x/bank/testutil" + distributionkeeper "cosmossdk.io/x/distribution/keeper" slashingkeeper "cosmossdk.io/x/slashing/keeper" - "cosmossdk.io/x/slashing/testutil" stakingkeeper "cosmossdk.io/x/staking/keeper" stakingtypes "cosmossdk.io/x/staking/types" - distributionkeeper "cosmossdk.io/x/distribution/keeper" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - + "github.com/cosmos/cosmos-sdk/tests/integration/slashing" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestSlashRedelegation(t *testing.T) { // setting up - var stakingKeeper *stakingkeeper.Keeper - var bankKeeper bankkeeper.Keeper - var slashKeeper slashingkeeper.Keeper - var distrKeeper distributionkeeper.Keeper + var ( + authKeeper authkeeper.AccountKeeper + stakingKeeper *stakingkeeper.Keeper + bankKeeper bankkeeper.Keeper + slashKeeper slashingkeeper.Keeper + distrKeeper distributionkeeper.Keeper + ) - app, err := simtestutil.Setup(depinject.Configs( - depinject.Supply(log.NewNopLogger()), - testutil.AppConfig, - ), &stakingKeeper, &bankKeeper, &slashKeeper, &distrKeeper) + app, err := simtestutil.Setup( + depinject.Configs( + depinject.Supply(log.NewNopLogger()), + slashing.AppConfig, + ), + &stakingKeeper, + &bankKeeper, + &slashKeeper, + &distrKeeper, + &authKeeper, + ) require.NoError(t, err) // get sdk context, staking msg server and bond denom @@ -56,8 +67,8 @@ func TestSlashRedelegation(t *testing.T) { // fund acc 1 and acc 2 testCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, stakingKeeper.TokensFromConsensusPower(ctx, 10))) - banktestutil.FundAccount(ctx, bankKeeper, testAcc1, testCoins) - banktestutil.FundAccount(ctx, bankKeeper, testAcc2, testCoins) + fundAccount(t, ctx, bankKeeper, authKeeper, testAcc1, testCoins) + fundAccount(t, ctx, bankKeeper, authKeeper, testAcc2, testCoins) balance1Before := bankKeeper.GetBalance(ctx, testAcc1, bondDenom) balance2Before := bankKeeper.GetBalance(ctx, testAcc2, bondDenom) @@ -68,7 +79,7 @@ func TestSlashRedelegation(t *testing.T) { // creating evil val evilValAddr := sdk.ValAddress(evilValPubKey.Address()) - banktestutil.FundAccount(ctx, bankKeeper, sdk.AccAddress(evilValAddr), testCoins) + fundAccount(t, ctx, bankKeeper, authKeeper, sdk.AccAddress(evilValAddr), testCoins) createValMsg1, _ := stakingtypes.NewMsgCreateValidator( evilValAddr.String(), evilValPubKey, testCoins[0], stakingtypes.Description{Details: "test"}, stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)), math.OneInt()) _, err = stakingMsgServer.CreateValidator(ctx, createValMsg1) @@ -76,7 +87,7 @@ func TestSlashRedelegation(t *testing.T) { // creating good val goodValAddr := sdk.ValAddress(goodValPubKey.Address()) - banktestutil.FundAccount(ctx, bankKeeper, sdk.AccAddress(goodValAddr), testCoins) + fundAccount(t, ctx, bankKeeper, authKeeper, sdk.AccAddress(goodValAddr), testCoins) createValMsg2, _ := stakingtypes.NewMsgCreateValidator( goodValAddr.String(), goodValPubKey, testCoins[0], stakingtypes.Description{Details: "test"}, stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0)), math.OneInt()) _, err = stakingMsgServer.CreateValidator(ctx, createValMsg2) @@ -99,7 +110,7 @@ func TestSlashRedelegation(t *testing.T) { require.NoError(t, err) // next block, commit height 2, move to height 3 - // with the new delegations, evil val increases in voting power and commit byzantine behaviour at height 3 consensus + // with the new delegations, evil val increases in voting power and commit byzantine behavior at height 3 consensus // at the same time, acc 1 and acc 2 withdraw delegation from evil val ctx, err = simtestutil.NextBlock(app, ctx, time.Duration(1)) require.NoError(t, err) @@ -126,9 +137,9 @@ func TestSlashRedelegation(t *testing.T) { require.NoError(t, err) // next block, commit height 3, move to height 4 - // Slash evil val for byzantine behaviour at height 3 consensus, + // Slash evil val for byzantine behavior at height 3 consensus, // at which acc 1 and acc 2 still contributed to evil val voting power - // even tho they undelegate at block 3, the valset update is applied after commited block 3 when height 3 consensus already passes + // even tho they undelegate at block 3, the valset update is applied after committed block 3 when height 3 consensus already passes ctx, err = simtestutil.NextBlock(app, ctx, time.Duration(1)) require.NoError(t, err) @@ -163,3 +174,14 @@ func TestSlashRedelegation(t *testing.T) { require.Equal(t, balance1AfterSlashing.Amount.Mul(math.NewIntFromUint64(10)).String(), balance1Before.Amount.String()) require.Equal(t, balance2AfterSlashing.Amount.Mul(math.NewIntFromUint64(10)).String(), balance2Before.Amount.String()) } + +func fundAccount(t *testing.T, ctx context.Context, bankKeeper bankkeeper.Keeper, authKeeper authkeeper.AccountKeeper, addr sdk.AccAddress, amount sdk.Coins) { + t.Helper() + + if authKeeper.GetAccount(ctx, addr) == nil { + addrAcc := authKeeper.NewAccountWithAddress(ctx, addr) + authKeeper.SetAccount(ctx, addrAcc) + } + + require.NoError(t, banktestutil.FundAccount(ctx, bankKeeper, addr, amount)) +} diff --git a/x/distribution/keeper/genesis.go b/x/distribution/keeper/genesis.go index 2abc164561..ce4a178401 100644 --- a/x/distribution/keeper/genesis.go +++ b/x/distribution/keeper/genesis.go @@ -121,7 +121,6 @@ func (k Keeper) InitGenesis(ctx context.Context, data types.GenesisState) { ), evt.ValidatorSlashEvent, ) - if err != nil { panic(err) } @@ -256,7 +255,6 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { return false, nil }, ) - if err != nil { panic(err) } diff --git a/x/distribution/keeper/grpc_query.go b/x/distribution/keeper/grpc_query.go index 16039f340f..38889665a0 100644 --- a/x/distribution/keeper/grpc_query.go +++ b/x/distribution/keeper/grpc_query.go @@ -330,7 +330,6 @@ func (k Querier) DelegatorValidators(ctx context.Context, req *types.QueryDelega return false }, ) - if err != nil { return nil, err } diff --git a/x/distribution/keeper/invariants.go b/x/distribution/keeper/invariants.go index 1bc6e23e4e..04f3294320 100644 --- a/x/distribution/keeper/invariants.go +++ b/x/distribution/keeper/invariants.go @@ -153,7 +153,6 @@ func ReferenceCountInvariant(k Keeper) sdk.Invariant { return false, nil }, ) - if err != nil { panic(err) } @@ -168,7 +167,6 @@ func ReferenceCountInvariant(k Keeper) sdk.Invariant { return false, nil }, ) - if err != nil { panic(err) } diff --git a/x/group/simulation/operations.go b/x/group/simulation/operations.go index ec84ccb602..392ac9c275 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -959,7 +959,6 @@ func SimulateMsgWithdrawProposal( } _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) - if err != nil { if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") { return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "no-op:group/group-policy was modified"), nil, nil @@ -1067,7 +1066,6 @@ func SimulateMsgVote( } _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) - if err != nil { if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") { return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "no-op:group/group-policy was modified"), nil, nil diff --git a/x/staking/keeper/delegation.go b/x/staking/keeper/delegation.go index 6b70d5121a..c5dea74ea0 100644 --- a/x/staking/keeper/delegation.go +++ b/x/staking/keeper/delegation.go @@ -431,7 +431,6 @@ func (k Keeper) GetRedelegations(ctx context.Context, delegator sdk.AccAddress, i++ return false, nil }) - if err != nil { return nil, err } diff --git a/x/staking/keeper/grpc_query.go b/x/staking/keeper/grpc_query.go index 942d299973..5dd6f46d69 100644 --- a/x/staking/keeper/grpc_query.go +++ b/x/staking/keeper/grpc_query.go @@ -118,7 +118,6 @@ func (k Querier) ValidatorDelegations(ctx context.Context, req *types.QueryValid return delegation, nil }, query.WithCollectionPaginationPairPrefix[sdk.ValAddress, sdk.AccAddress](valAddr), ) - if err != nil { delegations, pageResponse, err := k.getValidatorDelegationsLegacy(ctx, req) if err != nil {