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 #2926

Merged
merged 32 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c403bb2
lint tests
faddat Dec 12, 2022
07c1d2b
don't use prealloc for golangci
faddat Dec 12, 2022
7b0c5b3
fix unnecessary conversions
faddat Dec 12, 2022
7e477b2
var-declaration lints
faddat Dec 12, 2022
3c5432d
fix ineffectual assignments
faddat Dec 12, 2022
7666a6b
fix composite literal lints
faddat Dec 12, 2022
54598dc
address copylocks lints from govet
faddat Dec 12, 2022
79bf5fa
error checks in tests
faddat Dec 12, 2022
d6cd199
handshake_test.go error checks
faddat Dec 12, 2022
e2b5a27
packet_test.go error checks
faddat Dec 12, 2022
4cf6f9d
error checks
faddat Dec 12, 2022
0a247d8
msg_server_test.go
faddat Dec 12, 2022
d0ff51e
errcheck in upgrade_test.go
faddat Dec 12, 2022
8567226
goconsts & linting complete
faddat Dec 12, 2022
42011ef
Merge branch 'main' into golangci-lint-for-tests
faddat Dec 12, 2022
a1c1923
Update CHANGELOG.md
faddat Dec 12, 2022
1bfb6cd
Merge remote-tracking branch 'upstream/main' into golangci-lint-for-t…
faddat Dec 12, 2022
dd0fb8f
Merge branch 'golangci-lint-for-tests' of https://github.com/faddat/i…
faddat Dec 12, 2022
bc6a14d
golangci-lint run ./... --fix
faddat Dec 12, 2022
bb230dd
Merge branch 'main' into golangci-lint-for-tests
faddat Dec 18, 2022
43e58b6
last lint
faddat Dec 18, 2022
0cfe15f
fix lints
faddat Dec 18, 2022
56094f5
tidy
faddat Dec 19, 2022
d2aef2d
Merge branch 'main' into golangci-lint-for-tests
Dec 19, 2022
b7e987d
Merge branch 'main' into golangci-lint-for-tests
faddat Dec 21, 2022
9734eff
Merge branch 'main' into golangci-lint-for-tests
faddat Dec 24, 2022
425edf3
ignore legacy ica api
faddat Dec 24, 2022
455b036
ignore icacontrollersendtx
faddat Dec 24, 2022
3f4e78d
Merge branch 'main' into golangci-lint-for-tests
Jan 13, 2023
1b2c4ef
Merge branch 'main' into golangci-lint-for-tests
Jan 13, 2023
824a7a2
golangci lint fixes
crodriguezvega Jan 16, 2023
c2eac31
fix test
crodriguezvega Jan 16, 2023
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
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
run:
tests: false
tests: true
# # timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

linters:
disable-all: true
enable:
- deadcode
- depguard
- dogsled
- exportloopref
- errcheck
- goconst
- gocritic
- gofumpt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- staticcheck
- stylecheck
- revive
Expand All @@ -33,6 +30,9 @@ linters:

issues:
exclude-rules:
- text: "SA1019: suite.chainA.GetSimApp().ICAControllerKeeper.SendTx is deprecated: this is a legacy API that is only intended to function correctly in workflows where an underlying application has been set. Prior to to v6.x.x of ibc-go, the controller module was only functional as middleware, with authentication performed by the underlying application. For a full summary of the changes in v6.x.x, please see ADR009. This API will be removed in later releases."
linters:
- staticcheck
- text: "Use of weak random number generator"
linters:
- gosec
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (tests) [\#2926](https://github.com/cosmos/ibc-go/pull/2926) Lint tests
* (apps/transfer) [\#2643](https://github.com/cosmos/ibc-go/pull/2643) Add amount, denom, and memo to transfer event emission.
* (core) [\#2746](https://github.com/cosmos/ibc-go/pull/2746) Allow proof height to be zero for all core IBC `sdk.Msg` types that contain proofs.
* (light-clients/06-solomachine) [\#2746](https://github.com/cosmos/ibc-go/pull/2746) Discard proofHeight for solo machines and use the solo machine sequence instead.
Expand Down
4 changes: 2 additions & 2 deletions cmd/build_test_matrix/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func SuiteTwo(t *testing.T) {
type FeeMiddlewareTestSuite struct {}
`

err := os.WriteFile(path.Join(testingDir, goTestFileNameOne), []byte(fileWithTwoSuites), os.FileMode(777))
err := os.WriteFile(path.Join(testingDir, goTestFileNameOne), []byte(fileWithTwoSuites), os.FileMode(0o777))
assert.NoError(t, err)

_, err = getGithubActionMatrixForTests(testingDir, "", nil)
Expand Down Expand Up @@ -156,6 +156,6 @@ func helper() {}

func createFileWithTestSuiteAndTests(t *testing.T, suiteName, fn1Name, fn2Name, dir, filename string) {
goFileContents := goTestFileContents(suiteName, fn1Name, fn2Name)
err := os.WriteFile(path.Join(dir, filename), []byte(goFileContents), os.FileMode(777))
err := os.WriteFile(path.Join(dir, filename), []byte(goFileContents), os.FileMode(0o777))
assert.NoError(t, err)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ go 1.19
module github.com/cosmos/ibc-go/v6

require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-beta.4
cosmossdk.io/simapp v0.0.0-20221216140705-ee8890cf30e7
cosmossdk.io/tools/rosetta v0.2.0
Expand Down Expand Up @@ -36,7 +37,6 @@ require (
cosmossdk.io/api v0.2.6 // indirect
cosmossdk.io/core v0.3.2 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
suite.Require().NoError(err)

portCap := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), portID)
suite.chainA.GetSimApp().ICAControllerKeeper.ClaimCapability(suite.chainA.GetContext(), portCap, host.PortPath(portID))
suite.chainA.GetSimApp().ICAControllerKeeper.ClaimCapability(suite.chainA.GetContext(), portCap, host.PortPath(portID)) //nolint:errcheck // checking this error isn't needed for the test

path.EndpointA.ChannelConfig.PortID = portID
path.EndpointA.ChannelID = ibctesting.FirstChannelID
Expand Down Expand Up @@ -276,7 +276,9 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenTry() {
err = RegisterInterchainAccount(path.EndpointB, TestOwnerAddress)
suite.Require().NoError(err)

path.EndpointA.UpdateClient()
err = path.EndpointA.UpdateClient()
suite.Require().NoError(err)

channelKey := host.ChannelKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
proofInit, proofHeight := path.EndpointB.Chain.QueryProof(channelKey)

Expand Down Expand Up @@ -420,7 +422,8 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenConfirm() {
// commit state changes so proof can be created
suite.chainB.NextBlock()

path.EndpointA.UpdateClient()
err = path.EndpointA.UpdateClient()
suite.Require().NoError(err)

// query proof from ChainB
channelKey := host.ChannelKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
{
"invalid port ID",
func() {
path.EndpointA.ChannelConfig.PortID = "invalid-port-id"
path.EndpointA.ChannelConfig.PortID = "invalid-port-id" //nolint:goconst
},
false,
},
Expand Down Expand Up @@ -237,7 +237,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
suite.Require().NoError(err)

portCap := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), portID)
suite.chainA.GetSimApp().ICAControllerKeeper.ClaimCapability(suite.chainA.GetContext(), portCap, host.PortPath(portID))
suite.chainA.GetSimApp().ICAControllerKeeper.ClaimCapability(suite.chainA.GetContext(), portCap, host.PortPath(portID)) //nolint:errcheck // this error check isn't needed for tests
path.EndpointA.ChannelConfig.PortID = portID

// default values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {

func (suite *KeeperTestSuite) TestGetAllActiveChannels() {
var (
expectedChannelID string = "test-channel"
expectedPortID string = "test-port"
expectedChannelID = "test-channel"
expectedPortID = "test-port"
)

suite.SetupTest()
Expand Down Expand Up @@ -193,8 +193,8 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {

func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {
var (
expectedAccAddr string = "test-acc-addr"
expectedPortID string = "test-port"
expectedAccAddr = "test-acc-addr"
expectedPortID = "test-port"
)

suite.SetupTest()
Expand Down Expand Up @@ -245,8 +245,8 @@ func (suite *KeeperTestSuite) TestIsActiveChannel() {

func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() {
var (
expectedAccAddr string = "test-acc-addr"
expectedPortID string = "test-port"
expectedAccAddr = "test-acc-addr"
expectedPortID = "test-port"
)

suite.chainA.GetSimApp().ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedAccAddr)
Expand Down
9 changes: 6 additions & 3 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenAck() {
// commit state changes so proof can be created
suite.chainA.NextBlock()

path.EndpointB.UpdateClient()
err = path.EndpointB.UpdateClient()
suite.Require().NoError(err)

// query proof from ChainA
channelKey := host.ChannelKey(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
Expand Down Expand Up @@ -668,7 +669,8 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose()

_, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), nil, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0))
suite.Require().NoError(err)
path.EndpointB.UpdateClient()
err = path.EndpointB.UpdateClient()
suite.Require().NoError(err)

// relay the packet
packetRelay := channeltypes.NewPacket(icaPacketData.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.ZeroHeight(), ^uint64(0))
Expand All @@ -694,7 +696,8 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose()

_, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), nil, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0))
suite.Require().NoError(err)
path.EndpointB.UpdateClient()
err = path.EndpointB.UpdateClient()
suite.Require().NoError(err)

// relay the packet
packetRelay = channeltypes.NewPacket(icaPacketData.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.ZeroHeight(), ^uint64(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
{
"invalid port ID",
func() {
path.EndpointB.ChannelConfig.PortID = "invalid-port-id"
path.EndpointB.ChannelConfig.PortID = "invalid-port-id" //nolint:goconst
},
false,
},
Expand Down
12 changes: 6 additions & 6 deletions modules/apps/27-interchain-accounts/host/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {

func (suite *KeeperTestSuite) TestGetAllActiveChannels() {
var (
expectedChannelID string = "test-channel"
expectedPortID string = "test-port"
expectedChannelID = "test-channel"
expectedPortID = "test-port"
)

suite.SetupTest()
Expand Down Expand Up @@ -175,8 +175,8 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {

func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {
var (
expectedAccAddr string = "test-acc-addr"
expectedPortID string = "test-port"
expectedAccAddr = "test-acc-addr"
expectedPortID = "test-port"
)

suite.SetupTest()
Expand Down Expand Up @@ -225,8 +225,8 @@ func (suite *KeeperTestSuite) TestIsActiveChannel() {

func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() {
var (
expectedAccAddr string = "test-acc-addr"
expectedPortID string = "test-port"
expectedAccAddr = "test-acc-addr"
expectedPortID = "test-port"
)

suite.chainB.GetSimApp().ICAHostKeeper.SetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedAccAddr)
Expand Down
7 changes: 0 additions & 7 deletions modules/apps/27-interchain-accounts/types/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import (
"github.com/cosmos/ibc-go/v6/testing/simapp"
)

// caseRawBytes defines a helper struct, used for testing codec operations
type caseRawBytes struct {
name string
bz []byte
expPass bool
}

// mockSdkMsg defines a mock struct, used for testing codec error scenarios
type mockSdkMsg struct{}

Expand Down
10 changes: 6 additions & 4 deletions modules/apps/29-fee/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() {
// reset suite
suite.SetupTest()
suite.coordinator.SetupConnections(suite.path)
suite.path.EndpointB.ChanOpenInit()
err := suite.path.EndpointB.ChanOpenInit()
suite.Require().NoError(err)

// setup mock callback
suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanOpenTry = func(ctx sdk.Context, order channeltypes.Order, connectionHops []string,
Expand All @@ -188,7 +189,6 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() {
var (
chanCap *capabilitytypes.Capability
ok bool
err error
)

chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID))
Expand Down Expand Up @@ -286,8 +286,10 @@ func (suite *FeeTestSuite) TestOnChanOpenAck() {
// malleate test case
tc.malleate(suite)

suite.path.EndpointA.ChanOpenInit()
suite.path.EndpointB.ChanOpenTry()
err := suite.path.EndpointA.ChanOpenInit()
suite.Require().NoError(err)
err = suite.path.EndpointB.ChanOpenTry()
suite.Require().NoError(err)

module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.MockFeePort)
suite.Require().NoError(err)
Expand Down
16 changes: 8 additions & 8 deletions modules/apps/29-fee/keeper/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func (suite *KeeperTestSuite) TestIncentivizePacketEvent() {
}

for _, attr := range incentivizedPacketEvent.Attributes {
switch string(attr.Key) {
switch attr.Key {
case types.AttributeKeyRecvFee:
suite.Require().Equal(expRecvFees.String(), string(attr.Value))
suite.Require().Equal(expRecvFees.String(), attr.Value)

case types.AttributeKeyAckFee:
suite.Require().Equal(expAckFees.String(), string(attr.Value))
suite.Require().Equal(expAckFees.String(), attr.Value)

case types.AttributeKeyTimeoutFee:
suite.Require().Equal(expTimeoutFees.String(), string(attr.Value))
suite.Require().Equal(expTimeoutFees.String(), attr.Value)
}
}

Expand All @@ -69,15 +69,15 @@ func (suite *KeeperTestSuite) TestIncentivizePacketEvent() {
}

for _, attr := range incentivizedPacketEvent.Attributes {
switch string(attr.Key) {
switch attr.Key {
case types.AttributeKeyRecvFee:
suite.Require().Equal(expRecvFees.String(), string(attr.Value))
suite.Require().Equal(expRecvFees.String(), attr.Value)

case types.AttributeKeyAckFee:
suite.Require().Equal(expAckFees.String(), string(attr.Value))
suite.Require().Equal(expAckFees.String(), attr.Value)

case types.AttributeKeyTimeoutFee:
suite.Require().Equal(expTimeoutFees.String(), string(attr.Value))
suite.Require().Equal(expTimeoutFees.String(), attr.Value)
}
}
}
4 changes: 2 additions & 2 deletions modules/apps/29-fee/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,14 @@ func (suite *KeeperTestSuite) TestQueryPayee() {
{
"payee address not found: invalid channel",
func() {
req.ChannelId = "invalid-channel-id"
req.ChannelId = "invalid-channel-id" //nolint:goconst
},
false,
},
{
"payee address not found: invalid relayer address",
func() {
req.Relayer = "invalid-addr"
req.Relayer = "invalid-addr" //nolint:goconst
},
false,
},
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ func (suite *KeeperTestSuite) TestGetAllIdentifiedPacketFees() {
}

func (suite *KeeperTestSuite) TestGetAllFeeEnabledChannels() {
validPortId := "ibcmoduleport"
validPortID := "ibcmoduleport"
// set two channels enabled
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID)
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), validPortId, ibctesting.FirstChannelID)
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), validPortID, ibctesting.FirstChannelID)

expectedCh := []types.FeeEnabledChannel{
{
PortId: validPortId,
PortId: validPortID,
ChannelId: ibctesting.FirstChannelID,
},
{
Expand Down
Loading