From 79b70bed516a456a0758f2983da6408176b8ac4e Mon Sep 17 00:00:00 2001 From: Marko Date: Tue, 24 Oct 2023 16:01:06 +0200 Subject: [PATCH] chore: fix linting script (#18233) --- .github/workflows/lint.yml | 3 ++ .golangci.yml | 7 ++-- crypto/ledger/ledger_test.go | 1 + scripts/go-lint-all.bash | 22 +++++++++--- simapp/app.go | 35 ++++++++++--------- simapp/simd/cmd/root.go | 5 +-- tests/e2e/auth/cli_test.go | 4 ++- tests/e2e/bank/cli_test.go | 5 +-- .../client/grpc/cmtservice/service_test.go | 5 ++- tests/e2e/gov/cli_test.go | 8 ++--- tests/e2e/group/cli_test.go | 5 +-- tests/e2e/mint/cli_test.go | 1 + tests/e2e/server/export_test.go | 19 ++++++---- tests/e2e/staking/cli_test.go | 4 ++- 14 files changed, 79 insertions(+), 45 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 745f5588a18a..46696c312aac 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -32,6 +32,8 @@ jobs: id: lint_long run: | nix develop -c make lint + env: + NIX: 1 - uses: technote-space/get-diff-action@v6.1.2 if: steps.lint_long.outcome == 'skipped' id: git_diff_all @@ -49,3 +51,4 @@ jobs: env: GIT_DIFF: ${{ env.GIT_DIFF }} LINT_DIFF: 1 + NIX: 1 diff --git a/.golangci.yml b/.golangci.yml index 12db4460bedd..11259002d8d1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,14 +6,17 @@ run: exclude-dir: testutil/testdata skip-files: - server/grpc/gogoreflection/fix_registration.go - - tests/e2e/client/grpc/cmtservice/service_test.go - "fix_registration.go" - ".*\\.pb\\.go$" - ".*\\.pb\\.gw\\.go$" - ".*\\.pulsar\\.go$" + - crypto/keys/secp256k1/internal/* build-tags: - - rocksdb + - e2e + - ledger + - test_ledger_mock + linters: disable-all: true diff --git a/crypto/ledger/ledger_test.go b/crypto/ledger/ledger_test.go index 6371ea13ce4f..368c86ac419e 100644 --- a/crypto/ledger/ledger_test.go +++ b/crypto/ledger/ledger_test.go @@ -32,6 +32,7 @@ func TestPublicKeyUnsafe(t *testing.T) { } func checkDefaultPubKey(t *testing.T, priv types.LedgerPrivKey) { + t.Helper() require.NotNil(t, priv) expectedPkStr := "PubKeySecp256k1{034FEF9CD7C4C63588D3B03FEB5281B9D232CBA34D6F3D71AEE59211FFBFE1FE87}" require.Equal(t, "eb5ae98721034fef9cd7c4c63588d3b03feb5281b9d232cba34d6f3d71aee59211ffbfe1fe87", diff --git a/scripts/go-lint-all.bash b/scripts/go-lint-all.bash index 8850c65cd111..3860c0dd3e17 100755 --- a/scripts/go-lint-all.bash +++ b/scripts/go-lint-all.bash @@ -9,8 +9,15 @@ lint_module() { local root="$1" shift cd "$(dirname "$root")" && - echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" && - golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" + echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" && + if [[ -z "${NIX:-}" ]]; then + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=e2e,ledger,test_ledger_mock + else + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=rocksdb,e2e,ledger,test_ledger_mock + fi + if [[ "$(grep "^module" go.mod)" == "module cosmossdk.io/simapp" ]]; then + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=app_v1 + fi } export -f lint_module @@ -31,7 +38,14 @@ else for f in $(dirname $(echo "$GIT_DIFF" | tr -d "'") | uniq); do echo "linting $f [$(date -Iseconds -u)]" && cd $f && - golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" && + if [[ -z "${NIX:-}" ]]; then + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=e2e,ledger,test_ledger_mock + else + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=rocksdb,e2e,ledger,test_ledger_mock + fi + if [[ $f == simapp || $f == simapp/simd/cmd ]]; then + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=app_v1 + fi cd $REPO_ROOT done -fi \ No newline at end of file +fi diff --git a/simapp/app.go b/simapp/app.go index e13f0456b553..b12f88e22ea9 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -9,6 +9,11 @@ import ( "os" "path/filepath" + abci "github.com/cometbft/cometbft/abci/types" + dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/gogoproto/proto" + "github.com/spf13/cast" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/client/v2/autocli" @@ -24,6 +29,11 @@ import ( "cosmossdk.io/x/feegrant" feegrantkeeper "cosmossdk.io/x/feegrant/keeper" feegrantmodule "cosmossdk.io/x/feegrant/module" + "cosmossdk.io/x/gov" + govclient "cosmossdk.io/x/gov/client" + govkeeper "cosmossdk.io/x/gov/keeper" + govtypes "cosmossdk.io/x/gov/types" + govv1beta1 "cosmossdk.io/x/gov/types/v1beta1" "cosmossdk.io/x/group" groupkeeper "cosmossdk.io/x/group/keeper" groupmodule "cosmossdk.io/x/group/module" @@ -37,16 +47,7 @@ import ( "cosmossdk.io/x/upgrade" upgradekeeper "cosmossdk.io/x/upgrade/keeper" upgradetypes "cosmossdk.io/x/upgrade/types" - abci "github.com/cometbft/cometbft/abci/types" - dbm "github.com/cosmos/cosmos-db" - "github.com/cosmos/gogoproto/proto" - "github.com/spf13/cast" - "cosmossdk.io/x/gov" - govclient "cosmossdk.io/x/gov/client" - govkeeper "cosmossdk.io/x/gov/keeper" - govtypes "cosmossdk.io/x/gov/types" - govv1beta1 "cosmossdk.io/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -74,7 +75,6 @@ import ( authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" - "github.com/cosmos/cosmos-sdk/x/auth/tx" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -143,8 +143,7 @@ type SimApp struct { interfaceRegistry types.InterfaceRegistry // keys to access the substores - keys map[string]*storetypes.KVStoreKey - tkeys map[string]*storetypes.TransientStoreKey + keys map[string]*storetypes.KVStoreKey // keepers AccountKeeper authkeeper.AccountKeeper @@ -207,7 +206,7 @@ func NewSimApp( }) appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() - txConfig := tx.NewTxConfig(appCodec, tx.DefaultSignModes) + txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes) std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) @@ -290,12 +289,12 @@ func NewSimApp( ) // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) - enabledSignModes := append(tx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) - txConfigOpts := tx.ConfigOptions{ + enabledSignModes := append(authtx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := authtx.ConfigOptions{ EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), } - txConfig, err := tx.NewTxConfigWithOptions( + txConfig, err := authtx.NewTxConfigWithOptions( appCodec, txConfigOpts, ) @@ -613,7 +612,9 @@ func (app *SimApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*ab if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil { panic(err) } - app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()); err != nil { + panic(err) + } return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState) } diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 7ff428e91ad9..c1a2654579da 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -5,11 +5,12 @@ package cmd import ( "os" + dbm "github.com/cosmos/cosmos-db" + "github.com/spf13/cobra" + "cosmossdk.io/log" "cosmossdk.io/simapp" "cosmossdk.io/simapp/params" - dbm "github.com/cosmos/cosmos-db" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" diff --git a/tests/e2e/auth/cli_test.go b/tests/e2e/auth/cli_test.go index 45688f5f9121..a029338e3d57 100644 --- a/tests/e2e/auth/cli_test.go +++ b/tests/e2e/auth/cli_test.go @@ -6,9 +6,11 @@ package auth import ( "testing" + "github.com/stretchr/testify/suite" + "cosmossdk.io/simapp" + "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/stretchr/testify/suite" ) func TestE2ETestSuite(t *testing.T) { diff --git a/tests/e2e/bank/cli_test.go b/tests/e2e/bank/cli_test.go index 8ff0878935c2..4560aea6bf62 100644 --- a/tests/e2e/bank/cli_test.go +++ b/tests/e2e/bank/cli_test.go @@ -6,10 +6,11 @@ package client import ( "testing" + "github.com/stretchr/testify/suite" + "cosmossdk.io/simapp" - "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/testutil/network" ) func TestE2ETestSuite(t *testing.T) { diff --git a/tests/e2e/client/grpc/cmtservice/service_test.go b/tests/e2e/client/grpc/cmtservice/service_test.go index 2a802c503049..6fa138a09950 100644 --- a/tests/e2e/client/grpc/cmtservice/service_test.go +++ b/tests/e2e/client/grpc/cmtservice/service_test.go @@ -8,16 +8,16 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/suite" + "cosmossdk.io/simapp" _ "cosmossdk.io/x/gov" - "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/cosmos/cosmos-sdk/types" qtypes "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/version" _ "github.com/cosmos/cosmos-sdk/x/distribution" @@ -92,7 +92,6 @@ func (s *E2ETestSuite) TestQueryLatestBlock() { s.Require().NoError(err) var blockInfoRes cmtservice.GetLatestBlockResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &blockInfoRes)) - s.Require().Equal(types.ConsAddress(blockInfoRes.Block.Header.ProposerAddress).String(), blockInfoRes.SdkBlock.Header.ProposerAddress) s.Require().Contains(blockInfoRes.SdkBlock.Header.ProposerAddress, "cosmosvalcons") } diff --git a/tests/e2e/gov/cli_test.go b/tests/e2e/gov/cli_test.go index 611704395936..be8e7afc82e3 100644 --- a/tests/e2e/gov/cli_test.go +++ b/tests/e2e/gov/cli_test.go @@ -7,13 +7,13 @@ import ( "testing" "time" - "cosmossdk.io/simapp" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + "cosmossdk.io/simapp" v1 "cosmossdk.io/x/gov/types/v1" - "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/testutil/network" ) func TestE2ETestSuite(t *testing.T) { diff --git a/tests/e2e/group/cli_test.go b/tests/e2e/group/cli_test.go index 438686bc38aa..7c6e86088623 100644 --- a/tests/e2e/group/cli_test.go +++ b/tests/e2e/group/cli_test.go @@ -6,10 +6,11 @@ package group import ( "testing" + "github.com/stretchr/testify/suite" + "cosmossdk.io/simapp" - "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/testutil/network" ) func TestE2ETestSuite(t *testing.T) { diff --git a/tests/e2e/mint/cli_test.go b/tests/e2e/mint/cli_test.go index 35dc54d4e3a2..08158c279684 100644 --- a/tests/e2e/mint/cli_test.go +++ b/tests/e2e/mint/cli_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/suite" "cosmossdk.io/simapp" + "github.com/cosmos/cosmos-sdk/testutil/network" ) diff --git a/tests/e2e/server/export_test.go b/tests/e2e/server/export_test.go index 9c8922227d4c..60dfe04164bc 100644 --- a/tests/e2e/server/export_test.go +++ b/tests/e2e/server/export_test.go @@ -20,6 +20,7 @@ import ( "cosmossdk.io/log" "cosmossdk.io/simapp" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -95,10 +96,12 @@ func TestExportCmd_Height(t *testing.T) { // Fast forward to block `tc.fastForward`. for i := int64(2); i <= tc.fastForward; i++ { - app.FinalizeBlock(&abci.RequestFinalizeBlock{ + _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ Height: i, }) - app.Commit() + assert.NilError(t, err) + _, err = app.Commit() + assert.NilError(t, err) } output := &bytes.Buffer{} @@ -180,16 +183,18 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, ge err = genutil.ExportGenesisFile(&appGenesis, serverCtx.Config.GenesisFile()) assert.NilError(t, err) - app.InitChain(&abci.RequestInitChain{ + _, err = app.InitChain(&abci.RequestInitChain{ Validators: []abci.ValidatorUpdate{}, ConsensusParams: simtestutil.DefaultConsensusParams, AppStateBytes: appGenesis.AppState, - }, - ) - app.FinalizeBlock(&abci.RequestFinalizeBlock{ + }) + assert.NilError(t, err) + _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ Height: 1, }) - app.Commit() + assert.NilError(t, err) + _, err = app.Commit() + assert.NilError(t, err) cmd := server.ExportCmd(func(_ log.Logger, _ dbm.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, appOptions types.AppOptions, modulesToExport []string) (types.ExportedApp, error) { var simApp *simapp.SimApp diff --git a/tests/e2e/staking/cli_test.go b/tests/e2e/staking/cli_test.go index 6f74d310fbec..0705c5645e63 100644 --- a/tests/e2e/staking/cli_test.go +++ b/tests/e2e/staking/cli_test.go @@ -6,9 +6,11 @@ package testutil import ( "testing" + "github.com/stretchr/testify/suite" + "cosmossdk.io/simapp" + "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/stretchr/testify/suite" ) func TestE2ETestSuite(t *testing.T) {