Skip to content

Commit

Permalink
Merge pull request #1240 from CosmWasm/fix_linters
Browse files Browse the repository at this point in the history
Fix linters
  • Loading branch information
alpe authored Mar 7, 2023
2 parents 651ca9c + ccf3a88 commit 52d6b1f
Show file tree
Hide file tree
Showing 34 changed files with 408 additions and 389 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
Expand All @@ -23,12 +22,10 @@ linters:
- prealloc
- exportloopref
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- varcheck

issues:
exclude-rules:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ format-tools:

lint: format-tools
golangci-lint run --tests=false
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d

format: format-tools
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/CosmWasm/wasmd

Expand Down
11 changes: 6 additions & 5 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
errorsmod "cosmossdk.io/errors"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -24,19 +25,19 @@ type HandlerOptions struct {

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}
if options.WasmConfig == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder")
}
if options.TXCounterStoreKey == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
}

anteDecorators := []sdk.AnteDecorator{
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package cli
import (
"strconv"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/spf13/cobra"

"github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -44,7 +44,7 @@ func parseMigrateContractArgs(args []string, cliCtx client.Context) (types.MsgMi
// get the id of the code to instantiate
codeID, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return types.MsgMigrateContract{}, sdkerrors.Wrap(err, "code id")
return types.MsgMigrateContract{}, errorsmod.Wrap(err, "code id")
}

migrateMsg := args[2]
Expand Down
46 changes: 23 additions & 23 deletions x/wasm/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package wasm
import (
"math"

errorsmod "cosmossdk.io/errors"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
Expand Down Expand Up @@ -50,7 +50,7 @@ func (i IBCHandler) OnChanOpenInit(
}
contractAddr, err := ContractFromPortID(portID)
if err != nil {
return "", sdkerrors.Wrapf(err, "contract port id")
return "", errorsmod.Wrapf(err, "contract port id")
}

msg := wasmvmtypes.IBCChannelOpenMsg{
Expand All @@ -77,7 +77,7 @@ func (i IBCHandler) OnChanOpenInit(

// Claim channel capability passed back by IBC module
if err := i.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
return "", sdkerrors.Wrap(err, "claim capability")
return "", errorsmod.Wrap(err, "claim capability")
}
return acceptedVersion, nil
}
Expand All @@ -99,7 +99,7 @@ func (i IBCHandler) OnChanOpenTry(

contractAddr, err := ContractFromPortID(portID)
if err != nil {
return "", sdkerrors.Wrapf(err, "contract port id")
return "", errorsmod.Wrapf(err, "contract port id")
}

msg := wasmvmtypes.IBCChannelOpenMsg{
Expand Down Expand Up @@ -131,7 +131,7 @@ func (i IBCHandler) OnChanOpenTry(
if !i.keeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) {
// Only claim channel capability passed back by IBC module if we do not already own it
if err := i.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
return "", sdkerrors.Wrap(err, "claim capability")
return "", errorsmod.Wrap(err, "claim capability")
}
}

Expand All @@ -147,17 +147,17 @@ func (i IBCHandler) OnChanOpenAck(
) error {
contractAddr, err := ContractFromPortID(portID)
if err != nil {
return sdkerrors.Wrapf(err, "contract port id")
return errorsmod.Wrapf(err, "contract port id")
}
channelInfo, ok := i.channelKeeper.GetChannel(ctx, portID, channelID)
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
channelInfo.Counterparty.ChannelId = counterpartyChannelID

appVersion, ok := i.appVersionGetter.GetAppVersion(ctx, portID, channelID)
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID)
return errorsmod.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID)
}

msg := wasmvmtypes.IBCChannelConnectMsg{
Expand All @@ -173,15 +173,15 @@ func (i IBCHandler) OnChanOpenAck(
func (i IBCHandler) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error {
contractAddr, err := ContractFromPortID(portID)
if err != nil {
return sdkerrors.Wrapf(err, "contract port id")
return errorsmod.Wrapf(err, "contract port id")
}
channelInfo, ok := i.channelKeeper.GetChannel(ctx, portID, channelID)
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
appVersion, ok := i.appVersionGetter.GetAppVersion(ctx, portID, channelID)
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID)
return errorsmod.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID)
}
msg := wasmvmtypes.IBCChannelConnectMsg{
OpenConfirm: &wasmvmtypes.IBCOpenConfirm{
Expand All @@ -195,15 +195,15 @@ func (i IBCHandler) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string)
func (i IBCHandler) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error {
contractAddr, err := ContractFromPortID(portID)
if err != nil {
return sdkerrors.Wrapf(err, "contract port id")
return errorsmod.Wrapf(err, "contract port id")
}
channelInfo, ok := i.channelKeeper.GetChannel(ctx, portID, channelID)
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
appVersion, ok := i.appVersionGetter.GetAppVersion(ctx, portID, channelID)
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID)
return errorsmod.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID)
}

msg := wasmvmtypes.IBCChannelCloseMsg{
Expand All @@ -223,15 +223,15 @@ func (i IBCHandler) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string
// counterparty has closed the channel
contractAddr, err := ContractFromPortID(portID)
if err != nil {
return sdkerrors.Wrapf(err, "contract port id")
return errorsmod.Wrapf(err, "contract port id")
}
channelInfo, ok := i.channelKeeper.GetChannel(ctx, portID, channelID)
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
appVersion, ok := i.appVersionGetter.GetAppVersion(ctx, portID, channelID)
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID)
return errorsmod.Wrapf(channeltypes.ErrInvalidChannelVersion, "port ID (%s) channel ID (%s)", portID, channelID)
}

msg := wasmvmtypes.IBCChannelCloseMsg{
Expand Down Expand Up @@ -264,7 +264,7 @@ func (i IBCHandler) OnRecvPacket(
) ibcexported.Acknowledgement {
contractAddr, err := ContractFromPortID(packet.DestinationPort)
if err != nil {
return channeltypes.NewErrorAcknowledgement(sdkerrors.Wrapf(err, "contract port id"))
return channeltypes.NewErrorAcknowledgement(errorsmod.Wrapf(err, "contract port id"))
}
msg := wasmvmtypes.IBCPacketReceiveMsg{Packet: newIBCPacket(packet), Relayer: relayer.String()}
ack, err := i.keeper.OnRecvPacket(ctx, contractAddr, msg)
Expand Down Expand Up @@ -295,7 +295,7 @@ func (i IBCHandler) OnAcknowledgementPacket(
) error {
contractAddr, err := ContractFromPortID(packet.SourcePort)
if err != nil {
return sdkerrors.Wrapf(err, "contract port id")
return errorsmod.Wrapf(err, "contract port id")
}

err = i.keeper.OnAckPacket(ctx, contractAddr, wasmvmtypes.IBCPacketAckMsg{
Expand All @@ -304,7 +304,7 @@ func (i IBCHandler) OnAcknowledgementPacket(
Relayer: relayer.String(),
})
if err != nil {
return sdkerrors.Wrap(err, "on ack")
return errorsmod.Wrap(err, "on ack")
}
return nil
}
Expand All @@ -313,12 +313,12 @@ func (i IBCHandler) OnAcknowledgementPacket(
func (i IBCHandler) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error {
contractAddr, err := ContractFromPortID(packet.SourcePort)
if err != nil {
return sdkerrors.Wrapf(err, "contract port id")
return errorsmod.Wrapf(err, "contract port id")
}
msg := wasmvmtypes.IBCPacketTimeoutMsg{Packet: newIBCPacket(packet), Relayer: relayer.String()}
err = i.keeper.OnTimeoutPacket(ctx, contractAddr, msg)
if err != nil {
return sdkerrors.Wrap(err, "on timeout")
return errorsmod.Wrap(err, "on timeout")
}
return nil
}
Expand Down Expand Up @@ -351,7 +351,7 @@ func ValidateChannelParams(channelID string) error {
return err
}
if channelSequence > math.MaxUint32 {
return sdkerrors.Wrapf(types.ErrMaxIBCChannels, "channel sequence %d is greater than max allowed transfer channels %d", channelSequence, math.MaxUint32)
return errorsmod.Wrapf(types.ErrMaxIBCChannels, "channel sequence %d is greater than max allowed transfer channels %d", channelSequence, math.MaxUint32)
}
return nil
}
13 changes: 6 additions & 7 deletions x/wasm/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import (
"testing"
"time"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"

"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/x/wasm"

// simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
Expand All @@ -38,6 +34,9 @@ import (
tmprotoversion "github.com/tendermint/tendermint/proto/tendermint/version"
tmtypes "github.com/tendermint/tendermint/types"
tmversion "github.com/tendermint/tendermint/version"

"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/x/wasm"
)

var MaxAccounts = 10
Expand Down Expand Up @@ -433,7 +432,7 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa
// NextValidatorsHash
tmTrustedVals, ok = counterparty.GetValsAtHeight(int64(trustedHeight.RevisionHeight + 1))
if !ok {
return nil, sdkerrors.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight)
return nil, errorsmod.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight)
}
}
// inject trusted fields into last header
Expand Down
11 changes: 6 additions & 5 deletions x/wasm/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"strings"

errorsmod "cosmossdk.io/errors"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/CosmWasm/wasmd/x/wasm/types"
)
Expand All @@ -31,7 +32,7 @@ func newCustomEvents(evts wasmvmtypes.Events, contractAddr sdk.AccAddress) (sdk.
for _, e := range evts {
typ := strings.TrimSpace(e.Type)
if len(typ) <= eventTypeMinLength {
return nil, sdkerrors.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Event type too short: '%s'", typ))
return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Event type too short: '%s'", typ))
}
attributes, err := contractSDKEventAttributes(e.Attributes, contractAddr)
if err != nil {
Expand All @@ -50,16 +51,16 @@ func contractSDKEventAttributes(customAttributes []wasmvmtypes.EventAttribute, c
// ensure key and value are non-empty (and trim what is there)
key := strings.TrimSpace(l.Key)
if len(key) == 0 {
return nil, sdkerrors.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute key. Value: %s", l.Value))
return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute key. Value: %s", l.Value))
}
value := strings.TrimSpace(l.Value)
// TODO: check if this is legal in the SDK - if it is, we can remove this check
if len(value) == 0 {
return nil, sdkerrors.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute value. Key: %s", key))
return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute value. Key: %s", key))
}
// and reserve all _* keys for our use (not contract)
if strings.HasPrefix(key, types.AttributeReservedPrefix) {
return nil, sdkerrors.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Attribute key starts with reserved prefix %s: '%s'", types.AttributeReservedPrefix, key))
return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Attribute key starts with reserved prefix %s: '%s'", types.AttributeReservedPrefix, key))
}
attrs = append(attrs, sdk.NewAttribute(key, value))
}
Expand Down
9 changes: 5 additions & 4 deletions x/wasm/keeper/gas_register.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
errorsmod "cosmossdk.io/errors"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -140,7 +141,7 @@ func NewDefaultWasmGasRegister() WasmGasRegister {
// NewWasmGasRegister constructor
func NewWasmGasRegister(c WasmGasRegisterConfig) WasmGasRegister {
if c.GasMultiplier == 0 {
panic(sdkerrors.Wrap(sdkerrors.ErrLogic, "GasMultiplier can not be 0"))
panic(errorsmod.Wrap(sdkerrors.ErrLogic, "GasMultiplier can not be 0"))
}
return WasmGasRegister{
c: c,
Expand All @@ -155,23 +156,23 @@ func (g WasmGasRegister) NewContractInstanceCosts(pinned bool, msgLen int) store
// CompileCosts costs to persist and "compile" a new wasm contract
func (g WasmGasRegister) CompileCosts(byteLength int) storetypes.Gas {
if byteLength < 0 {
panic(sdkerrors.Wrap(types.ErrInvalid, "negative length"))
panic(errorsmod.Wrap(types.ErrInvalid, "negative length"))
}
return g.c.CompileCost * uint64(byteLength)
}

// UncompressCosts costs to unpack a new wasm contract
func (g WasmGasRegister) UncompressCosts(byteLength int) sdk.Gas {
if byteLength < 0 {
panic(sdkerrors.Wrap(types.ErrInvalid, "negative length"))
panic(errorsmod.Wrap(types.ErrInvalid, "negative length"))
}
return g.c.UncompressCost.Mul(uint64(byteLength)).Floor()
}

// InstantiateContractCosts costs when interacting with a wasm contract
func (g WasmGasRegister) InstantiateContractCosts(pinned bool, msgLen int) sdk.Gas {
if msgLen < 0 {
panic(sdkerrors.Wrap(types.ErrInvalid, "negative length"))
panic(errorsmod.Wrap(types.ErrInvalid, "negative length"))
}
dataCosts := sdk.Gas(msgLen) * g.c.ContractMessageDataCost
if pinned {
Expand Down
Loading

0 comments on commit 52d6b1f

Please sign in to comment.