Skip to content

Commit

Permalink
chore: fix linter warnings (#3311)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5a67efc)

# Conflicts:
#	modules/apps/27-interchain-accounts/controller/keeper/account.go
#	modules/apps/27-interchain-accounts/controller/keeper/genesis.go
#	modules/apps/27-interchain-accounts/host/keeper/genesis.go
#	modules/core/02-client/migrations/v7/store.go
#	modules/core/04-channel/keeper/handshake_test.go
#	modules/core/keeper/msg_server.go
#	modules/core/module.go
#	testing/chain.go
  • Loading branch information
crodriguezvega authored and mergify[bot] committed Apr 18, 2023
1 parent 524ee5b commit 1245047
Show file tree
Hide file tree
Showing 39 changed files with 190 additions and 218 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.3.1
with:
version: latest
version: v1.52.0
args: --timeout 5m
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ linters:

issues:
exclude-rules:
- text: "unused-parameter"
linters:
- revive
- text: "SA1019:"
linters:
- staticcheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ func SetupICAPath(path *ibctesting.Path, owner string) error {
return err
}

if err := path.EndpointB.ChanOpenConfirm(); err != nil {
return err
}

return nil
return path.EndpointB.ChanOpenConfirm()
}

func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID,
case k.portKeeper.IsBound(ctx, portID) && !k.IsBound(ctx, portID):
return "", sdkerrors.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID)
case !k.portKeeper.IsBound(ctx, portID):
<<<<<<< HEAD
cap := k.BindPort(ctx, portID)
if err := k.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil {
return "", sdkerrors.Wrapf(err, "unable to bind to newly generated portID: %s", portID)
=======
capability := k.BindPort(ctx, portID)
if err := k.ClaimCapability(ctx, capability, host.PortPath(portID)); err != nil {
return "", errorsmod.Wrapf(err, "unable to bind to newly generated portID: %s", portID)
>>>>>>> 5a67efc4 (chore: fix linter warnings (#3311))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {
{
"port is already bound for owner but capability is claimed by another module",
func() {
cap := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID)
err := suite.chainA.GetSimApp().TransferKeeper.ClaimCapability(suite.chainA.GetContext(), cap, host.PortPath(TestPortID))
capability := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID)
err := suite.chainA.GetSimApp().TransferKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(TestPortID))
suite.Require().NoError(err)
},
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ import (
// InitGenesis initializes the interchain accounts controller application state from a provided genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGenesisState) {
for _, portID := range state.Ports {
<<<<<<< HEAD
if !keeper.IsBound(ctx, portID) {
cap := keeper.BindPort(ctx, portID)
if err := keeper.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil {
=======
if !keeper.HasCapability(ctx, portID) {
capability := keeper.BindPort(ctx, portID)
if err := keeper.ClaimCapability(ctx, capability, host.PortPath(portID)); err != nil {
>>>>>>> 5a67efc4 (chore: fix linter warnings (#3311))
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ func SetupICAPath(path *ibctesting.Path, owner string) error {
return err
}

if err := path.EndpointB.ChanOpenConfirm(); err != nil {
return err
}

return nil
return path.EndpointB.ChanOpenConfirm()
}

// RegisterInterchainAccount is a helper function for starting the channel handshake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ func (suite *MigrationsTestSuite) SetupPath() error {
return err
}

if err := suite.path.EndpointB.ChanOpenConfirm(); err != nil {
return err
}

return nil
return suite.path.EndpointB.ChanOpenConfirm()
}

func (suite *MigrationsTestSuite) RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) error {
Expand Down Expand Up @@ -101,22 +97,22 @@ func (suite *MigrationsTestSuite) TestMigrateICS27ChannelCapability() {
// note: suite.SetupPath() now claims the chanel capability using icacontroller for "channel-0"
capName := host.ChannelCapabilityPath(suite.path.EndpointA.ChannelConfig.PortID, channeltypes.FormatChannelIdentifier(1))

cap, err := suite.chainA.GetSimApp().ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), capName)
capability, err := suite.chainA.GetSimApp().ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), capName)
suite.Require().NoError(err)

err = suite.chainA.GetSimApp().ScopedICAMockKeeper.ClaimCapability(suite.chainA.GetContext(), cap, capName)
err = suite.chainA.GetSimApp().ScopedICAMockKeeper.ClaimCapability(suite.chainA.GetContext(), capability, capName)
suite.Require().NoError(err)

// assert the capability is owned by the mock module
cap, found := suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().NotNil(cap)
capability, found := suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().NotNil(capability)
suite.Require().True(found)

isAuthenticated := suite.chainA.GetSimApp().ScopedICAMockKeeper.AuthenticateCapability(suite.chainA.GetContext(), cap, capName)
isAuthenticated := suite.chainA.GetSimApp().ScopedICAMockKeeper.AuthenticateCapability(suite.chainA.GetContext(), capability, capName)
suite.Require().True(isAuthenticated)

cap, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().Nil(cap)
capability, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().Nil(capability)
suite.Require().False(found)

suite.ResetMemStore() // empty the x/capability in-memory store
Expand All @@ -132,24 +128,24 @@ func (suite *MigrationsTestSuite) TestMigrateICS27ChannelCapability() {
suite.Require().NoError(err)

// assert the capability is now owned by the ICS27 controller submodule
cap, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().NotNil(cap)
capability, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().NotNil(capability)
suite.Require().True(found)

isAuthenticated = suite.chainA.GetSimApp().ScopedICAControllerKeeper.AuthenticateCapability(suite.chainA.GetContext(), cap, capName)
isAuthenticated = suite.chainA.GetSimApp().ScopedICAControllerKeeper.AuthenticateCapability(suite.chainA.GetContext(), capability, capName)
suite.Require().True(isAuthenticated)

cap, found = suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().Nil(cap)
capability, found = suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().Nil(capability)
suite.Require().False(found)

// ensure channel capability for "channel-0" is still owned by the controller
capName = host.ChannelCapabilityPath(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)
cap, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().NotNil(cap)
capability, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName)
suite.Require().NotNil(capability)
suite.Require().True(found)

isAuthenticated = suite.chainA.GetSimApp().ScopedICAControllerKeeper.AuthenticateCapability(suite.chainA.GetContext(), cap, capName)
isAuthenticated = suite.chainA.GetSimApp().ScopedICAControllerKeeper.AuthenticateCapability(suite.chainA.GetContext(), capability, capName)
suite.Require().True(isAuthenticated)

suite.AssertMockCapabiltiesUnchanged()
Expand All @@ -159,29 +155,29 @@ func (suite *MigrationsTestSuite) TestMigrateICS27ChannelCapability() {
// 1. A capability with a single owner
// 2. A capability with two owners, neither of which is "ibc"
func (suite *MigrationsTestSuite) CreateMockCapabilities() {
cap, err := suite.chainA.GetSimApp().ScopedIBCMockKeeper.NewCapability(suite.chainA.GetContext(), "mock_one")
capability, err := suite.chainA.GetSimApp().ScopedIBCMockKeeper.NewCapability(suite.chainA.GetContext(), "mock_one")
suite.Require().NoError(err)
suite.Require().NotNil(cap)
suite.Require().NotNil(capability)

cap, err = suite.chainA.GetSimApp().ScopedICAMockKeeper.NewCapability(suite.chainA.GetContext(), "mock_two")
capability, err = suite.chainA.GetSimApp().ScopedICAMockKeeper.NewCapability(suite.chainA.GetContext(), "mock_two")
suite.Require().NoError(err)
suite.Require().NotNil(cap)
suite.Require().NotNil(capability)

err = suite.chainA.GetSimApp().ScopedIBCMockKeeper.ClaimCapability(suite.chainA.GetContext(), cap, "mock_two")
err = suite.chainA.GetSimApp().ScopedIBCMockKeeper.ClaimCapability(suite.chainA.GetContext(), capability, "mock_two")
suite.Require().NoError(err)
}

// AssertMockCapabiltiesUnchanged authenticates the mock capabilities created at the start of the test to ensure they remain unchanged
func (suite *MigrationsTestSuite) AssertMockCapabiltiesUnchanged() {
cap, found := suite.chainA.GetSimApp().ScopedIBCMockKeeper.GetCapability(suite.chainA.GetContext(), "mock_one")
capability, found := suite.chainA.GetSimApp().ScopedIBCMockKeeper.GetCapability(suite.chainA.GetContext(), "mock_one")
suite.Require().True(found)
suite.Require().NotNil(cap)
suite.Require().NotNil(capability)

cap, found = suite.chainA.GetSimApp().ScopedIBCMockKeeper.GetCapability(suite.chainA.GetContext(), "mock_two")
capability, found = suite.chainA.GetSimApp().ScopedIBCMockKeeper.GetCapability(suite.chainA.GetContext(), "mock_two")
suite.Require().True(found)
suite.Require().NotNil(cap)
suite.Require().NotNil(capability)

isAuthenticated := suite.chainA.GetSimApp().ScopedICAMockKeeper.AuthenticateCapability(suite.chainA.GetContext(), cap, "mock_two")
isAuthenticated := suite.chainA.GetSimApp().ScopedICAMockKeeper.AuthenticateCapability(suite.chainA.GetContext(), capability, "mock_two")
suite.Require().True(isAuthenticated)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ func DefaultParams() Params {

// Validate validates all controller submodule parameters
func (p Params) Validate() error {
if err := validateEnabledType(p.ControllerEnabled); err != nil {
return err
}

return nil
return validateEnabledType(p.ControllerEnabled)
}

// ParamSetPairs implements params.ParamSet
Expand Down
18 changes: 3 additions & 15 deletions modules/apps/27-interchain-accounts/genesis/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ func (gs GenesisState) Validate() error {
return err
}

if err := gs.HostGenesisState.Validate(); err != nil {
return err
}

return nil
return gs.HostGenesisState.Validate()
}

// DefaultControllerGenesis creates and returns the default interchain accounts ControllerGenesisState
Expand Down Expand Up @@ -81,11 +77,7 @@ func (gs ControllerGenesisState) Validate() error {
}
}

if err := gs.Params.Validate(); err != nil {
return err
}

return nil
return gs.Params.Validate()
}

// DefaultHostGenesis creates and returns the default interchain accounts HostGenesisState
Expand Down Expand Up @@ -132,9 +124,5 @@ func (gs HostGenesisState) Validate() error {
return err
}

if err := gs.Params.Validate(); err != nil {
return err
}

return nil
return gs.Params.Validate()
}
6 changes: 1 addition & 5 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ func SetupICAPath(path *ibctesting.Path, owner string) error {
return err
}

if err := path.EndpointB.ChanOpenConfirm(); err != nil {
return err
}

return nil
return path.EndpointB.ChanOpenConfirm()
}

// Test initiating a ChanOpenInit using the host chain instead of the controller chain
Expand Down
6 changes: 6 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ import (

// InitGenesis initializes the interchain accounts host application state from a provided genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisState) {
<<<<<<< HEAD
if !keeper.IsBound(ctx, state.Port) {
cap := keeper.BindPort(ctx, state.Port)
if err := keeper.ClaimCapability(ctx, cap, host.PortPath(state.Port)); err != nil {
=======
if !keeper.HasCapability(ctx, state.Port) {
capability := keeper.BindPort(ctx, state.Port)
if err := keeper.ClaimCapability(ctx, capability, host.PortPath(state.Port)); err != nil {
>>>>>>> 5a67efc4 (chore: fix linter warnings (#3311))
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ func SetupICAPath(path *ibctesting.Path, owner string) error {
return err
}

if err := path.EndpointB.ChanOpenConfirm(); err != nil {
return err
}

return nil
return path.EndpointB.ChanOpenConfirm()
}

// RegisterInterchainAccount is a helper function for starting the channel handshake
Expand Down
6 changes: 1 addition & 5 deletions modules/apps/27-interchain-accounts/host/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ func (p Params) Validate() error {
return err
}

if err := validateAllowlist(p.AllowMessages); err != nil {
return err
}

return nil
return validateAllowlist(p.AllowMessages)
}

// ParamSetPairs implements params.ParamSet
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes
if am.hostKeeper != nil {
am.hostKeeper.SetParams(ctx, hostParams)

cap := am.hostKeeper.BindPort(ctx, types.HostPortID)
if err := am.hostKeeper.ClaimCapability(ctx, cap, ibchost.PortPath(types.HostPortID)); err != nil {
capability := am.hostKeeper.BindPort(ctx, types.HostPortID)
if err := am.hostKeeper.ClaimCapability(ctx, capability, ibchost.PortPath(types.HostPortID)); err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
}
}
Expand Down
12 changes: 2 additions & 10 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,7 @@ func (im IBCMiddleware) OnChanCloseInit(
return types.ErrFeeModuleLocked
}

if err := im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID); err != nil {
return err
}

return nil
return im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID)
}

// OnChanCloseConfirm implements the IBCMiddleware interface
Expand All @@ -205,11 +201,7 @@ func (im IBCMiddleware) OnChanCloseConfirm(
return types.ErrFeeModuleLocked
}

if err := im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID); err != nil {
return err
}

return nil
return im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID)
}

// OnRecvPacket implements the IBCMiddleware interface.
Expand Down
6 changes: 1 addition & 5 deletions modules/apps/29-fee/ica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ func SetupPath(path *ibctesting.Path, owner string) error {
return err
}

if err := path.EndpointB.ChanOpenConfirm(); err != nil {
return err
}

return nil
return path.EndpointB.ChanOpenConfirm()
}

// RegisterInterchainAccount invokes the the InterchainAccounts entrypoint, routes a new MsgChannelOpenInit to the appropriate handler,
Expand Down
6 changes: 1 addition & 5 deletions modules/apps/29-fee/types/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ func (p PacketFee) Validate() error {
return ErrRelayersNotEmpty
}

if err := p.Fee.Validate(); err != nil {
return err
}

return nil
return p.Fee.Validate()
}

// NewPacketFees creates and returns a new PacketFees struct including a list of type PacketFee
Expand Down
12 changes: 2 additions & 10 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ func (msg MsgPayPacketFee) ValidateBasic() error {
return ErrRelayersNotEmpty
}

if err := msg.Fee.Validate(); err != nil {
return err
}

return nil
return msg.Fee.Validate()
}

// GetSigners implements sdk.Msg
Expand Down Expand Up @@ -172,11 +168,7 @@ func (msg MsgPayPacketFeeAsync) ValidateBasic() error {
return err
}

if err := msg.PacketFee.Validate(); err != nil {
return err
}

return nil
return msg.PacketFee.Validate()
}

// GetSigners implements sdk.Msg
Expand Down
Loading

0 comments on commit 1245047

Please sign in to comment.