Skip to content

Commit

Permalink
Rename imports within host/controller (#571)
Browse files Browse the repository at this point in the history
* alias ica types import to  for host submodule

* alias ica types import to  for controller submodule
  • Loading branch information
colin-axner committed Nov 30, 2021
1 parent 5bed1d7 commit e6a5583
Show file tree
Hide file tree
Showing 24 changed files with 243 additions and 243 deletions.
8 changes: 4 additions & 4 deletions modules/apps/27-interchain-accounts/controller/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v2/modules/core/exported"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (im IBCModule) OnChanOpenTry(
version,
counterpartyVersion string,
) error {
return sdkerrors.Wrap(types.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain")
return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain")
}

// OnChanOpenAck implements the IBCModule interface
Expand Down Expand Up @@ -92,7 +92,7 @@ func (im IBCModule) OnChanOpenConfirm(
portID,
channelID string,
) error {
return sdkerrors.Wrap(types.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain")
return sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain")
}

// OnChanCloseInit implements the IBCModule interface
Expand Down Expand Up @@ -156,5 +156,5 @@ func (im IBCModule) NegotiateAppVersion(
counterparty channeltypes.Counterparty,
proposedVersion string,
) (string, error) {
return "", sdkerrors.Wrap(types.ErrInvalidChannelFlow, "ICS-27 app version negotiation is unsupported on controller chains")
return "", sdkerrors.Wrap(icatypes.ErrInvalidChannelFlow, "ICS-27 app version negotiation is unsupported on controller chains")
}
30 changes: 15 additions & 15 deletions modules/apps/27-interchain-accounts/controller/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
clienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v2/modules/core/24-host"
Expand All @@ -19,13 +19,13 @@ import (
var (
// TestAccAddress defines a resuable bech32 address for testing purposes
// TODO: update crypto.AddressHash() when sdk uses address.Module()
TestAccAddress = types.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(types.ModuleName))), TestPortID)
TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), TestPortID)
// TestOwnerAddress defines a reusable bech32 address for testing purposes
TestOwnerAddress = "cosmos17dtl0mjt3t77kpuhg2edqzjpszulwhgzuj9ljs"
// TestPortID defines a resuable port identifier for testing purposes
TestPortID, _ = types.GeneratePortID(TestOwnerAddress, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
TestPortID, _ = icatypes.GeneratePortID(TestOwnerAddress, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
// TestVersion defines a resuable interchainaccounts version string for testing purposes
TestVersion = types.NewAppVersion(types.VersionPrefix, TestAccAddress.String())
TestVersion = icatypes.NewAppVersion(icatypes.VersionPrefix, TestAccAddress.String())
)

type InterchainAccountsTestSuite struct {
Expand All @@ -50,18 +50,18 @@ func (suite *InterchainAccountsTestSuite) SetupTest() {

func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
path := ibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig.PortID = types.PortID
path.EndpointB.ChannelConfig.PortID = types.PortID
path.EndpointA.ChannelConfig.PortID = icatypes.PortID
path.EndpointB.ChannelConfig.PortID = icatypes.PortID
path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED
path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED
path.EndpointA.ChannelConfig.Version = types.VersionPrefix
path.EndpointA.ChannelConfig.Version = icatypes.VersionPrefix
path.EndpointB.ChannelConfig.Version = TestVersion

return path
}

func InitInterchainAccount(endpoint *ibctesting.Endpoint, owner string) error {
portID, err := types.GeneratePortID(owner, endpoint.ConnectionID, endpoint.Counterparty.ConnectionID)
portID, err := icatypes.GeneratePortID(owner, endpoint.ConnectionID, endpoint.Counterparty.ConnectionID)
if err != nil {
return err
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
suite.coordinator.SetupConnections(path)

// mock init interchain account
portID, err := types.GeneratePortID(TestOwnerAddress, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
portID, err := icatypes.GeneratePortID(TestOwnerAddress, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
suite.Require().NoError(err)

portCap := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), portID)
Expand All @@ -160,7 +160,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
Ordering: channeltypes.ORDERED,
Counterparty: counterparty,
ConnectionHops: []string{path.EndpointA.ConnectionID},
Version: types.VersionPrefix,
Version: icatypes.VersionPrefix,
}

tc.malleate() // malleate mutates test data
Expand Down Expand Up @@ -213,7 +213,7 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenTry() {
proofInit, proofHeight := path.EndpointB.Chain.QueryProof(channelKey)

// use chainA (controller) for ChanOpenTry
msg := channeltypes.NewMsgChannelOpenTry(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, TestVersion, channeltypes.ORDERED, []string{path.EndpointA.ConnectionID}, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, types.VersionPrefix, proofInit, proofHeight, types.ModuleName)
msg := channeltypes.NewMsgChannelOpenTry(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, TestVersion, channeltypes.ORDERED, []string{path.EndpointA.ConnectionID}, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, icatypes.VersionPrefix, proofInit, proofHeight, icatypes.ModuleName)
handler := suite.chainA.GetSimApp().MsgServiceRouter().Handler(msg)
_, err = handler(suite.chainA.GetContext(), msg)

Expand Down Expand Up @@ -334,7 +334,7 @@ func (suite *InterchainAccountsTestSuite) TestChanOpenConfirm() {
proofAck, proofHeight := path.EndpointB.Chain.QueryProof(channelKey)

// use chainA (controller) for ChanOpenConfirm
msg := channeltypes.NewMsgChannelOpenConfirm(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, proofAck, proofHeight, types.ModuleName)
msg := channeltypes.NewMsgChannelOpenConfirm(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, proofAck, proofHeight, icatypes.ModuleName)
handler := suite.chainA.GetSimApp().MsgServiceRouter().Handler(msg)
_, err = handler(suite.chainA.GetContext(), msg)

Expand Down Expand Up @@ -505,22 +505,22 @@ func (suite *InterchainAccountsTestSuite) TestNegotiateAppVersion() {
cbs, ok := suite.chainA.GetSimApp().GetIBCKeeper().Router.GetRoute(module)
suite.Require().True(ok)

counterpartyPortID, err := types.GeneratePortID(TestOwnerAddress, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
counterpartyPortID, err := icatypes.GeneratePortID(TestOwnerAddress, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
suite.Require().NoError(err)

counterparty := channeltypes.Counterparty{
PortId: counterpartyPortID,
ChannelId: path.EndpointB.ChannelID,
}

proposedVersion = types.VersionPrefix
proposedVersion = icatypes.VersionPrefix

tc.malleate()

version, err := cbs.NegotiateAppVersion(suite.chainA.GetContext(), channeltypes.ORDERED, path.EndpointA.ConnectionID, path.EndpointA.ChannelConfig.PortID, counterparty, proposedVersion)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NoError(types.ValidateVersion(version))
suite.Require().NoError(icatypes.ValidateVersion(version))
suite.Require().Equal(TestVersion, version)
} else {
suite.Require().Error(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v2/modules/core/24-host"
)
Expand All @@ -16,21 +16,21 @@ import (
// already in use. Gaining access to interchain accounts whose channels have closed
// cannot be done with this function. A regular MsgChanOpenInit must be used.
func (k Keeper) InitInterchainAccount(ctx sdk.Context, connectionID, counterpartyConnectionID, owner string) error {
portID, err := types.GeneratePortID(owner, connectionID, counterpartyConnectionID)
portID, err := icatypes.GeneratePortID(owner, connectionID, counterpartyConnectionID)
if err != nil {
return err
}

if k.portKeeper.IsBound(ctx, portID) {
return sdkerrors.Wrap(types.ErrPortAlreadyBound, portID)
return sdkerrors.Wrap(icatypes.ErrPortAlreadyBound, portID)
}

cap := k.BindPort(ctx, portID)
if err := k.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil {
return sdkerrors.Wrap(err, "unable to bind to newly generated portID")
}

msg := channeltypes.NewMsgChannelOpenInit(portID, types.VersionPrefix, channeltypes.ORDERED, []string{connectionID}, types.PortID, types.ModuleName)
msg := channeltypes.NewMsgChannelOpenInit(portID, icatypes.VersionPrefix, channeltypes.ORDERED, []string{connectionID}, icatypes.PortID, icatypes.ModuleName)
handler := k.msgRouter.Handler(msg)
if _, err := handler(ctx, msg); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper_test

import (
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
ibctesting "github.com/cosmos/ibc-go/v2/testing"
)

Expand Down Expand Up @@ -37,7 +37,7 @@ func (suite *KeeperTestSuite) TestInitInterchainAccount() {
{
"MsgChanOpenInit fails - channel is already active",
func() {
portID, err := types.GeneratePortID(owner, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
portID, err := icatypes.GeneratePortID(owner, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
suite.Require().NoError(err)

suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
host "github.com/cosmos/ibc-go/v2/modules/core/24-host"
)

// InitGenesis initializes the interchain accounts controller application state from a provided genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, state types.ControllerGenesisState) {
func InitGenesis(ctx sdk.Context, keeper Keeper, state icatypes.ControllerGenesisState) {
for _, portID := range state.Ports {
if !keeper.IsBound(ctx, portID) {
cap := keeper.BindPort(ctx, portID)
Expand All @@ -30,8 +30,8 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state types.ControllerGenesisSt
}

// ExportGenesis returns the interchain accounts controller exported genesis
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.ControllerGenesisState {
return types.NewControllerGenesisState(
func ExportGenesis(ctx sdk.Context, keeper Keeper) icatypes.ControllerGenesisState {
return icatypes.NewControllerGenesisState(
keeper.GetAllActiveChannels(ctx),
keeper.GetAllInterchainAccounts(ctx),
keeper.GetAllPorts(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package keeper_test

import (
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
ibctesting "github.com/cosmos/ibc-go/v2/testing"
)

func (suite *KeeperTestSuite) TestInitGenesis() {
suite.SetupTest()

genesisState := types.ControllerGenesisState{
ActiveChannels: []types.ActiveChannel{
genesisState := icatypes.ControllerGenesisState{
ActiveChannels: []icatypes.ActiveChannel{
{
PortId: TestPortID,
ChannelId: ibctesting.FirstChannelID,
},
},
InterchainAccounts: []types.RegisteredInterchainAccount{
InterchainAccounts: []icatypes.RegisteredInterchainAccount{
{
PortId: TestPortID,
AccountAddress: TestAccAddress.String(),
Expand Down
28 changes: 14 additions & 14 deletions modules/apps/27-interchain-accounts/controller/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
connectiontypes "github.com/cosmos/ibc-go/v2/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
Expand All @@ -32,26 +32,26 @@ func (k Keeper) OnChanOpenInit(
return sdkerrors.Wrapf(channeltypes.ErrInvalidChannelOrdering, "expected %s channel, got %s", channeltypes.ORDERED, order)
}

connSequence, err := types.ParseControllerConnSequence(portID)
connSequence, err := icatypes.ParseControllerConnSequence(portID)
if err != nil {
return sdkerrors.Wrapf(err, "expected format %s, got %s", types.ControllerPortFormat, portID)
return sdkerrors.Wrapf(err, "expected format %s, got %s", icatypes.ControllerPortFormat, portID)
}

counterpartyConnSequence, err := types.ParseHostConnSequence(portID)
counterpartyConnSequence, err := icatypes.ParseHostConnSequence(portID)
if err != nil {
return sdkerrors.Wrapf(err, "expected format %s, got %s", types.ControllerPortFormat, portID)
return sdkerrors.Wrapf(err, "expected format %s, got %s", icatypes.ControllerPortFormat, portID)
}

if err := k.validateControllerPortParams(ctx, channelID, portID, connSequence, counterpartyConnSequence); err != nil {
return sdkerrors.Wrapf(err, "failed to validate controller port %s", portID)
}

if counterparty.PortId != types.PortID {
return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "expected %s, got %s", types.PortID, counterparty.PortId)
if counterparty.PortId != icatypes.PortID {
return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "expected %s, got %s", icatypes.PortID, counterparty.PortId)
}

if version != types.VersionPrefix {
return sdkerrors.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.VersionPrefix, version)
if version != icatypes.VersionPrefix {
return sdkerrors.Wrapf(icatypes.ErrInvalidVersion, "expected %s, got %s", icatypes.VersionPrefix, version)
}

activeChannelID, found := k.GetActiveChannelID(ctx, portID)
Expand All @@ -70,19 +70,19 @@ func (k Keeper) OnChanOpenAck(
channelID string,
counterpartyVersion string,
) error {
if portID == types.PortID {
return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "portID cannot be host chain port ID: %s", types.PortID)
if portID == icatypes.PortID {
return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "portID cannot be host chain port ID: %s", icatypes.PortID)
}

if err := types.ValidateVersion(counterpartyVersion); err != nil {
if err := icatypes.ValidateVersion(counterpartyVersion); err != nil {
return sdkerrors.Wrap(err, "counterparty version validation failed")
}

k.SetActiveChannelID(ctx, portID, channelID)

accAddr, err := types.ParseAddressFromVersion(counterpartyVersion)
accAddr, err := icatypes.ParseAddressFromVersion(counterpartyVersion)
if err != nil {
return sdkerrors.Wrapf(err, "expected format <app-version%saccount-address>, got %s", types.Delimiter, counterpartyVersion)
return sdkerrors.Wrapf(err, "expected format <app-version%saccount-address>, got %s", icatypes.Delimiter, counterpartyVersion)
}

k.SetInterchainAccountAddress(ctx, portID, accAddr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper_test
import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibctesting "github.com/cosmos/ibc-go/v2/testing"
Expand Down Expand Up @@ -77,7 +77,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
{
"invalid connection sequence",
func() {
portID, err := types.GeneratePortID(TestOwnerAddress, "connection-1", "connection-0")
portID, err := icatypes.GeneratePortID(TestOwnerAddress, "connection-1", "connection-0")
suite.Require().NoError(err)

path.EndpointA.ChannelConfig.PortID = portID
Expand All @@ -88,7 +88,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
{
"invalid counterparty connection sequence",
func() {
portID, err := types.GeneratePortID(TestOwnerAddress, "connection-0", "connection-1")
portID, err := icatypes.GeneratePortID(TestOwnerAddress, "connection-0", "connection-1")
suite.Require().NoError(err)

path.EndpointA.ChannelConfig.PortID = portID
Expand All @@ -115,7 +115,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
suite.coordinator.SetupConnections(path)

// mock init interchain account
portID, err := types.GeneratePortID(TestOwnerAddress, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
portID, err := icatypes.GeneratePortID(TestOwnerAddress, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID)
suite.Require().NoError(err)

portCap := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), portID)
Expand All @@ -129,7 +129,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
Ordering: channeltypes.ORDERED,
Counterparty: counterparty,
ConnectionHops: []string{path.EndpointA.ConnectionID},
Version: types.VersionPrefix,
Version: icatypes.VersionPrefix,
}

chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID))
Expand Down Expand Up @@ -176,7 +176,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenAck() {
},
{
"invalid portID", func() {
path.EndpointA.ChannelConfig.PortID = types.PortID
path.EndpointA.ChannelConfig.PortID = icatypes.PortID
expectedChannelID = ""
}, false,
},
Expand Down
Loading

0 comments on commit e6a5583

Please sign in to comment.