diff --git a/.golangci.yml b/.golangci.yml index b6dd494ab..8a62346b5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,12 +10,12 @@ linters: # - bodyclose # - containedctx # - contextcheck - # - decorder + - decorder # - dogsled - # - durationcheck - # - errcheck - # - errchkjson - # - errname + - durationcheck + - errcheck + - errchkjson + - errname # - errorlint # - exhaustive # - forbidigo @@ -23,39 +23,39 @@ linters: - 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 diff --git a/btcstaking/identifiable_staking_test.go b/btcstaking/identifiable_staking_test.go index c342e1b14..247915b97 100644 --- a/btcstaking/identifiable_staking_test.go +++ b/btcstaking/identifiable_staking_test.go @@ -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++ { diff --git a/crypto/eots/error.go b/crypto/eots/error.go index 831587a2c..703af436b 100644 --- a/crypto/eots/error.go +++ b/crypto/eots/error.go @@ -4,10 +4,10 @@ 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 @@ -15,6 +15,6 @@ type ErrorKind = ecdsa_schnorr.ErrorKind 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} } diff --git a/test/e2e/configurer/base.go b/test/e2e/configurer/base.go index 65e1d0488..0384e1aa2 100644 --- a/test/e2e/configurer/base.go +++ b/test/e2e/configurer/base.go @@ -1,6 +1,7 @@ package configurer import ( + "context" "encoding/json" "fmt" "io" @@ -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 } diff --git a/test/e2e/configurer/chain/queries.go b/test/e2e/configurer/chain/queries.go index 0a26c8129..37ba3fbe6 100644 --- a/test/e2e/configurer/chain/queries.go +++ b/test/e2e/configurer/chain/queries.go @@ -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 } diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 9c692768c..437232ceb 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -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 diff --git a/test/e2e/configurer/upgrade_test.go b/test/e2e/configurer/upgrade_test.go index fb992c761..2c5cc58c4 100644 --- a/test/e2e/configurer/upgrade_test.go +++ b/test/e2e/configurer/upgrade_test.go @@ -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)) diff --git a/test/e2e/initialization/chain/main.go b/test/e2e/initialization/chain/main.go index 9f251c9f9..4a330ed2c 100644 --- a/test/e2e/initialization/chain/main.go +++ b/test/e2e/initialization/chain/main.go @@ -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) diff --git a/testutil/datagen/btcstaking.go b/testutil/datagen/btcstaking.go index f76448a18..bd2eef8ff 100644 --- a/testutil/datagen/btcstaking.go +++ b/testutil/datagen/btcstaking.go @@ -154,7 +154,7 @@ func GenRandomBTCDelegation( BtcPk: delBTCPK, Pop: pop, FpBtcPkList: fpBTCPKs, - StakingTime: uint32(stakingTime), + StakingTime: stakingTime, StartHeight: startHeight, EndHeight: endHeight, TotalSat: totalSat, diff --git a/x/btccheckpoint/keeper/keeper.go b/x/btccheckpoint/keeper/keeper.go index b9219f4b5..0c9654480 100644 --- a/x/btccheckpoint/keeper/keeper.go +++ b/x/btccheckpoint/keeper/keeper.go @@ -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", ) ) @@ -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 } diff --git a/x/btclightclient/keeper/grpc_query_test.go b/x/btclightclient/keeper/grpc_query_test.go index 4e97f58c5..7252ba921 100644 --- a/x/btclightclient/keeper/grpc_query_test.go +++ b/x/btclightclient/keeper/grpc_query_test.go @@ -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)) } diff --git a/x/btclightclient/keeper/msg_server_test.go b/x/btclightclient/keeper/msg_server_test.go index 26eaac2aa..4f0b91365 100644 --- a/x/btclightclient/keeper/msg_server_test.go +++ b/x/btclightclient/keeper/msg_server_test.go @@ -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)} diff --git a/x/btclightclient/types/msgs_test.go b/x/btclightclient/types/msgs_test.go index 9a4766fd8..04a517366 100644 --- a/x/btclightclient/types/msgs_test.go +++ b/x/btclightclient/types/msgs_test.go @@ -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() @@ -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: diff --git a/x/btcstaking/keeper/msg_server_test.go b/x/btcstaking/keeper/msg_server_test.go index 1e53260f7..31373619d 100644 --- a/x/btcstaking/keeper/msg_server_test.go +++ b/x/btcstaking/keeper/msg_server_test.go @@ -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, diff --git a/x/btcstaking/types/btc_undelegation_test.go b/x/btcstaking/types/btc_undelegation_test.go index 7cfaecdba..005a554a1 100644 --- a/x/btcstaking/types/btc_undelegation_test.go +++ b/x/btcstaking/types/btc_undelegation_test.go @@ -75,7 +75,7 @@ func FuzzBTCUndelegation_SlashingTx(f *testing.F) { slashingPkScript, stakingTimeBlocks, 1000, - uint32(stakingTimeBlocks)+1000, + stakingTimeBlocks+1000, uint64(stakingValue), slashingRate, slashingChangeLockTime, diff --git a/x/btcstaking/types/pop.go b/x/btcstaking/types/pop.go index 97b014cf9..c20d919f4 100644 --- a/x/btcstaking/types/pop.go +++ b/x/btcstaking/types/pop.go @@ -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() diff --git a/x/btcstaking/types/validate_parsed_message_test.go b/x/btcstaking/types/validate_parsed_message_test.go index 7e6284621..44931aa4e 100644 --- a/x/btcstaking/types/validate_parsed_message_test.go +++ b/x/btcstaking/types/validate_parsed_message_test.go @@ -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, diff --git a/x/checkpointing/proposal.go b/x/checkpointing/proposal.go index de0662345..8685fbca1 100644 --- a/x/checkpointing/proposal.go +++ b/x/checkpointing/proposal.go @@ -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 } diff --git a/x/epoching/types/epoching.go b/x/epoching/types/epoching.go index 295fe7671..9b1b2ab0e 100644 --- a/x/epoching/types/epoching.go +++ b/x/epoching/types/epoching.go @@ -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 diff --git a/x/finality/keeper/genesis_test.go b/x/finality/keeper/genesis_test.go index df9286152..2db1a2f0f 100644 --- a/x/finality/keeper/genesis_test.go +++ b/x/finality/keeper/genesis_test.go @@ -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{ diff --git a/x/finality/keeper/tallying_bench_test.go b/x/finality/keeper/tallying_bench_test.go index 9e1d5f998..c621bc7cf 100644 --- a/x/finality/keeper/tallying_bench_test.go +++ b/x/finality/keeper/tallying_bench_test.go @@ -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{}