Skip to content

Commit

Permalink
linting 47 pr (#1261)
Browse files Browse the repository at this point in the history
* lint cosmwasm for sdk 47

* fix

* remove setGenesis

* remove additional unused functions

* pass tests

* use SDK's errors module

* unecessary conversions

* unnecessary conversions

* remove unneeded event manager

* complete linting of tests for 47

* add test for reimportation

* check errors

* Update x/wasm/keeper/proposal_integration_test.go

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* apply suggestion

* suggestions

* lints

* don't return error in when making new transactions

* no todo's in the code

* Fix test data generator

* Update x/wasm/types/genesis_test.go

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>

* use the full string invalid address (2 words) always

---------

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>
  • Loading branch information
faddat and alpe authored Mar 15, 2023
1 parent 2eaa893 commit bb13192
Show file tree
Hide file tree
Showing 49 changed files with 297 additions and 323 deletions.
50 changes: 28 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
run:
tests: false
tests: true
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

linters:
disable-all: true
Expand All @@ -8,53 +10,57 @@ linters:
- depguard
- dogsled
- errcheck
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- revive
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- exportloopref
- nolintlint
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused

issues:
exclude-rules:
- text: "simtypes"
linters:
- staticcheck
- text: "Use of weak random number generator"
linters:
- gosec
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
dogsled:
max-blank-identifiers: 3
errcheck:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0
prealloc:
# XXX: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.

# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# True by default.
simple: false
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: true # Report preallocation suggestions on for loops, false by default
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ var (
// WasmApp extended ABCI application
type WasmApp struct {
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino //nolint:staticcheck
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry types.InterfaceRegistry
Expand Down Expand Up @@ -911,7 +911,7 @@ func (app *WasmApp) LoadHeight(height int64) error {
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *WasmApp) LegacyAmino() *codec.LegacyAmino { //nolint:staticcheck
func (app *WasmApp) LegacyAmino() *codec.LegacyAmino {
return app.legacyAmino
}

Expand Down
23 changes: 1 addition & 22 deletions app/app_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package app

import (
"encoding/json"
"os"
"testing"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -16,7 +14,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
)

var emptyWasmOpts []wasm.Option = nil
var emptyWasmOpts []wasm.Option

func TestWasmdExport(t *testing.T) {
db := dbm.NewMemDB()
Expand Down Expand Up @@ -85,22 +83,3 @@ func TestGetEnabledProposals(t *testing.T) {
})
}
}

func setGenesis(gapp *WasmApp) error {
genesisState := NewDefaultGenesisState(gapp.appCodec)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
return err
}

// Initialize the chain
gapp.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)

gapp.Commit()
return nil
}
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) //nolint:errcheck
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
return false
})

Expand Down
8 changes: 4 additions & 4 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (app WasmApp) RegisterUpgradeHandlers() {
case banktypes.ModuleName:
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck
case stakingtypes.ModuleName:
keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck
keyTable = stakingtypes.ParamKeyTable()
case minttypes.ModuleName:
keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
case distrtypes.ModuleName:
Expand All @@ -57,11 +57,11 @@ func (app WasmApp) RegisterUpgradeHandlers() {
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck
// ibc types
case ibctransfertypes.ModuleName:
keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck
keyTable = ibctransfertypes.ParamKeyTable()
case icahosttypes.SubModuleName:
keyTable = icahosttypes.ParamKeyTable() //nolint:staticcheck
keyTable = icahosttypes.ParamKeyTable()
case icacontrollertypes.SubModuleName:
keyTable = icacontrollertypes.ParamKeyTable() //nolint:staticcheck
keyTable = icacontrollertypes.ParamKeyTable()
// wasm
case wasmtypes.ModuleName:
keyTable = wasmtypes.ParamKeyTable() //nolint:staticcheck
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)

func setup(db dbm.DB, withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*app.WasmApp, app.GenesisState) {
func setup(db dbm.DB, withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*app.WasmApp, app.GenesisState) { //nolint:unparam
wasmApp := app.NewWasmApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, wasm.EnableAllProposals, simtestutil.EmptyAppOptions{}, nil)

if withGenesis {
Expand Down Expand Up @@ -182,7 +182,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
storeTx, err := simtestutil.GenSignedMockTx(r, txGen, []sdk.Msg{&storeMsg}, nil, 55123123, "", []uint64{0}, []uint64{0}, minter)
require.NoError(b, err)
_, res, err := wasmApp.SimDeliver(txGen.TxEncoder(), storeTx)
_, _, err = wasmApp.SimDeliver(txGen.TxEncoder(), storeTx)
require.NoError(b, err)
codeID := uint64(1)

Expand Down Expand Up @@ -216,13 +216,13 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo {
gasWanted := 500000 + 10000*uint64(numAccounts)
initTx, err := simtestutil.GenSignedMockTx(r, txGen, []sdk.Msg{&initMsg}, nil, gasWanted, "", []uint64{0}, []uint64{1}, minter)
require.NoError(b, err)
_, res, err = wasmApp.SimDeliver(txGen.TxEncoder(), initTx)
_, res, err := wasmApp.SimDeliver(txGen.TxEncoder(), initTx)
require.NoError(b, err)

// TODO: parse contract address better
evt := res.Events[len(res.Events)-1]
attr := evt.Attributes[0]
contractAddr := string(attr.Value)
contractAddr := attr.Value

wasmApp.EndBlock(abci.RequestEndBlock{Height: height})
wasmApp.Commit()
Expand Down Expand Up @@ -259,7 +259,7 @@ func GenSequenceOfTxs(b testing.TB, info *AppInfo, msgGen func(*AppInfo) ([]sdk.
info.MinterKey,
)
require.NoError(b, err)
info.SeqNum += 1
info.SeqNum++
}

return txs
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestGovVoteByContract(t *testing.T) {

// with other delegators voted yes
_, err = chain.SendMsgs(v1.NewMsgVote(chain.SenderAccount.GetAddress(), propID, v1.VoteOption_VOTE_OPTION_YES, ""))
require.NoError(t, gotErr)
require.NoError(t, err)

// when contract votes
spec.vote.ProposalId = propID
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -49,7 +50,7 @@ func TestGrants(t *testing.T) {
filter types.ContractAuthzFilterX
transferAmount sdk.Coin
senderKey cryptotypes.PrivKey
expErr *sdkerrors.Error
expErr *errorsmod.Error
}{
"in limits and filter": {
limit: types.NewMaxFundsLimit(myAmount),
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/ica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestICA(t *testing.T) {
}
relativeTimeout := uint64(time.Minute.Nanoseconds()) // note this is in nanoseconds
msgSendTx := icacontrollertypes.NewMsgSendTx(ownerAddr.String(), path.EndpointA.ConnectionID, relativeTimeout, payloadPacket)
res, err = controllerChain.SendMsgs(msgSendTx)
_, err = controllerChain.SendMsgs(msgSendTx)
require.NoError(t, err)

assert.Equal(t, 1, len(controllerChain.PendingSendPackets))
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/alias.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint
//nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/Cosmwasm/wasmd/x/wasm/types
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func ProposalUpdateContractAdminCmd() *cobra.Command {
return err
}

src, err := parseUpdateContractAdminArgs(args, clientCtx)
src := parseUpdateContractAdminArgs(args, clientCtx)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func UpdateContractAdminCmd() *cobra.Command {
return err
}

msg, err := parseUpdateContractAdminArgs(args, clientCtx)
msg := parseUpdateContractAdminArgs(args, clientCtx)
if err != nil {
return err
}
Expand All @@ -86,13 +86,13 @@ func UpdateContractAdminCmd() *cobra.Command {
return cmd
}

func parseUpdateContractAdminArgs(args []string, cliCtx client.Context) (types.MsgUpdateAdmin, error) {
func parseUpdateContractAdminArgs(args []string, cliCtx client.Context) types.MsgUpdateAdmin {
msg := types.MsgUpdateAdmin{
Sender: cliCtx.GetFromAddress().String(),
Contract: args[0],
NewAdmin: args[1],
}
return msg, nil
return msg
}

// ClearContractAdminCmd clears an admin for a contract
Expand Down
3 changes: 2 additions & 1 deletion x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func TestInitGenesis(t *testing.T) {
q2 := newData.grpcQueryRouter

// initialize new app with genstate
InitGenesis(newData.ctx, &newData.keeper, *genState)
_, err = InitGenesis(newData.ctx, &newData.keeper, *genState)
require.NoError(t, err)

// run same checks again on newdata, to make sure it was reinitialized correctly
assertCodeList(t, q2, newData.ctx, 1, data.encConf.Marshaler)
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/ibctesting/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/golang/protobuf/proto" //nolint
"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"

"github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down
8 changes: 5 additions & 3 deletions x/wasm/keeper/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestCountTxDecorator(t *testing.T) {
func TestLimitSimulationGasDecorator(t *testing.T) {
var (
hundred sdk.Gas = 100
zero sdk.Gas = 0
zero sdk.Gas = 0 //nolint:revive // leave the zero for clarity
)
specs := map[string]struct {
customLimit *sdk.Gas
Expand Down Expand Up @@ -169,12 +169,14 @@ func TestLimitSimulationGasDecorator(t *testing.T) {
if spec.expErr != nil {
require.PanicsWithValue(t, spec.expErr, func() {
ante := keeper.NewLimitSimulationGasDecorator(spec.customLimit)
ante.AnteHandle(ctx, nil, spec.simulation, nextAnte)
_, err := ante.AnteHandle(ctx, nil, spec.simulation, nextAnte)
require.NoError(t, err)
})
return
}
ante := keeper.NewLimitSimulationGasDecorator(spec.customLimit)
ante.AnteHandle(ctx, nil, spec.simulation, nextAnte)
_, err := ante.AnteHandle(ctx, nil, spec.simulation, nextAnte)
require.NoError(t, err)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func hasWasmModuleEvent(ctx sdk.Context, contractAddr sdk.AccAddress) bool {
for _, e := range ctx.EventManager().Events() {
if e.Type == types.WasmModuleEventType {
for _, a := range e.Attributes {
if string(a.Key) == types.AttributeKeyContractAddr && string(a.Value) == contractAddr.String() {
if a.Key == types.AttributeKeyContractAddr && a.Value == contractAddr.String() {
return true
}
}
Expand Down
Loading

0 comments on commit bb13192

Please sign in to comment.