Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix lint action and fix lint errors #53

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/setup-go@v2.1.4
- 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/get-diff-action@v6.1.2
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}:x-oauth-basic@github.com/.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/get-diff-action@v6.1.2
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}:x-oauth-basic@github.com/.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 @@ -1136,7 +1136,9 @@
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)

Check warning on line 1140 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L1140

Added line #L1140 was not covered by tests
}
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 @@ -94,7 +94,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 @@ -105,7 +105,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 @@

// 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)

Check warning on line 26 in x/tokenfactory/keeper/before_send.go

View check run for this annotation

Codecov / codecov/patch

x/tokenfactory/keeper/before_send.go#L26

Added line #L26 was not covered by tests
}

_, 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) 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) {

Check warning on line 15 in x/tokenfactory/keeper/creators.go

View check run for this annotation

Codecov / codecov/patch

x/tokenfactory/keeper/creators.go#L15

Added line #L15 was not covered by tests
denoms = append(denoms, key.K2())
return false, nil
})
if err != nil {
panic(err)

Check warning on line 20 in x/tokenfactory/keeper/creators.go

View check run for this annotation

Codecov / codecov/patch

x/tokenfactory/keeper/creators.go#L19-L20

Added lines #L19 - L20 were not covered by tests
}
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 @@
// 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 @@
})
return false, nil
})
if err != nil {
panic(err)

Check warning on line 57 in x/tokenfactory/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/tokenfactory/keeper/genesis.go#L57

Added line #L57 was not covered by tests
}

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
Loading