Skip to content

Commit

Permalink
chore: fix linting script (cosmos#18233)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored Oct 24, 2023
1 parent 90723b7 commit 79b70be
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
id: lint_long
run: |
nix develop -c make lint
env:
NIX: 1
- uses: technote-space/[email protected]
if: steps.lint_long.outcome == 'skipped'
id: git_diff_all
Expand All @@ -49,3 +51,4 @@ jobs:
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
LINT_DIFF: 1
NIX: 1
7 changes: 5 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crypto/ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 18 additions & 4 deletions scripts/go-lint-all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
fi
35 changes: 18 additions & 17 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 3 additions & 2 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/auth/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/bank/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/client/grpc/cmtservice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}

Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/gov/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/group/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/mint/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/suite"

"cosmossdk.io/simapp"

"github.com/cosmos/cosmos-sdk/testutil/network"
)

Expand Down
19 changes: 12 additions & 7 deletions tests/e2e/server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/staking/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 79b70be

Please sign in to comment.