Skip to content

Commit

Permalink
enable more linters from golanci-lint (#333)
Browse files Browse the repository at this point in the history
- enables more linters from golang ci lint
- fixes some low hanging fruits
  • Loading branch information
KonradStaniec authored Dec 9, 2024
1 parent e819a3b commit b8a2d25
Show file tree
Hide file tree
Showing 21 changed files with 68 additions and 49 deletions.
46 changes: 23 additions & 23 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,52 @@ linters:
# - bodyclose
# - containedctx
# - contextcheck
# - decorder
- decorder
# - dogsled
# - durationcheck
# - errcheck
# - errchkjson
# - errname
- durationcheck
- errcheck
- errchkjson
- errname
# - errorlint
# - exhaustive
# - forbidigo
# - forcetypeassert
- goconst
# - gocritic
# - gocyclo
# - goheader
# - gomodguard
- goheader
- gomodguard
- goprintffuncname
- gosimple
- govet
# - grouper
# - importas
# - ineffassign
# - loggercheck
- grouper
- importas
- ineffassign
- loggercheck
# - maintidx
# - makezero
- misspell
# - nakedret
# - nilerr
- nakedret
- nilerr
# - nlreturn
# - noctx
# - nosprintfhostport
- noctx
- nosprintfhostport
# - paralleltest
# - reassign
- reassign
# - revive
# - rowserrcheck
# - sqlclosecheck
- rowserrcheck
- sqlclosecheck
- staticcheck
# - stylecheck
# - tenv
# - testableexamples
- tenv
- testableexamples
# - tparallel
- typecheck
# - unconvert
- unconvert
# - unparam
# - usestdlibvars
- usestdlibvars
- unused
# - wastedassign
- wastedassign
- whitespace
# - wrapcheck

Expand Down
2 changes: 1 addition & 1 deletion btcstaking/identifiable_staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func generateTxFromOutputs(r *rand.Rand, info *btcstaking.IdentifiableStakingInf
numOutputs := r.Int31n(18) + 2

stakingOutputIdx := int(r.Int31n(numOutputs))
opReturnOutputIdx := int(datagen.RandomIntOtherThan(r, int(stakingOutputIdx), int(numOutputs)))
opReturnOutputIdx := int(datagen.RandomIntOtherThan(r, stakingOutputIdx, int(numOutputs)))

tx := wire.NewMsgTx(2)
for i := 0; i < int(numOutputs); i++ {
Expand Down
6 changes: 3 additions & 3 deletions crypto/eots/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import (
ecdsa_schnorr "github.com/decred/dcrd/dcrec/secp256k1/v4/schnorr"
)

// ErrorKind identifies a kind of error. It has full support for errors.Is
// KindOfError identifies a kind of error. It has full support for errors.Is
// and errors.As, so the caller can directly check against an error kind
// when determining the reason for an error.
type ErrorKind = ecdsa_schnorr.ErrorKind
type KindOfError = ecdsa_schnorr.ErrorKind

// Error identifies an error related to a schnorr signature. It has full
// support for errors.Is and errors.As, so the caller can ascertain the
// specific reason for the error by checking the underlying error.
type Error = ecdsa_schnorr.Error

// signatureError creates an Error given a set of arguments.
func signatureError(kind ErrorKind, desc string) Error {
func signatureError(kind KindOfError, desc string) Error {
return Error{Err: kind, Description: desc}
}
13 changes: 12 additions & 1 deletion test/e2e/configurer/base.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package configurer

import (
"context"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -202,7 +203,17 @@ func (bc *baseConfigurer) runHermesIBCRelayer(chainConfigA *chain.Config, chainC
endpoint := fmt.Sprintf("http://%s/state", hermesResource.GetHostPort("3031/tcp"))

require.Eventually(bc.t, func() bool {
resp, err := http.Get(endpoint)
req, err := http.NewRequestWithContext(
context.Background(),
http.MethodGet,
endpoint,
nil,
)
if err != nil {
return false
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return false
}
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/configurer/chain/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ func (n *NodeConfig) QueryGRPCGateway(path string, queryParams url.Values) ([]by

var resp *http.Response
require.Eventually(n.t, func() bool {
req, err := http.NewRequest("GET", fullQueryPath, nil)
req, err := http.NewRequestWithContext(
context.Background(),
http.MethodGet,
fullQueryPath,
nil,
)
if err != nil {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/configurer/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func parseSubmitProposal(cdc codec.Codec, path string) (proposal, []sdk.Msg, sdk
}

// writeProposalToFile marshal the prop as json to the file.
func writeProposalToFile(cdc codec.Codec, path string, prop proposal) error {
func writeProposalToFile(_ codec.Codec, path string, prop proposal) error {
bz, err := json.MarshalIndent(&prop, "", " ")
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/configurer/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestWriteGovPropToFile(t *testing.T) {
require.NoError(t, err)

r := rand.New(rand.NewSource(time.Now().Unix()))
newPropHeight := int64(r.Int63())
newPropHeight := r.Int63()
msgProp.Plan.Height = newPropHeight

tempFilePath := filepath.Join(t.TempDir(), filepath.Base(config.UpgradeSignetLaunchFilePath))
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/initialization/chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ func main() {
panic(err)
}

b, _ := json.Marshal(createdChain)
b, err := json.Marshal(createdChain)
if err != nil {
panic(err)
}

fileName := fmt.Sprintf("%v/%v-encode", dataDir, chainId)
if err = os.WriteFile(fileName, b, 0o777); err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion testutil/datagen/btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func GenRandomBTCDelegation(
BtcPk: delBTCPK,
Pop: pop,
FpBtcPkList: fpBTCPKs,
StakingTime: uint32(stakingTime),
StakingTime: stakingTime,
StartHeight: startHeight,
EndHeight: endHeight,
TotalSat: totalSat,
Expand Down
4 changes: 2 additions & 2 deletions x/btccheckpoint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (e submissionBtcError) Error() string {
}

const (
submissionUnknownErr submissionBtcError = submissionBtcError(
errSubmissionUnknown submissionBtcError = submissionBtcError(
"One of submission blocks is not known to btclightclient",
)
)
Expand Down Expand Up @@ -111,7 +111,7 @@ func (k Keeper) headerDepth(ctx context.Context, headerHash *bbn.BTCHeaderHashBy

if err != nil {
// one of blocks is not known to light client
return 0, submissionUnknownErr
return 0, errSubmissionUnknown
}
return blockDepth, nil
}
Expand Down
4 changes: 2 additions & 2 deletions x/btclightclient/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ func FuzzHashesQuery(f *testing.F) {
t.Fatalf("Valid request led to a nil response")
}
// If we are on the last page the elements retrieved should be equal to the remaining ones
if headersRetrieved+uint32(limit) >= chainSize && uint32(len(resp.Hashes)) != chainSize-headersRetrieved {
if headersRetrieved+limit >= chainSize && uint32(len(resp.Hashes)) != chainSize-headersRetrieved {
t.Fatalf("On the last page expected %d elements but got %d", chainSize-headersRetrieved, len(resp.Hashes))
}
// Otherwise, the elements retrieved should be equal to the limit
if headersRetrieved+uint32(limit) < chainSize && uint32(len(resp.Hashes)) != limit {
if headersRetrieved+limit < chainSize && uint32(len(resp.Hashes)) != limit {
t.Fatalf("On an intermediate page expected %d elements but got %d", limit, len(resp.Hashes))
}

Expand Down
2 changes: 1 addition & 1 deletion x/btclightclient/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func FuzzMsgServerReorgChain(f *testing.F) {
r,
forkHeader.Header.ToBlockHeader(),
nil,
uint32(forkChainLen),
forkChainLen,
)
chainExtensionWork := chainWork(chainExtension)
msg := &types.MsgInsertHeaders{Signer: address.String(), Headers: keepertest.NewBTCHeaderBytesList(chainExtension)}
Expand Down
4 changes: 1 addition & 3 deletions x/btclightclient/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ func FuzzMsgInsertHeader(f *testing.F) {

f.Fuzz(func(t *testing.T, seed int64) {
r := rand.New(rand.NewSource(seed))
errorKind := 0

addressBytes := datagen.GenRandomByteArray(r, 1+uint64(r.Intn(255)))
headerBytes := datagen.GenRandomBTCHeaderInfo(r).Header
headerHex := headerBytes.MarshalHex()
Expand All @@ -33,7 +31,7 @@ func FuzzMsgInsertHeader(f *testing.F) {
require.NoError(t, err)

// Perform modifications on the header
errorKind = r.Intn(2)
errorKind := r.Intn(2)
var bitsBig sdkmath.Uint
switch errorKind {
case 0:
Expand Down
4 changes: 2 additions & 2 deletions x/btcstaking/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,14 +976,14 @@ func TestDoNotAllowDelegationWithoutFinalityProvider(t *testing.T) {
FpBtcPkList: []bbn.BIP340PubKey{*fp.BtcPk},
BtcPk: bbn.NewBIP340PubKeyFromBTCPK(delSK.PubKey()),
Pop: pop,
StakingTime: uint32(stakingTimeBlocks),
StakingTime: stakingTimeBlocks,
StakingValue: stakingValue,
StakingTx: serializedStakingTx,
StakingTxInclusionProof: txInclusionProof,
SlashingTx: testStakingInfo.SlashingTx,
DelegatorSlashingSig: delegatorSig,
UnbondingTx: unbondingTx,
UnbondingTime: uint32(unbondingTime),
UnbondingTime: unbondingTime,
UnbondingValue: unbondingValue,
UnbondingSlashingTx: testUnbondingInfo.SlashingTx,
DelegatorUnbondingSlashingSig: delUnbondingSlashingSig,
Expand Down
2 changes: 1 addition & 1 deletion x/btcstaking/types/btc_undelegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func FuzzBTCUndelegation_SlashingTx(f *testing.F) {
slashingPkScript,
stakingTimeBlocks,
1000,
uint32(stakingTimeBlocks)+1000,
stakingTimeBlocks+1000,
uint64(stakingValue),
slashingRate,
slashingChangeLockTime,
Expand Down
2 changes: 1 addition & 1 deletion x/btcstaking/types/pop.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func VerifyBIP322(sigType BTCSigType, btcSigRaw []byte, bip340PK *bbn.BIP340PubK
// unmarshal pop.BtcSig to bip322Sig
var bip322Sig BIP322Sig
if err := bip322Sig.Unmarshal(btcSigRaw); err != nil {
return nil
return err
}

btcKeyBytes, err := bip340PK.Marshal()
Expand Down
2 changes: 1 addition & 1 deletion x/btcstaking/types/validate_parsed_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func createMsgDelegationForParams(
SlashingTx: testStakingInfo.SlashingTx,
DelegatorSlashingSig: delegatorSig,
UnbondingTx: unbondingInfo.serializedUnbondingTx,
UnbondingTime: uint32(unbondingTime),
UnbondingTime: unbondingTime,
UnbondingValue: unbondingValue,
UnbondingSlashingTx: unbondingInfo.unbondingSlashingTx,
DelegatorUnbondingSlashingSig: unbondingInfo.unbondingSlashinSig,
Expand Down
1 change: 1 addition & 0 deletions x/checkpointing/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func (h *ProposalHandler) ProcessProposal() sdk.ProcessProposalHandler {
err = baseapp.ValidateVoteExtensions(ctx, h.ckptKeeper, req.Height, ctx.ChainID(), *injectedCkpt.ExtendedCommitInfo)
if err != nil {
// the returned err will lead to panic as something very wrong happened during consensus
h.logger.Error("invalid vote extensions by ValidateVoteExtensions: %w", err)
return resReject, nil
}

Expand Down
2 changes: 1 addition & 1 deletion x/epoching/types/epoching.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (e Epoch) IsFirstBlockOfNextEpoch(ctx context.Context) bool {

// WithinBoundary checks whether the given height is within this epoch or not
func (e Epoch) WithinBoundary(height uint64) bool {
if height < e.FirstBlockHeight || height > uint64(e.GetLastBlockHeight()) {
if height < e.FirstBlockHeight || height > e.GetLastBlockHeight() {
return false
} else {
return true
Expand Down
2 changes: 1 addition & 1 deletion x/finality/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func FuzzTestExportGenesis(f *testing.F) {
fps := datagen.CreateNFinalityProviders(r, t, int(numFps))
vpFps := make(map[string]*types.VotingPowerFP, 0)
for _, fp := range fps {
vp := uint64(datagen.RandomInt(r, 1000000))
vp := datagen.RandomInt(r, 1000000)
// sets voting power
k.SetVotingPower(ctx, *fp.BtcPk, blkHeight, vp)
vpFps[fp.BtcPk.MarshalHex()] = &types.VotingPowerFP{
Expand Down
2 changes: 1 addition & 1 deletion x/finality/keeper/tallying_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func benchmarkTallyBlocks(b *testing.B, numFPs int) {
// activate BTC staking protocol at a random height
activatedHeight := uint64(1)
// add mock queries to GetBTCStakingActivatedHeight
ctx = datagen.WithCtxHeight(ctx, uint64(activatedHeight))
ctx = datagen.WithCtxHeight(ctx, activatedHeight)

// simulate fp set
fpSet := map[string]uint64{}
Expand Down

0 comments on commit b8a2d25

Please sign in to comment.