Skip to content

Commit

Permalink
additional code cov and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Sep 24, 2021
1 parent df1aa03 commit f9b58a8
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 59 deletions.
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/keeper/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
29 changes: 15 additions & 14 deletions modules/apps/27-interchain-accounts/keeper/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
8 changes: 4 additions & 4 deletions modules/apps/27-interchain-accounts/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
}
Expand Down
36 changes: 18 additions & 18 deletions modules/apps/27-interchain-accounts/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/27-interchain-accounts/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions modules/apps/27-interchain-accounts/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
15 changes: 8 additions & 7 deletions modules/apps/27-interchain-accounts/types/keys_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
7 changes: 0 additions & 7 deletions modules/apps/27-interchain-accounts/types/querier.go

This file was deleted.

0 comments on commit f9b58a8

Please sign in to comment.