Skip to content

Commit 96d58e7

Browse files
lint tests (#2926)
* lint tests * don't use prealloc for golangci * fix unnecessary conversions * var-declaration lints * fix ineffectual assignments * fix composite literal lints * address copylocks lints from govet * error checks in tests * handshake_test.go error checks * packet_test.go error checks * error checks * msg_server_test.go * errcheck in upgrade_test.go * goconsts & linting complete * Update CHANGELOG.md * golangci-lint run ./... --fix * last lint * fix lints * tidy * ignore legacy ica api * ignore icacontrollersendtx * golangci lint fixes * fix test Co-authored-by: Carlos Rodriguez <carlos@interchain.io> Co-authored-by: Carlos Rodriguez <crodveg@gmail.com>
1 parent 6e67730 commit 96d58e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+330
-251
lines changed

.golangci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
run:
2-
tests: false
2+
tests: true
33
# # timeout for analysis, e.g. 30s, 5m, default is 1m
44
timeout: 5m
55

66
linters:
77
disable-all: true
88
enable:
9-
- deadcode
109
- depguard
1110
- dogsled
1211
- exportloopref
1312
- errcheck
1413
- goconst
1514
- gocritic
1615
- gofumpt
17-
- goimports
1816
- gosec
1917
- gosimple
2018
- govet
2119
- ineffassign
2220
- misspell
2321
- nakedret
24-
- prealloc
2522
- staticcheck
2623
- stylecheck
2724
- revive
@@ -33,6 +30,9 @@ linters:
3330

3431
issues:
3532
exclude-rules:
33+
- 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."
34+
linters:
35+
- staticcheck
3636
- text: "Use of weak random number generator"
3737
linters:
3838
- gosec

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
6868

6969
### Improvements
7070

71+
* (tests) [\#2926](https://github.com/cosmos/ibc-go/pull/2926) Lint tests
7172
* (apps/transfer) [\#2643](https://github.com/cosmos/ibc-go/pull/2643) Add amount, denom, and memo to transfer event emission.
7273
* (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.
7374
* (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.

cmd/build_test_matrix/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func SuiteTwo(t *testing.T) {
102102
type FeeMiddlewareTestSuite struct {}
103103
`
104104

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

108108
_, err = getGithubActionMatrixForTests(testingDir, "", nil)
@@ -156,6 +156,6 @@ func helper() {}
156156

157157
func createFileWithTestSuiteAndTests(t *testing.T, suiteName, fn1Name, fn2Name, dir, filename string) {
158158
goFileContents := goTestFileContents(suiteName, fn1Name, fn2Name)
159-
err := os.WriteFile(path.Join(dir, filename), []byte(goFileContents), os.FileMode(777))
159+
err := os.WriteFile(path.Join(dir, filename), []byte(goFileContents), os.FileMode(0o777))
160160
assert.NoError(t, err)
161161
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ go 1.19
33
module github.com/cosmos/ibc-go/v6
44

55
require (
6+
cosmossdk.io/errors v1.0.0-beta.7
67
cosmossdk.io/math v1.0.0-beta.4
78
cosmossdk.io/simapp v0.0.0-20221216140705-ee8890cf30e7
89
cosmossdk.io/tools/rosetta v0.2.0
@@ -36,7 +37,6 @@ require (
3637
cosmossdk.io/api v0.2.6 // indirect
3738
cosmossdk.io/core v0.3.2 // indirect
3839
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
39-
cosmossdk.io/errors v1.0.0-beta.7 // indirect
4040
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
4141
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
4242
github.com/99designs/keyring v1.2.1 // indirect

modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
209209
suite.Require().NoError(err)
210210

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

214214
path.EndpointA.ChannelConfig.PortID = portID
215215
path.EndpointA.ChannelID = ibctesting.FirstChannelID
@@ -276,7 +276,9 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenTry() {
276276
err = RegisterInterchainAccount(path.EndpointB, TestOwnerAddress)
277277
suite.Require().NoError(err)
278278

279-
path.EndpointA.UpdateClient()
279+
err = path.EndpointA.UpdateClient()
280+
suite.Require().NoError(err)
281+
280282
channelKey := host.ChannelKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
281283
proofInit, proofHeight := path.EndpointB.Chain.QueryProof(channelKey)
282284

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

423-
path.EndpointA.UpdateClient()
425+
err = path.EndpointA.UpdateClient()
426+
suite.Require().NoError(err)
424427

425428
// query proof from ChainB
426429
channelKey := host.ChannelKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
103103
{
104104
"invalid port ID",
105105
func() {
106-
path.EndpointA.ChannelConfig.PortID = "invalid-port-id"
106+
path.EndpointA.ChannelConfig.PortID = "invalid-port-id" //nolint:goconst
107107
},
108108
false,
109109
},
@@ -237,7 +237,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
237237
suite.Require().NoError(err)
238238

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

243243
// default values

modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
157157

158158
func (suite *KeeperTestSuite) TestGetAllActiveChannels() {
159159
var (
160-
expectedChannelID string = "test-channel"
161-
expectedPortID string = "test-port"
160+
expectedChannelID = "test-channel"
161+
expectedPortID = "test-port"
162162
)
163163

164164
suite.SetupTest()
@@ -193,8 +193,8 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {
193193

194194
func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {
195195
var (
196-
expectedAccAddr string = "test-acc-addr"
197-
expectedPortID string = "test-port"
196+
expectedAccAddr = "test-acc-addr"
197+
expectedPortID = "test-port"
198198
)
199199

200200
suite.SetupTest()
@@ -245,8 +245,8 @@ func (suite *KeeperTestSuite) TestIsActiveChannel() {
245245

246246
func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() {
247247
var (
248-
expectedAccAddr string = "test-acc-addr"
249-
expectedPortID string = "test-port"
248+
expectedAccAddr = "test-acc-addr"
249+
expectedPortID = "test-port"
250250
)
251251

252252
suite.chainA.GetSimApp().ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedAccAddr)

modules/apps/27-interchain-accounts/host/ibc_module_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenAck() {
251251
// commit state changes so proof can be created
252252
suite.chainA.NextBlock()
253253

254-
path.EndpointB.UpdateClient()
254+
err = path.EndpointB.UpdateClient()
255+
suite.Require().NoError(err)
255256

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

669670
_, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), nil, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0))
670671
suite.Require().NoError(err)
671-
path.EndpointB.UpdateClient()
672+
err = path.EndpointB.UpdateClient()
673+
suite.Require().NoError(err)
672674

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

695697
_, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), nil, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0))
696698
suite.Require().NoError(err)
697-
path.EndpointB.UpdateClient()
699+
err = path.EndpointB.UpdateClient()
700+
suite.Require().NoError(err)
698701

699702
// relay the packet
700703
packetRelay = channeltypes.NewPacket(icaPacketData.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.ZeroHeight(), ^uint64(0))

modules/apps/27-interchain-accounts/host/keeper/handshake_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
167167
{
168168
"invalid port ID",
169169
func() {
170-
path.EndpointB.ChannelConfig.PortID = "invalid-port-id"
170+
path.EndpointB.ChannelConfig.PortID = "invalid-port-id" //nolint:goconst
171171
},
172172
false,
173173
},

modules/apps/27-interchain-accounts/host/keeper/keeper_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
141141

142142
func (suite *KeeperTestSuite) TestGetAllActiveChannels() {
143143
var (
144-
expectedChannelID string = "test-channel"
145-
expectedPortID string = "test-port"
144+
expectedChannelID = "test-channel"
145+
expectedPortID = "test-port"
146146
)
147147

148148
suite.SetupTest()
@@ -175,8 +175,8 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {
175175

176176
func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {
177177
var (
178-
expectedAccAddr string = "test-acc-addr"
179-
expectedPortID string = "test-port"
178+
expectedAccAddr = "test-acc-addr"
179+
expectedPortID = "test-port"
180180
)
181181

182182
suite.SetupTest()
@@ -225,8 +225,8 @@ func (suite *KeeperTestSuite) TestIsActiveChannel() {
225225

226226
func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() {
227227
var (
228-
expectedAccAddr string = "test-acc-addr"
229-
expectedPortID string = "test-port"
228+
expectedAccAddr = "test-acc-addr"
229+
expectedPortID = "test-port"
230230
)
231231

232232
suite.chainB.GetSimApp().ICAHostKeeper.SetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedAccAddr)

0 commit comments

Comments
 (0)