chore: bump golangci-lint to v1.54.2 (#17538)

This commit is contained in:
Julien Robert 2023-08-25 16:07:24 +02:00 committed by GitHub
parent 03fb7da26d
commit 5839c3a600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 50 additions and 58 deletions

View File

@ -369,7 +369,7 @@ benchmark:
### Linting ###
###############################################################################
golangci_version=v1.53.3
golangci_version=v1.54.2
lint-install:
@echo "--> Installing golangci-lint $(golangci_version)"

View File

@ -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)

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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)
}
})
}

View File

@ -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()

View File

@ -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()

View File

@ -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 {

View File

@ -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)

View File

@ -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)
}
}

View File

@ -114,6 +114,8 @@ func (s *KeeperTestSuite) TestGRPCQueryConsensusParams() {
}
for _, tc := range testCases {
tc := tc
s.Run(tc.msg, func() {
s.SetupTest() // reset

View File

@ -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)
}
}

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -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 != "" {

View File

@ -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

View File

@ -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)
}
}

View File

@ -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

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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