diff --git a/modules/apps/27-interchain-accounts/keeper/account.go b/modules/apps/27-interchain-accounts/keeper/account.go index d66c15ddab9..f10bd73e005 100644 --- a/modules/apps/27-interchain-accounts/keeper/account.go +++ b/modules/apps/27-interchain-accounts/keeper/account.go @@ -22,7 +22,7 @@ func (k Keeper) InitInterchainAccount(ctx sdk.Context, connectionID, counterpart return err } - if k.IsBound(ctx, portID) { + if k.portKeeper.IsBound(ctx, portID) { return sdkerrors.Wrap(types.ErrPortAlreadyBound, portID) } diff --git a/modules/apps/27-interchain-accounts/keeper/account_test.go b/modules/apps/27-interchain-accounts/keeper/account_test.go index 87630e29d91..3d5a1bb31af 100644 --- a/modules/apps/27-interchain-accounts/keeper/account_test.go +++ b/modules/apps/27-interchain-accounts/keeper/account_test.go @@ -20,27 +20,28 @@ func (suite *KeeperTestSuite) TestInitInterchainAccount() { { "success", func() {}, true, }, - /* - // TODO: https://github.com/cosmos/ibc-go/issues/288 - { - "port is already bound", func() { - // mock init interchain account - portID := suite.chainA.GetSimApp().ICAKeeper.GeneratePortId(owner, path.EndpointA.ConnectionID) - suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), portID) - }, false, - }, - */ { - "fails to generate port-id", func() { + "port is already bound", + func() { + suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID) + }, + false, + }, + { + "fails to generate port-id", + func() { owner = "" - }, false, + }, + false, }, { - "MsgChanOpenInit fails - channel is already active", func() { + "MsgChanOpenInit fails - channel is already active", + func() { portID, err := types.GeneratePortID(owner, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) suite.Require().NoError(err) suite.chainA.GetSimApp().ICAKeeper.SetActiveChannel(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID) - }, false, + }, + false, }, } diff --git a/modules/apps/27-interchain-accounts/types/account.go b/modules/apps/27-interchain-accounts/types/account.go index f664bc1186d..a9f1fdcde1a 100644 --- a/modules/apps/27-interchain-accounts/types/account.go +++ b/modules/apps/27-interchain-accounts/types/account.go @@ -84,7 +84,7 @@ func (ia InterchainAccount) Validate() error { return ia.BaseAccount.Validate() } -type InterchainAccountPretty struct { +type interchainAccountPretty struct { Address sdk.AccAddress `json:"address" yaml:"address"` PubKey string `json:"public_key" yaml:"public_key"` AccountNumber uint64 `json:"account_number" yaml:"account_number"` @@ -104,7 +104,7 @@ func (ia InterchainAccount) MarshalYAML() ([]byte, error) { return nil, err } - bz, err := yaml.Marshal(InterchainAccountPretty{ + bz, err := yaml.Marshal(interchainAccountPretty{ Address: accAddr, PubKey: "", AccountNumber: ia.AccountNumber, @@ -126,7 +126,7 @@ func (ia InterchainAccount) MarshalJSON() ([]byte, error) { return nil, err } - bz, err := json.Marshal(InterchainAccountPretty{ + bz, err := json.Marshal(interchainAccountPretty{ Address: accAddr, PubKey: "", AccountNumber: ia.AccountNumber, @@ -143,7 +143,7 @@ func (ia InterchainAccount) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals raw JSON bytes into a ModuleAccount. func (ia *InterchainAccount) UnmarshalJSON(bz []byte) error { - var alias InterchainAccountPretty + var alias interchainAccountPretty if err := json.Unmarshal(bz, &alias); err != nil { return err } diff --git a/modules/apps/27-interchain-accounts/types/account_test.go b/modules/apps/27-interchain-accounts/types/account_test.go index 644121a6652..acca53e39c4 100644 --- a/modules/apps/27-interchain-accounts/types/account_test.go +++ b/modules/apps/27-interchain-accounts/types/account_test.go @@ -9,7 +9,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/stretchr/testify/suite" - "gopkg.in/yaml.v2" "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" ibctesting "github.com/cosmos/ibc-go/v2/testing" @@ -48,6 +47,13 @@ func (suite *TypesTestSuite) TestGenerateAddress() { suite.Require().NotEmpty(accAddr) } +func (suite *TypesTestSuite) TestParseAddressFromVersion() { + version := types.NewAppVersion(types.VersionPrefix, TestOwnerAddress) + + addr := types.ParseAddressFromVersion(version) + suite.Require().Equal(TestOwnerAddress, addr) +} + func (suite *TypesTestSuite) TestGeneratePortID() { var ( path *ibctesting.Path @@ -75,25 +81,25 @@ func (suite *TypesTestSuite) TestGeneratePortID() { true, }, { - "invalid owner address", + "invalid connectionID", func() { - owner = " " + path.EndpointA.ConnectionID = "connection" }, "", false, }, { - "invalid connectionID", + "invalid counterparty connectionID", func() { - path.EndpointA.ConnectionID = "connection" + path.EndpointB.ConnectionID = "connection" }, "", false, }, { - "invalid counterparty connectionID", + "invalid owner address", func() { - path.EndpointB.ConnectionID = "connection" + owner = " " }, "", false, @@ -172,20 +178,14 @@ func (suite *TypesTestSuite) TestGenesisAccountValidate() { func (suite *TypesTestSuite) TestInterchainAccountMarshalYAML() { addr := suite.chainA.SenderAccount.GetAddress() - ba := authtypes.NewBaseAccountWithAddress(addr) + baseAcc := authtypes.NewBaseAccountWithAddress(addr) - interchainAcc := types.NewInterchainAccount(ba, suite.chainB.SenderAccount.GetAddress().String()) - bz, err := yaml.Marshal(types.InterchainAccountPretty{ - Address: addr, - PubKey: "", - AccountNumber: interchainAcc.AccountNumber, - Sequence: interchainAcc.Sequence, - AccountOwner: interchainAcc.AccountOwner, - }) + interchainAcc := types.NewInterchainAccount(baseAcc, suite.chainB.SenderAccount.GetAddress().String()) + bz, err := interchainAcc.MarshalYAML() suite.Require().NoError(err) - bz1, err := interchainAcc.MarshalYAML() - suite.Require().Equal(string(bz), string(bz1)) + expected := fmt.Sprintf("address: %s\npublic_key: \"\"\naccount_number: 0\nsequence: 0\naccount_owner: %s\n", suite.chainA.SenderAccount.GetAddress(), suite.chainB.SenderAccount.GetAddress()) + suite.Require().Equal(expected, string(bz)) } func (suite *TypesTestSuite) TestInterchainAccountJSON() { diff --git a/modules/apps/27-interchain-accounts/types/codec.go b/modules/apps/27-interchain-accounts/types/codec.go index c46946deaa2..bfa8cde043c 100644 --- a/modules/apps/27-interchain-accounts/types/codec.go +++ b/modules/apps/27-interchain-accounts/types/codec.go @@ -6,6 +6,10 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) +var ( + ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) +) + // RegisterLegacyAminoCodec registers the account interfaces and concrete types on the // provided LegacyAmino codec. These types are used for Amino JSON serialization func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { @@ -18,7 +22,3 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations((*authtypes.AccountI)(nil), &InterchainAccount{}) } - -var ( - ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) -) diff --git a/modules/apps/27-interchain-accounts/types/expected_keepers.go b/modules/apps/27-interchain-accounts/types/expected_keepers.go index add14e17b0b..8b355e504a0 100644 --- a/modules/apps/27-interchain-accounts/types/expected_keepers.go +++ b/modules/apps/27-interchain-accounts/types/expected_keepers.go @@ -46,5 +46,6 @@ type ConnectionKeeper interface { // PortKeeper defines the expected IBC port keeper type PortKeeper interface { BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability + IsBound(ctx sdk.Context, portID string) bool LookupModuleByPort(ctx sdk.Context, portID string) (string, *capabilitytypes.Capability, error) } diff --git a/modules/apps/27-interchain-accounts/types/keys.go b/modules/apps/27-interchain-accounts/types/keys.go index 51841d0de0b..8640226191f 100644 --- a/modules/apps/27-interchain-accounts/types/keys.go +++ b/modules/apps/27-interchain-accounts/types/keys.go @@ -38,11 +38,11 @@ func NewAppVersion(versionPrefix, accAddr string) string { } // KeyActiveChannel creates and returns a new key used for active channels store operations -func KeyActiveChannel(portId string) []byte { - return []byte(fmt.Sprintf("activeChannel/%s", portId)) +func KeyActiveChannel(portID string) []byte { + return []byte(fmt.Sprintf("activeChannel/%s", portID)) } // KeyOwnerAccount creates and returns a new key used for owner account store operations -func KeyOwnerAccount(portId string) []byte { - return []byte(fmt.Sprintf("owner/%s", portId)) +func KeyOwnerAccount(portID string) []byte { + return []byte(fmt.Sprintf("owner/%s", portID)) } diff --git a/modules/apps/27-interchain-accounts/types/keys_test.go b/modules/apps/27-interchain-accounts/types/keys_test.go index 43db0bf8a13..037061a3d3e 100644 --- a/modules/apps/27-interchain-accounts/types/keys_test.go +++ b/modules/apps/27-interchain-accounts/types/keys_test.go @@ -1,14 +1,15 @@ package types_test import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" ) -func TestKeyActiveChannel(t *testing.T) { - key := types.KeyActiveChannel("owner") - require.Equal(t, string(key), "activeChannel/owner") +func (suite *TypesTestSuite) TestKeyActiveChannel() { + key := types.KeyActiveChannel("port-id") + suite.Require().Equal("activeChannel/port-id", string(key)) +} + +func (suite *TypesTestSuite) TestKeyOwnerAccount() { + key := types.KeyOwnerAccount("port-id") + suite.Require().Equal("owner/port-id", string(key)) } diff --git a/modules/apps/27-interchain-accounts/types/querier.go b/modules/apps/27-interchain-accounts/types/querier.go deleted file mode 100644 index 34faaba304b..00000000000 --- a/modules/apps/27-interchain-accounts/types/querier.go +++ /dev/null @@ -1,7 +0,0 @@ -package types - -// query endpoints supported by the auth Querier -const ( - QueryIBCAccount = "ibcaccount" - QueryIBCAccountFromData = "ibcaccount-from-data" -)