From 5839c3a600440022f0e76fa5baaf323716a8104e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 25 Aug 2023 16:07:24 +0200 Subject: [PATCH] chore: bump golangci-lint to v1.54.2 (#17538) --- Makefile | 2 +- .../secp256k1/internal/secp256k1/secp256_test.go | 3 +-- internal/conv/string.go | 9 +-------- internal/util.go | 16 ---------------- store/internal/conv/string.go | 9 +-------- .../staking/keeper/msg_server_test.go | 16 +++++++++------- tools/cosmovisor/args_test.go | 2 ++ tools/cosmovisor/cmd/cosmovisor/init_test.go | 2 ++ x/auth/tx/query.go | 2 ++ x/authz/keeper/grpc_query_test.go | 2 ++ x/bank/simulation/genesis_test.go | 2 ++ x/consensus/keeper/keeper_test.go | 2 ++ x/distribution/simulation/genesis_test.go | 2 ++ x/gov/migrations/v3/convert_test.go | 2 ++ x/gov/simulation/genesis_test.go | 2 ++ x/group/keeper/grpc_query_test.go | 7 +++++++ x/group/keeper/keeper.go | 2 ++ x/mint/simulation/genesis_test.go | 2 ++ x/nft/internal/conv/string.go | 9 +-------- x/slashing/simulation/genesis_test.go | 2 ++ x/staking/simulation/genesis_test.go | 2 ++ x/upgrade/internal/conv/string.go | 9 +-------- x/upgrade/keeper/grpc_query_test.go | 2 ++ 23 files changed, 50 insertions(+), 58 deletions(-) delete mode 100644 internal/util.go diff --git a/Makefile b/Makefile index 06f0f03bc5a5..de65f7e34ba6 100644 --- a/Makefile +++ b/Makefile @@ -369,7 +369,7 @@ benchmark: ### Linting ### ############################################################################### -golangci_version=v1.53.3 +golangci_version=v1.54.2 lint-install: @echo "--> Installing golangci-lint $(golangci_version)" diff --git a/crypto/keys/secp256k1/internal/secp256k1/secp256_test.go b/crypto/keys/secp256k1/internal/secp256k1/secp256_test.go index 4b0daef0def8..04011643bea0 100644 --- a/crypto/keys/secp256k1/internal/secp256k1/secp256_test.go +++ b/crypto/keys/secp256k1/internal/secp256k1/secp256_test.go @@ -24,8 +24,7 @@ func generateKeyPair() (pubkey, privkey []byte) { if err != nil { panic(err) } - pubkey = elliptic.Marshal(S256(), key.X, key.Y) - + pubkey = elliptic.Marshal(S256(), key.X, key.Y) //nolint:staticcheck // crypto will be refactored soon. privkey = make([]byte, 32) blob := key.D.Bytes() copy(privkey[32-len(blob):], blob) diff --git a/internal/conv/string.go b/internal/conv/string.go index ab2b7f44b38a..96d89c3a5fff 100644 --- a/internal/conv/string.go +++ b/internal/conv/string.go @@ -1,20 +1,13 @@ package conv import ( - "reflect" "unsafe" ) // UnsafeStrToBytes uses unsafe to convert string into byte array. Returned bytes // must not be altered after this function is called as it will cause a segmentation fault. func UnsafeStrToBytes(s string) []byte { - var buf []byte - sHdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) - bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) - bufHdr.Data = sHdr.Data - bufHdr.Cap = sHdr.Len - bufHdr.Len = sHdr.Len - return buf + return unsafe.Slice(unsafe.StringData(s), len(s)) // ref https://github.com/golang/go/issues/53003#issuecomment-1140276077 } // UnsafeBytesToStr is meant to make a zero allocation conversion diff --git a/internal/util.go b/internal/util.go deleted file mode 100644 index 97e3b4d1654f..000000000000 --- a/internal/util.go +++ /dev/null @@ -1,16 +0,0 @@ -package util - -import ( - "fmt" -) - -func CombineErrors(ret, also error, desc string) error { - if also != nil { - if ret != nil { - ret = fmt.Errorf("%w; %v: %v", ret, desc, also) - } else { - ret = also - } - } - return ret -} diff --git a/store/internal/conv/string.go b/store/internal/conv/string.go index ab2b7f44b38a..96d89c3a5fff 100644 --- a/store/internal/conv/string.go +++ b/store/internal/conv/string.go @@ -1,20 +1,13 @@ package conv import ( - "reflect" "unsafe" ) // UnsafeStrToBytes uses unsafe to convert string into byte array. Returned bytes // must not be altered after this function is called as it will cause a segmentation fault. func UnsafeStrToBytes(s string) []byte { - var buf []byte - sHdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) - bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) - bufHdr.Data = sHdr.Data - bufHdr.Cap = sHdr.Len - bufHdr.Len = sHdr.Len - return buf + return unsafe.Slice(unsafe.StringData(s), len(s)) // ref https://github.com/golang/go/issues/53003#issuecomment-1140276077 } // UnsafeBytesToStr is meant to make a zero allocation conversion diff --git a/tests/integration/staking/keeper/msg_server_test.go b/tests/integration/staking/keeper/msg_server_test.go index f84c305795dc..a3e79fc863ab 100644 --- a/tests/integration/staking/keeper/msg_server_test.go +++ b/tests/integration/staking/keeper/msg_server_test.go @@ -159,16 +159,18 @@ func TestCancelUnbondingDelegation(t *testing.T) { }, } - for _, testCase := range testCases { - t.Run(testCase.name, func(t *testing.T) { - _, err := msgServer.CancelUnbondingDelegation(ctx, &testCase.req) - if testCase.exceptErr { - assert.ErrorContains(t, err, testCase.expErrMsg) + for _, tc := range testCases { + tc := tc + + t.Run(tc.name, func(t *testing.T) { + _, err := msgServer.CancelUnbondingDelegation(ctx, &tc.req) + if tc.exceptErr { + assert.ErrorContains(t, err, tc.expErrMsg) } else { assert.NilError(t, err) balanceForNotBondedPool := f.bankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom) - assert.DeepEqual(t, balanceForNotBondedPool, moduleBalance.Sub(testCase.req.Amount)) - moduleBalance = moduleBalance.Sub(testCase.req.Amount) + assert.DeepEqual(t, balanceForNotBondedPool, moduleBalance.Sub(tc.req.Amount)) + moduleBalance = moduleBalance.Sub(tc.req.Amount) } }) } diff --git a/tools/cosmovisor/args_test.go b/tools/cosmovisor/args_test.go index 4645a562da94..e161d229e7db 100644 --- a/tools/cosmovisor/args_test.go +++ b/tools/cosmovisor/args_test.go @@ -764,6 +764,8 @@ func (s *argsTestSuite) TestGetConfigFromEnv() { } for _, tc := range tests { + tc := tc + s.T().Run(tc.name, func(t *testing.T) { s.setEnv(t, &tc.envVals) cfg, err := GetConfigFromEnv() diff --git a/tools/cosmovisor/cmd/cosmovisor/init_test.go b/tools/cosmovisor/cmd/cosmovisor/init_test.go index d4d08e7b6aa1..1ec40e8eb7e8 100644 --- a/tools/cosmovisor/cmd/cosmovisor/init_test.go +++ b/tools/cosmovisor/cmd/cosmovisor/init_test.go @@ -325,6 +325,8 @@ func (s *InitTestSuite) TestInitializeCosmovisorNegativeValidation() { } for _, tc := range tests { + tc := tc + s.T().Run(tc.name, func(t *testing.T) { s.setEnv(t, &tc.env) buffer, logger := s.NewCapturingLogger() diff --git a/x/auth/tx/query.go b/x/auth/tx/query.go index 9733f7f8c156..318c44cb851c 100644 --- a/x/auth/tx/query.go +++ b/x/auth/tx/query.go @@ -116,6 +116,8 @@ func getBlocksForTxResults(clientCtx client.Context, resTxs []*coretypes.ResultT resBlocks := make(map[int64]*coretypes.ResultBlock) for _, resTx := range resTxs { + resTx := resTx + if _, ok := resBlocks[resTx.Height]; !ok { resBlock, err := node.Block(context.Background(), &resTx.Height) if err != nil { diff --git a/x/authz/keeper/grpc_query_test.go b/x/authz/keeper/grpc_query_test.go index 00d16f96381a..c7054f164d4a 100644 --- a/x/authz/keeper/grpc_query_test.go +++ b/x/authz/keeper/grpc_query_test.go @@ -261,6 +261,8 @@ func (suite *TestSuite) TestGRPCQueryGranteeGrants() { } for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { tc.preRun() result, err := queryClient.GranteeGrants(gocontext.Background(), &tc.request) diff --git a/x/bank/simulation/genesis_test.go b/x/bank/simulation/genesis_test.go index 4f4ec400f033..57490ca6c51f 100644 --- a/x/bank/simulation/genesis_test.go +++ b/x/bank/simulation/genesis_test.go @@ -79,6 +79,8 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { + tt := tt + require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index 019a38506fc2..2d39d1ca2591 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -114,6 +114,8 @@ func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() { } for _, tc := range testCases { + tc := tc + s.Run(tc.msg, func() { s.SetupTest() // reset diff --git a/x/distribution/simulation/genesis_test.go b/x/distribution/simulation/genesis_test.go index 62e26f451503..f051551f013e 100644 --- a/x/distribution/simulation/genesis_test.go +++ b/x/distribution/simulation/genesis_test.go @@ -73,6 +73,8 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { + tt := tt + require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/gov/migrations/v3/convert_test.go b/x/gov/migrations/v3/convert_test.go index 0a1f8f31fab5..cc1ae9cbeefe 100644 --- a/x/gov/migrations/v3/convert_test.go +++ b/x/gov/migrations/v3/convert_test.go @@ -152,6 +152,8 @@ func TestConvertToLegacyTallyResult(t *testing.T) { }, } for name, tc := range testCases { + tc := tc + t.Run(name, func(t *testing.T) { _, err := v3.ConvertToLegacyTallyResult(&tc.tallyResult) if tc.expErr { diff --git a/x/gov/simulation/genesis_test.go b/x/gov/simulation/genesis_test.go index 573d10c56e23..c1491eef39ec 100644 --- a/x/gov/simulation/genesis_test.go +++ b/x/gov/simulation/genesis_test.go @@ -91,6 +91,8 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { + tt := tt + require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/group/keeper/grpc_query_test.go b/x/group/keeper/grpc_query_test.go index f71f86a84e6a..024b18e99b12 100644 --- a/x/group/keeper/grpc_query_test.go +++ b/x/group/keeper/grpc_query_test.go @@ -119,6 +119,8 @@ func TestQueryGroupInfo(t *testing.T) { } for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { _, err := fixture.queryClient.GroupInfo(fixture.ctx, &tc.req) if tc.expErrMsg != "" { @@ -157,6 +159,7 @@ func TestQueryGroupPolicyInfo(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { _, err := fixture.queryClient.GroupPolicyInfo(fixture.ctx, &tc.req) if tc.expErrMsg != "" { @@ -197,6 +200,7 @@ func TestQueryGroupMembers(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { resp, err := fixture.queryClient.GroupMembers(fixture.ctx, &tc.req) if tc.expErrMsg != "" { @@ -242,6 +246,7 @@ func TestQueryGroupsByAdmin(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { resp, err := fixture.queryClient.GroupsByAdmin(fixture.ctx, &tc.req) if tc.expErrMsg != "" { @@ -282,6 +287,7 @@ func TestQueryGroupPoliciesByGroup(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { resp, err := fixture.keeper.GroupPoliciesByGroup(fixture.ctx, &tc.req) if tc.expErrMsg != "" { @@ -327,6 +333,7 @@ func TestQueryGroupPoliciesByAdmin(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { resp, err := fixture.keeper.GroupPoliciesByAdmin(fixture.ctx, &tc.req) if tc.expErrMsg != "" { diff --git a/x/group/keeper/keeper.go b/x/group/keeper/keeper.go index 4a79e7303348..45873f2342a0 100644 --- a/x/group/keeper/keeper.go +++ b/x/group/keeper/keeper.go @@ -373,6 +373,8 @@ func (k Keeper) PruneProposals(ctx sdk.Context) error { return nil } for _, proposal := range proposals { + proposal := proposal + err := k.pruneProposal(ctx, proposal.Id) if err != nil { return err diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go index a923a6845db7..3ed9a334a0f4 100644 --- a/x/mint/simulation/genesis_test.go +++ b/x/mint/simulation/genesis_test.go @@ -80,6 +80,8 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { + tt := tt + require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/nft/internal/conv/string.go b/x/nft/internal/conv/string.go index ab2b7f44b38a..96d89c3a5fff 100644 --- a/x/nft/internal/conv/string.go +++ b/x/nft/internal/conv/string.go @@ -1,20 +1,13 @@ package conv import ( - "reflect" "unsafe" ) // UnsafeStrToBytes uses unsafe to convert string into byte array. Returned bytes // must not be altered after this function is called as it will cause a segmentation fault. func UnsafeStrToBytes(s string) []byte { - var buf []byte - sHdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) - bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) - bufHdr.Data = sHdr.Data - bufHdr.Cap = sHdr.Len - bufHdr.Len = sHdr.Len - return buf + return unsafe.Slice(unsafe.StringData(s), len(s)) // ref https://github.com/golang/go/issues/53003#issuecomment-1140276077 } // UnsafeBytesToStr is meant to make a zero allocation conversion diff --git a/x/slashing/simulation/genesis_test.go b/x/slashing/simulation/genesis_test.go index 33d42e8e333c..fb03ff1bfa55 100644 --- a/x/slashing/simulation/genesis_test.go +++ b/x/slashing/simulation/genesis_test.go @@ -79,6 +79,8 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { + tt := tt + require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/staking/simulation/genesis_test.go b/x/staking/simulation/genesis_test.go index d3b74e5758fe..a681dbcd65e7 100644 --- a/x/staking/simulation/genesis_test.go +++ b/x/staking/simulation/genesis_test.go @@ -105,6 +105,8 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { + tt := tt + require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/upgrade/internal/conv/string.go b/x/upgrade/internal/conv/string.go index 8cd9e6827850..f78334057be0 100644 --- a/x/upgrade/internal/conv/string.go +++ b/x/upgrade/internal/conv/string.go @@ -1,18 +1,11 @@ package conv import ( - "reflect" "unsafe" ) // UnsafeStrToBytes uses unsafe to convert string into byte array. Returned bytes // must not be altered after this function is called as it will cause a segmentation fault. func UnsafeStrToBytes(s string) []byte { - var buf []byte - sHdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) - bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) - bufHdr.Data = sHdr.Data - bufHdr.Cap = sHdr.Len - bufHdr.Len = sHdr.Len - return buf + return unsafe.Slice(unsafe.StringData(s), len(s)) // ref https://github.com/golang/go/issues/53003#issuecomment-1140276077 } diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index bb2eab17bd20..aaec09092014 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -194,6 +194,8 @@ func (suite *UpgradeTestSuite) TestModuleVersions() { suite.Require().NoError(err) for _, tc := range testCases { + tc := tc + suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset