Skip to content

Commit

Permalink
fix lint action and fix lint errors (#53)
Browse files Browse the repository at this point in the history
* fix lint action and fix lint errors

* chore
  • Loading branch information
Vritra4 authored Jul 17, 2024
1 parent e4a132c commit 3af55a1
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 40 deletions.
42 changes: 29 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
WASM_DIR: ./wasmchain
MOVE_DIR: ./movechain

jobs:
golangci:
env:
# for private repo access
GOPRIVATE: github.com/initia-labs/*
GOPRIVATE: github.com/initia-labs,github.com/skip-mev/slinky
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
GOLANGCI_LINT_VERSION: v1.59.1
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22
- uses: technote-space/get-diff-action@v5
check-latest: true
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
Expand All @@ -45,26 +44,43 @@ jobs:
go.sum
# for private repo access
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
- name: run go linters
# install golangci-lint
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
- name: run go linters (long)
if: env.GIT_DIFF
id: lint_long
run: |
make tools
make lint
if: env.GIT_DIFF
- uses: technote-space/[email protected]
if: steps.lint_long.outcome == 'skipped'
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: run go linters (short)
if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF
run: |
make lint
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
LINT_DIFF: 1
# Use --check or --exit-code when available (Go 1.19?)
# https://github.com/golang/go/issues/27005
tidy:
env:
# for private repo access
GOPRIVATE: github.com/initia-labs/*
GOPRIVATE: github.com/initia-labs,github.com/skip-mev/slinky
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
runs-on: ubuntu-latest
name: tidy
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.22
check-latest: true
# for private repo access
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
- run: |
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ benchmark:
###############################################################################

lint:
golangci-lint run --out-format=tab
golangci-lint run --out-format=tab --timeout=15m

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0
golangci-lint run --fix --out-format=tab --timeout=15m

.PHONY: lint lint-fix

format:
Expand Down
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,9 @@ func (app *MinitiaApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain)
if err := tmjson.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
4 changes: 2 additions & 2 deletions app/ibc-hooks/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand Down Expand Up @@ -277,7 +277,7 @@ func _createTestInput(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
ac,
)
ibcHooksKeeper.Params.Set(ctx, ibchookstypes.DefaultParams())
ibcHooksKeeper.Params.Set(ctx, ibchookstypes.DefaultParams()) //nolint:errcheck

wasmKeeper := wasmkeeper.NewKeeper(
appCodec,
Expand Down
4 changes: 2 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func SetupWithGenesisAccounts(
// allow empty validator
if valSet == nil || len(valSet.Validators) == 0 {
privVal := ed25519.GenPrivKey()
pubKey, err := cryptocodec.ToTmPubKeyInterface(privVal.PubKey())
pubKey, err := cryptocodec.ToTmPubKeyInterface(privVal.PubKey()) //nolint:staticcheck
if err != nil {
panic(err)
}
Expand All @@ -106,7 +106,7 @@ func SetupWithGenesisAccounts(

validators := make([]opchildtypes.Validator, 0, len(valSet.Validators))
for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey) //nolint:staticcheck
if err != nil {
panic(err)
}
Expand Down
6 changes: 0 additions & 6 deletions x/tokenfactory/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,6 @@ func NewSetBeforeSendHookCmd(ac address.Codec) *cobra.Command {
return err
}

txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags())
if err != nil {
return err
}
txf = txf.WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)

msg := types.NewMsgSetBeforeSendHook(
fromAddr,
args[0],
Expand Down
7 changes: 2 additions & 5 deletions x/tokenfactory/keeper/before_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ func (k Keeper) setBeforeSendHook(ctx context.Context, denom string, cosmwasmAdd

// delete the store for denom prefix store when cosmwasm address is nil
if cosmwasmAddress == "" {
k.DenomHookAddr.Remove(ctx, denom)
return nil
return k.DenomHookAddr.Remove(ctx, denom)
}

_, err = k.ac.StringToBytes(cosmwasmAddress)
if err != nil {
return err
}

k.DenomHookAddr.Set(ctx, denom, cosmwasmAddress)

return nil
return k.DenomHookAddr.Set(ctx, denom, cosmwasmAddress)
}

func (k Keeper) GetBeforeSendHook(ctx context.Context, denom string) string {
Expand Down
3 changes: 2 additions & 1 deletion x/tokenfactory/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var ModuleBasics = module.NewBasicManager(
)

var (
valPubKeys = testutilsims.CreateTestPubKeys(5)
valPubKeys = testutilsims.CreateTestPubKeys(5) //nolint:unused

pubKeys = []crypto.PubKey{
secp256k1.GenPrivKey().PubKey(),
Expand All @@ -86,6 +86,7 @@ var (
sdk.AccAddress(pubKeys[4].Address()),
}

//nolint:unused
valAddrs = []sdk.ValAddress{
sdk.ValAddress(pubKeys[0].Address()),
sdk.ValAddress(pubKeys[1].Address()),
Expand Down
3 changes: 1 addition & 2 deletions x/tokenfactory/keeper/createdenom.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func (k Keeper) createDenomAfterValidation(ctx context.Context, creatorAddr stri
return err
}

k.addDenomFromCreator(ctx, creatorAddr, denom)
return nil
return k.addDenomFromCreator(ctx, creatorAddr, denom)
}

func (k Keeper) validateCreateDenom(ctx context.Context, creatorAddr string, subdenom string) (newTokenDenom string, err error) {
Expand Down
4 changes: 2 additions & 2 deletions x/tokenfactory/keeper/createdenom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestCreateDenom(t *testing.T) {
// Set denom creation fee in params
input.Faucet.Fund(ctx, addrs[0], defaultDenomCreationFee.DenomCreationFee...)

tokenFactoryKeeper.SetParams(ctx, tc.denomCreationFee)
tokenFactoryKeeper.SetParams(ctx, tc.denomCreationFee) //nolint:errcheck
denomCreationFee := tokenFactoryKeeper.GetParams(ctx).DenomCreationFee
require.Equal(t, tc.denomCreationFee.DenomCreationFee, denomCreationFee)

Expand Down Expand Up @@ -181,7 +181,7 @@ func TestGasConsume(t *testing.T) {
// set params with the gas consume amount

tokenFactoryKeeper := input.TokenFactoryKeeper
tokenFactoryKeeper.SetParams(ctx, types.NewParams(nil, tc.gasConsume))
tokenFactoryKeeper.SetParams(ctx, types.NewParams(nil, tc.gasConsume)) //nolint:errcheck

// amount of gas consumed prior to the denom creation
gasConsumedBefore := ctx.GasMeter().GasConsumed()
Expand Down
5 changes: 4 additions & 1 deletion x/tokenfactory/keeper/creators.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ func (k Keeper) addDenomFromCreator(ctx context.Context, creator, denom string)

func (k Keeper) getDenomsFromCreator(ctx context.Context, creator string) []string {
denoms := []string{}
k.CreatorDenoms.Walk(ctx, collections.NewPrefixedPairRange[string, string](creator), func(key collections.Pair[string, string]) (stop bool, err error) {
err := k.CreatorDenoms.Walk(ctx, collections.NewPrefixedPairRange[string, string](creator), func(key collections.Pair[string, string]) (stop bool, err error) {
denoms = append(denoms, key.K2())
return false, nil
})
if err != nil {
panic(err)
}
return denoms
}
5 changes: 4 additions & 1 deletion x/tokenfactory/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
// ExportGenesis returns the tokenfactory module's exported genesis.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
genDenoms := []types.GenesisDenom{}
k.CreatorDenoms.Walk(ctx, nil, func(key collections.Pair[string, string]) (stop bool, err error) {
err := k.CreatorDenoms.Walk(ctx, nil, func(key collections.Pair[string, string]) (stop bool, err error) {
denom := key.K2()

authorityMetadata, err := k.GetAuthorityMetadata(ctx, denom)
Expand All @@ -53,6 +53,9 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
})
return false, nil
})
if err != nil {
panic(err)
}

return &types.GenesisState{
FactoryDenoms: genDenoms,
Expand Down
4 changes: 2 additions & 2 deletions x/tokenfactory/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestGenesis(t *testing.T) {
tokenfactoryModuleAccount := accountKeeper.GetAccount(ctx, accountKeeper.GetModuleAddress(types.ModuleName))
require.Nil(t, tokenfactoryModuleAccount)

tokenFactoryKeeper.SetParams(ctx, types.Params{DenomCreationFee: sdk.Coins{sdk.NewInt64Coin("uinit", 100)}})
tokenFactoryKeeper.SetParams(ctx, types.Params{DenomCreationFee: sdk.Coins{sdk.NewInt64Coin("uinit", 100)}}) //nolint:errcheck
tokenFactoryKeeper.InitGenesis(ctx, genesisState)

// check that the module account is now initialized
Expand All @@ -80,7 +80,7 @@ func TestGenesis(t *testing.T) {
require.Equal(t, genesisState, *exportedGenesis)

// verify that the exported bank genesis is valid
bankKeeper.SetParams(ctx, banktypes.DefaultParams())
bankKeeper.SetParams(ctx, banktypes.DefaultParams()) //nolint:errcheck
exportedBankGenesis := bankKeeper.ExportGenesis(ctx)
require.NoError(t, exportedBankGenesis.Validate())

Expand Down

0 comments on commit 3af55a1

Please sign in to comment.