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

lint tests #1130

Closed
wants to merge 10 commits into from
Closed
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
9 changes: 2 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
run:
tests: false
tests: true

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
- goconst
- gocritic
- gofmt
- goimports
- gofumpt
- revive
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- exportloopref
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- varcheck

issues:
exclude-rules:
Expand Down
21 changes: 1 addition & 20 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
)

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

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

func setGenesis(gapp *WasmApp) error {
genesisState := NewDefaultGenesisState()
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
}
6 changes: 3 additions & 3 deletions benchmarks/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo {
}
storeTx, err := helpers.GenTx(txGen, []sdk.Msg{&storeMsg}, nil, 55123123, "", []uint64{0}, []uint64{0}, minter)
require.NoError(b, err)
_, res, err := wasmApp.Deliver(txGen.TxEncoder(), storeTx)
_, _, err = wasmApp.Deliver(txGen.TxEncoder(), storeTx)
require.NoError(b, err)
codeID := uint64(1)

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

// TODO: parse contract address better
Expand Down Expand Up @@ -202,7 +202,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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ require (
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint v0.34.23
Expand Down Expand Up @@ -111,6 +110,7 @@ require (
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.14.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/tendermint/btcd v0.1.1 // indirect
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/ica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestICA(t *testing.T) {
ownerAddr := sdk.AccAddress(controllerChain.SenderPrivKey.PubKey().Address())
msg := intertxtypes.NewMsgRegisterAccount(ownerAddr.String(), path.EndpointA.ConnectionID, "")
res, err := controllerChain.SendMsgs(msg)
require.NoError(t, err)
chanID, portID, version := parseIBCChannelEvents(t, res)

// next open channels on both sides
Expand Down Expand Up @@ -69,7 +70,7 @@ func TestICA(t *testing.T) {
payloadMsg := banktypes.NewMsgSend(icaAddr, targetAddr, sdk.NewCoins(sendCoin))
msg2, err := intertxtypes.NewMsgSubmitTx(payloadMsg, path.EndpointA.ConnectionID, ownerAddr.String())
require.NoError(t, err)
res, err = controllerChain.SendMsgs(msg2)
_, err = controllerChain.SendMsgs(msg2)
require.NoError(t, err)

assert.Equal(t, 1, len(controllerChain.PendingSendPackets))
Expand Down
8 changes: 4 additions & 4 deletions x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestInitGenesis(t *testing.T) {
creator := data.faucet.NewFundedRandomAccount(data.ctx, deposit.Add(deposit...)...)
fred := data.faucet.NewFundedRandomAccount(data.ctx, topUp...)

h := data.module.Route().Handler()
q := data.module.LegacyQuerierHandler(nil)
h := data.module.Route().Handler() //nolint:staticcheck // SA1019: data.module.Route is deprecated: use LegacyQuerierHandler instead. (staticcheck)
q := data.module.LegacyQuerierHandler(nil) //nolint:staticcheck // SA1019: data.module.LegacyQuerierHandler is deprecated: use LegacyQuerierHandler instead. (staticcheck)

msg := MsgStoreCode{
Sender: creator.String(),
Expand Down Expand Up @@ -77,10 +77,10 @@ func TestInitGenesis(t *testing.T) {

// create new app to import genstate into
newData := setupTest(t)
q2 := newData.module.LegacyQuerierHandler(nil)
q2 := newData.module.LegacyQuerierHandler(nil) //nolint:staticcheck // SA1019: data.module.LegacyQuerierHandler is deprecated: use LegacyQuerierHandler instead. (staticcheck)

// initialize new app with genstate
InitGenesis(newData.ctx, &newData.keeper, *genState)
InitGenesis(newData.ctx, &newData.keeper, *genState) //nolint:staticcheck,errcheck // SA1019: data.module.Route is deprecated: use LegacyQuerierHandler instead. (staticcheck)

// run same checks again on newdata, to make sure it was reinitialized correctly
assertCodeList(t, q2, newData.ctx, 1)
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 @@ -115,7 +115,7 @@ func TestCountTxDecorator(t *testing.T) {
func TestLimitSimulationGasDecorator(t *testing.T) {
var (
hundred sdk.Gas = 100
zero sdk.Gas = 0
zero sdk.Gas
)
specs := map[string]struct {
customLimit *sdk.Gas
Expand Down Expand Up @@ -171,12 +171,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
24 changes: 12 additions & 12 deletions x/wasm/keeper/gas_register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func TestNewContractInstanceCosts(t *testing.T) {
"big msg - unpinned": {
srcLen: math.MaxUint32,
srcConfig: DefaultGasRegisterConfig(),
exp: sdk.Gas(DefaultContractMessageDataCost*math.MaxUint32 + DefaultInstanceCost),
exp: DefaultContractMessageDataCost*math.MaxUint32 + DefaultInstanceCost,
},
"empty msg - unpinned": {
srcLen: 0,
srcConfig: DefaultGasRegisterConfig(),
exp: sdk.Gas(DefaultInstanceCost),
exp: DefaultInstanceCost,
},

"negative len": {
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestContractInstanceCosts(t *testing.T) {
srcLen: math.MaxUint32,
srcConfig: DefaultGasRegisterConfig(),
pinned: true,
exp: sdk.Gas(DefaultContractMessageDataCost * math.MaxUint32),
exp: DefaultContractMessageDataCost * math.MaxUint32,
},
"empty msg - pinned": {
srcLen: 0,
Expand All @@ -147,12 +147,12 @@ func TestContractInstanceCosts(t *testing.T) {
"big msg - unpinned": {
srcLen: math.MaxUint32,
srcConfig: DefaultGasRegisterConfig(),
exp: sdk.Gas(DefaultContractMessageDataCost*math.MaxUint32 + DefaultInstanceCost),
exp: DefaultContractMessageDataCost*math.MaxUint32 + DefaultInstanceCost,
},
"empty msg - unpinned": {
srcLen: 0,
srcConfig: DefaultGasRegisterConfig(),
exp: sdk.Gas(DefaultInstanceCost),
exp: DefaultInstanceCost,
},

"negative len": {
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestReplyCost(t *testing.T) {
},
srcConfig: DefaultGasRegisterConfig(),
pinned: true,
exp: sdk.Gas(3*DefaultEventAttributeDataCost + DefaultPerAttributeCost + DefaultContractMessageDataCost), // 3 == len("foo")
exp: 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost + DefaultContractMessageDataCost, // 3 == len("foo")
},
"subcall response with events - pinned": {
src: wasmvmtypes.Reply{
Expand All @@ -210,7 +210,7 @@ func TestReplyCost(t *testing.T) {
},
srcConfig: DefaultGasRegisterConfig(),
pinned: true,
exp: sdk.Gas(3*DefaultEventAttributeDataCost + DefaultPerAttributeCost), // 3 == len("foo")
exp: 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost, // 3 == len("foo")
},
"subcall response with events exceeds free tier- pinned": {
src: wasmvmtypes.Reply{
Expand All @@ -224,7 +224,7 @@ func TestReplyCost(t *testing.T) {
},
srcConfig: DefaultGasRegisterConfig(),
pinned: true,
exp: sdk.Gas((3+6)*DefaultEventAttributeDataCost + DefaultPerAttributeCost), // 3 == len("foo"), 6 == len("myData")
exp: (3+6)*DefaultEventAttributeDataCost + DefaultPerAttributeCost, // 3 == len("foo"), 6 == len("myData")
},
"subcall response error - pinned": {
src: wasmvmtypes.Reply{
Expand All @@ -248,7 +248,7 @@ func TestReplyCost(t *testing.T) {
},
},
srcConfig: DefaultGasRegisterConfig(),
exp: sdk.Gas(DefaultInstanceCost + 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost + DefaultContractMessageDataCost),
exp: DefaultInstanceCost + 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost + DefaultContractMessageDataCost,
},
"subcall response with events - unpinned": {
src: wasmvmtypes.Reply{
Expand All @@ -261,7 +261,7 @@ func TestReplyCost(t *testing.T) {
},
},
srcConfig: DefaultGasRegisterConfig(),
exp: sdk.Gas(DefaultInstanceCost + 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost),
exp: DefaultInstanceCost + 3*DefaultEventAttributeDataCost + DefaultPerAttributeCost,
},
"subcall response with events exceeds free tier- unpinned": {
src: wasmvmtypes.Reply{
Expand All @@ -274,7 +274,7 @@ func TestReplyCost(t *testing.T) {
},
},
srcConfig: DefaultGasRegisterConfig(),
exp: sdk.Gas(DefaultInstanceCost + (3+6)*DefaultEventAttributeDataCost + DefaultPerAttributeCost), // 3 == len("foo"), 6 == len("myData")
exp: DefaultInstanceCost + (3+6)*DefaultEventAttributeDataCost + DefaultPerAttributeCost, // 3 == len("foo"), 6 == len("myData")
},
"subcall response error - unpinned": {
src: wasmvmtypes.Reply{
Expand All @@ -283,7 +283,7 @@ func TestReplyCost(t *testing.T) {
},
},
srcConfig: DefaultGasRegisterConfig(),
exp: sdk.Gas(DefaultInstanceCost + 3*DefaultContractMessageDataCost),
exp: DefaultInstanceCost + 3*DefaultContractMessageDataCost,
},
"subcall response with empty events": {
src: wasmvmtypes.Reply{
Expand Down
Loading