From 670f1399725a6d653b14c581802f45b23e66c718 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 17 Sep 2021 12:57:52 +0200 Subject: [PATCH 1/7] test: adding tests for account type --- .../keeper/handshake.go | 20 ----- .../27-interchain-accounts/types/account.go | 19 ++-- .../types/account_test.go | 89 ++++++++++++++++++- 3 files changed, 99 insertions(+), 29 deletions(-) diff --git a/modules/apps/27-interchain-accounts/keeper/handshake.go b/modules/apps/27-interchain-accounts/keeper/handshake.go index e4677b72188..6900a6187be 100644 --- a/modules/apps/27-interchain-accounts/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/keeper/handshake.go @@ -112,23 +112,3 @@ func (k Keeper) OnChanOpenConfirm( ) error { return nil } - -// May want to use these for re-opening a channel when it is closed -//// OnChanCloseInit implements the IBCModule interface -//func (am AppModule) OnChanCloseInit( -// ctx sdk.Context, -// portID, -// channelID string, -//) error { -// // Disallow user-initiated channel closing for transfer channels -// return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") -//} - -//// OnChanCloseConfirm implements the IBCModule interface -//func (am AppModule) OnChanCloseConfirm( -// ctx sdk.Context, -// portID, -// channelID string, -//) error { -// return nil -//} diff --git a/modules/apps/27-interchain-accounts/types/account.go b/modules/apps/27-interchain-accounts/types/account.go index 93f8b18e9a4..af6ff281241 100644 --- a/modules/apps/27-interchain-accounts/types/account.go +++ b/modules/apps/27-interchain-accounts/types/account.go @@ -5,13 +5,12 @@ import ( "fmt" "strings" - yaml "gopkg.in/yaml.v2" - crypto "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/tendermint/tendermint/crypto/tmhash" + "gopkg.in/yaml.v2" connectiontypes "github.com/cosmos/ibc-go/modules/core/03-connection/types" ) @@ -66,20 +65,24 @@ func NewInterchainAccount(ba *authtypes.BaseAccount, accountOwner string) *Inter } // SetPubKey - Implements AccountI -func (InterchainAccount) SetPubKey(pubKey crypto.PubKey) error { +func (ia InterchainAccount) SetPubKey(pubKey crypto.PubKey) error { return fmt.Errorf("not supported for interchain accounts") } // SetSequence - Implements AccountI -func (InterchainAccount) SetSequence(seq uint64) error { +func (ia InterchainAccount) SetSequence(seq uint64) error { return fmt.Errorf("not supported for interchain accounts") } func (ia InterchainAccount) Validate() error { + if strings.TrimSpace(ia.AccountOwner) == "" { + return fmt.Errorf("AccountOwner cannot be empty") + } + return ia.BaseAccount.Validate() } -type ibcAccountPretty 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"` @@ -99,7 +102,7 @@ func (ia InterchainAccount) MarshalYAML() (interface{}, error) { return nil, err } - bs, err := yaml.Marshal(ibcAccountPretty{ + bs, err := yaml.Marshal(interchainAccountPretty{ Address: accAddr, PubKey: "", AccountNumber: ia.AccountNumber, @@ -121,7 +124,7 @@ func (ia InterchainAccount) MarshalJSON() ([]byte, error) { return nil, err } - return json.Marshal(ibcAccountPretty{ + return json.Marshal(interchainAccountPretty{ Address: accAddr, PubKey: "", AccountNumber: ia.AccountNumber, @@ -132,7 +135,7 @@ func (ia InterchainAccount) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals raw JSON bytes into a ModuleAccount. func (ia *InterchainAccount) UnmarshalJSON(bz []byte) error { - var alias ibcAccountPretty + 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 15bc23eb3e8..451aebaa5e8 100644 --- a/modules/apps/27-interchain-accounts/types/account_test.go +++ b/modules/apps/27-interchain-accounts/types/account_test.go @@ -1,12 +1,18 @@ package types_test import ( + "encoding/json" "testing" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + 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/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/testing" - "github.com/stretchr/testify/suite" ) type TypesTestSuite struct { @@ -88,3 +94,84 @@ func (suite *TypesTestSuite) TestGeneratePortID() { }) } } + +func (suite *TypesTestSuite) TestInterchainAccount() { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + baseAcc := authtypes.NewBaseAccountWithAddress(addr) + interchainAcc := types.NewInterchainAccount(baseAcc, "account-owner-id") + + // should fail when trying to set the public key or sequence of an interchain account + err := interchainAcc.SetPubKey(pubkey) + suite.Require().Error(err) + err = interchainAcc.SetSequence(1) + suite.Require().Error(err) +} + +func (suite *TypesTestSuite) TestGenesisAccountValidate() { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + baseAcc := authtypes.NewBaseAccountWithAddress(addr) + pubkey = secp256k1.GenPrivKey().PubKey() + ownerAddr := sdk.AccAddress(pubkey.Address()) + + testCases := []struct { + name string + acc authtypes.GenesisAccount + expPass bool + }{ + { + "interchain account with empty AccountOwner field", + types.NewInterchainAccount(baseAcc, ""), + false, + }, + { + "success", + types.NewInterchainAccount(baseAcc, ownerAddr.String()), + true, + }, + } + + for _, tc := range testCases { + err := tc.acc.Validate() + + if tc.expPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + } +} + +func (suite *TypesTestSuite) TestInterchainAccountMarshalYAML() { + suite.SetupTest() // reset + addr, err := sdk.AccAddressFromHex("0000000000000000000000000000000000000000") + suite.Require().NoError(err) + ba := authtypes.NewBaseAccountWithAddress(addr) + + interchainAcc := types.NewInterchainAccount(ba, "accountOwner") + + bs, err := yaml.Marshal(interchainAcc) + suite.Require().NoError(err) + + want := "|\n address: cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrql8a\n public_key: \"\"\n account_number: 0\n sequence: 0\n account_owner: accountOwner\n" + suite.Require().Equal(want, string(bs)) +} + +func (suite *TypesTestSuite) TestInterchainAccountJSON() { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + baseAcc := authtypes.NewBaseAccountWithAddress(addr) + + interchainAcc := types.NewInterchainAccount(baseAcc, "owner-address") + + bz, err := json.Marshal(interchainAcc) + suite.Require().NoError(err) + + bz1, err := interchainAcc.MarshalJSON() + suite.Require().NoError(err) + suite.Require().Equal(string(bz), string(bz1)) + + var a types.InterchainAccount + suite.Require().NoError(json.Unmarshal(bz, &a)) +} From a5ada7de35cce357c8ebdcb1d4e7fc91d26fe9ba Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 17 Sep 2021 13:37:00 +0200 Subject: [PATCH 2/7] tests: adding test for keeper & account --- .../apps/27-interchain-accounts/keeper/account.go | 13 ------------- .../27-interchain-accounts/keeper/account_test.go | 6 +++++- .../27-interchain-accounts/keeper/keeper_test.go | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/modules/apps/27-interchain-accounts/keeper/account.go b/modules/apps/27-interchain-accounts/keeper/account.go index 43e3bc4b143..52244d781cf 100644 --- a/modules/apps/27-interchain-accounts/keeper/account.go +++ b/modules/apps/27-interchain-accounts/keeper/account.go @@ -58,16 +58,3 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, portID string) { k.accountKeeper.SetAccount(ctx, interchainAccount) k.SetInterchainAccountAddress(ctx, portID, interchainAccount.Address) } - -func (k Keeper) GetInterchainAccount(ctx sdk.Context, addr sdk.AccAddress) (types.InterchainAccount, error) { - acc := k.accountKeeper.GetAccount(ctx, addr) - if acc == nil { - return types.InterchainAccount{}, sdkerrors.Wrap(types.ErrInterchainAccountNotFound, "there is no account") - } - - interchainAccount, ok := acc.(*types.InterchainAccount) - if !ok { - return types.InterchainAccount{}, sdkerrors.Wrap(types.ErrInterchainAccountNotFound, "account is not an interchain account") - } - return *interchainAccount, nil -} diff --git a/modules/apps/27-interchain-accounts/keeper/account_test.go b/modules/apps/27-interchain-accounts/keeper/account_test.go index 3d9cd9bae49..ee9276bbca6 100644 --- a/modules/apps/27-interchain-accounts/keeper/account_test.go +++ b/modules/apps/27-interchain-accounts/keeper/account_test.go @@ -17,7 +17,6 @@ func (suite *KeeperTestSuite) TestInitInterchainAccount() { malleate func() expPass bool }{ - { "success", func() {}, true, }, @@ -31,6 +30,11 @@ func (suite *KeeperTestSuite) TestInitInterchainAccount() { }, false, }, */ + { + "fails to generate port-id", func() { + owner = "" + }, false, + }, { "MsgChanOpenInit fails - channel is already active", func() { portID, err := types.GeneratePortID(owner, path.EndpointA.ConnectionID, path.EndpointB.ConnectionID) diff --git a/modules/apps/27-interchain-accounts/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/keeper/keeper_test.go index 7064d6ebc07..3d01c2efac6 100644 --- a/modules/apps/27-interchain-accounts/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/keeper/keeper_test.go @@ -119,6 +119,20 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { suite.Require().Empty(retrievedAddr) } +func (suite *KeeperTestSuite) TestIsActiveChannel() { + suite.SetupTest() // reset + path := NewICAPath(suite.chainA, suite.chainB) + owner := "owner" + suite.coordinator.SetupConnections(path) + + err := suite.SetupICAPath(path, owner) + suite.Require().NoError(err) + portID := path.EndpointA.ChannelConfig.PortID + + isActive := suite.chainA.GetSimApp().ICAKeeper.IsActiveChannel(suite.chainA.GetContext(), portID) + suite.Require().Equal(isActive, true) +} + func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() { expectedAddr, portID := "address", "port" suite.chainA.GetSimApp().ICAKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), portID, expectedAddr) From 61eae324093b1d9edba2878c9aa8182eb2bcd43e Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 17 Sep 2021 13:41:10 +0200 Subject: [PATCH 3/7] fix: updating channel closing capabilities --- modules/apps/27-interchain-accounts/module.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 740eea4ad6b..b9a86118db7 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -187,7 +187,7 @@ func (am AppModule) OnChanCloseInit( channelID string, ) error { // Disallow user-initiated channel closing for interchain account channels - return nil + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") } func (am AppModule) OnChanCloseConfirm( @@ -195,7 +195,7 @@ func (am AppModule) OnChanCloseConfirm( portID, channelID string, ) error { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") + return nil } func (am AppModule) OnRecvPacket( From 4c27d8742b22dd9bd9197ba34ee4e1dfe53c6456 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 17 Sep 2021 13:56:15 +0200 Subject: [PATCH 4/7] fix: updating to use test library instead of hardcoded values --- .../27-interchain-accounts/types/account_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/apps/27-interchain-accounts/types/account_test.go b/modules/apps/27-interchain-accounts/types/account_test.go index 451aebaa5e8..074fcf8c333 100644 --- a/modules/apps/27-interchain-accounts/types/account_test.go +++ b/modules/apps/27-interchain-accounts/types/account_test.go @@ -2,6 +2,7 @@ package types_test import ( "encoding/json" + "fmt" "testing" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -145,25 +146,24 @@ func (suite *TypesTestSuite) TestGenesisAccountValidate() { func (suite *TypesTestSuite) TestInterchainAccountMarshalYAML() { suite.SetupTest() // reset - addr, err := sdk.AccAddressFromHex("0000000000000000000000000000000000000000") - suite.Require().NoError(err) + + addr := suite.chainA.SenderAccount.GetAddress() ba := authtypes.NewBaseAccountWithAddress(addr) - interchainAcc := types.NewInterchainAccount(ba, "accountOwner") + interchainAcc := types.NewInterchainAccount(ba, suite.chainB.SenderAccount.GetAddress().String()) bs, err := yaml.Marshal(interchainAcc) suite.Require().NoError(err) - want := "|\n address: cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrql8a\n public_key: \"\"\n account_number: 0\n sequence: 0\n account_owner: accountOwner\n" + want := fmt.Sprintf("|\n address: %s\n public_key: \"\"\n account_number: 0\n sequence: 0\n account_owner: %s\n", addr, interchainAcc.AccountOwner) suite.Require().Equal(want, string(bs)) } func (suite *TypesTestSuite) TestInterchainAccountJSON() { - pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) - baseAcc := authtypes.NewBaseAccountWithAddress(addr) + addr := suite.chainA.SenderAccount.GetAddress() + ba := authtypes.NewBaseAccountWithAddress(addr) - interchainAcc := types.NewInterchainAccount(baseAcc, "owner-address") + interchainAcc := types.NewInterchainAccount(ba, suite.chainB.SenderAccount.GetAddress().String()) bz, err := json.Marshal(interchainAcc) suite.Require().NoError(err) From 4b63f25b2514dff1b8718ddd9c953784cc08e45d Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 22 Sep 2021 18:08:04 +0200 Subject: [PATCH 5/7] fix: updating error handling for account --- modules/apps/27-interchain-accounts/types/account.go | 6 +++--- .../apps/27-interchain-accounts/types/account_test.go | 10 +++++----- modules/apps/27-interchain-accounts/types/errors.go | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/apps/27-interchain-accounts/types/account.go b/modules/apps/27-interchain-accounts/types/account.go index af6ff281241..16492691eb1 100644 --- a/modules/apps/27-interchain-accounts/types/account.go +++ b/modules/apps/27-interchain-accounts/types/account.go @@ -66,17 +66,17 @@ func NewInterchainAccount(ba *authtypes.BaseAccount, accountOwner string) *Inter // SetPubKey - Implements AccountI func (ia InterchainAccount) SetPubKey(pubKey crypto.PubKey) error { - return fmt.Errorf("not supported for interchain accounts") + return sdkerrors.Wrap(ErrUnsupported, "cannot set public key for interchain account") } // SetSequence - Implements AccountI func (ia InterchainAccount) SetSequence(seq uint64) error { - return fmt.Errorf("not supported for interchain accounts") + return sdkerrors.Wrap(ErrUnsupported, "cannot set sequence number for interchain account") } func (ia InterchainAccount) Validate() error { if strings.TrimSpace(ia.AccountOwner) == "" { - return fmt.Errorf("AccountOwner cannot be empty") + return sdkerrors.Wrap(ErrInvalidOwnerAddress, "AccountOwner cannot be empty") } return ia.BaseAccount.Validate() diff --git a/modules/apps/27-interchain-accounts/types/account_test.go b/modules/apps/27-interchain-accounts/types/account_test.go index 074fcf8c333..3d1005ee2c1 100644 --- a/modules/apps/27-interchain-accounts/types/account_test.go +++ b/modules/apps/27-interchain-accounts/types/account_test.go @@ -121,16 +121,16 @@ func (suite *TypesTestSuite) TestGenesisAccountValidate() { acc authtypes.GenesisAccount expPass bool }{ - { - "interchain account with empty AccountOwner field", - types.NewInterchainAccount(baseAcc, ""), - false, - }, { "success", types.NewInterchainAccount(baseAcc, ownerAddr.String()), true, }, + { + "interchain account with empty AccountOwner field", + types.NewInterchainAccount(baseAcc, ""), + false, + }, } for _, tc := range testCases { diff --git a/modules/apps/27-interchain-accounts/types/errors.go b/modules/apps/27-interchain-accounts/types/errors.go index 32425a81071..4b79d032c8c 100644 --- a/modules/apps/27-interchain-accounts/types/errors.go +++ b/modules/apps/27-interchain-accounts/types/errors.go @@ -11,9 +11,10 @@ var ( ErrUnsupportedChain = sdkerrors.Register(ModuleName, 5, "unsupported chain") ErrInvalidOutgoingData = sdkerrors.Register(ModuleName, 6, "invalid outgoing data") ErrInvalidRoute = sdkerrors.Register(ModuleName, 7, "invalid route") - ErrInterchainAccountNotFound = sdkerrors.Register(ModuleName, 8, "Interchain Account not found") - ErrInterchainAccountAlreadySet = sdkerrors.Register(ModuleName, 9, "Interchain Account is already set") + ErrInterchainAccountNotFound = sdkerrors.Register(ModuleName, 8, "interchain Account not found") + ErrInterchainAccountAlreadySet = sdkerrors.Register(ModuleName, 9, "interchain Account is already set") ErrActiveChannelNotFound = sdkerrors.Register(ModuleName, 10, "no active channel for this owner") ErrInvalidVersion = sdkerrors.Register(ModuleName, 11, "invalid interchain accounts version") ErrInvalidOwnerAddress = sdkerrors.Register(ModuleName, 12, "invalid owner address") + ErrUnsupported = sdkerrors.Register(ModuleName, 13, "interchain account does not support this action") ) From c85b8c70685b0169c358c26a362555e7737ddf7f Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 22 Sep 2021 18:20:42 +0200 Subject: [PATCH 6/7] test: adding test for account string comparison --- modules/apps/27-interchain-accounts/types/account.go | 2 +- modules/apps/27-interchain-accounts/types/account_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/types/account.go b/modules/apps/27-interchain-accounts/types/account.go index 16492691eb1..1f1b675ce0c 100644 --- a/modules/apps/27-interchain-accounts/types/account.go +++ b/modules/apps/27-interchain-accounts/types/account.go @@ -87,7 +87,7 @@ type interchainAccountPretty struct { PubKey string `json:"public_key" yaml:"public_key"` AccountNumber uint64 `json:"account_number" yaml:"account_number"` Sequence uint64 `json:"sequence" yaml:"sequence"` - AccountOwner string `json:"address" yaml:"account_owner"` + AccountOwner string `json:"account_owner" yaml:"account_owner"` } func (ia InterchainAccount) String() string { diff --git a/modules/apps/27-interchain-accounts/types/account_test.go b/modules/apps/27-interchain-accounts/types/account_test.go index 3d1005ee2c1..720d862a747 100644 --- a/modules/apps/27-interchain-accounts/types/account_test.go +++ b/modules/apps/27-interchain-accounts/types/account_test.go @@ -174,4 +174,5 @@ func (suite *TypesTestSuite) TestInterchainAccountJSON() { var a types.InterchainAccount suite.Require().NoError(json.Unmarshal(bz, &a)) + suite.Require().Equal(interchainAcc.String(), a.String()) } From d9d2392a85a9c2e045f1124cee158bc73ee55d22 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 22 Sep 2021 19:17:32 +0200 Subject: [PATCH 7/7] fix: updating marshal yaml --- .../27-interchain-accounts/types/account.go | 24 ++++++++++++------- .../types/account_test.go | 19 ++++++++------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/modules/apps/27-interchain-accounts/types/account.go b/modules/apps/27-interchain-accounts/types/account.go index 29972004cdb..e737e0233bd 100644 --- a/modules/apps/27-interchain-accounts/types/account.go +++ b/modules/apps/27-interchain-accounts/types/account.go @@ -87,7 +87,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"` @@ -97,17 +97,17 @@ type interchainAccountPretty struct { func (ia InterchainAccount) String() string { out, _ := ia.MarshalYAML() - return out.(string) + return string(out) } -// MarshalYAML returns the YAML representation of a InterchainAccount. -func (ia InterchainAccount) MarshalYAML() (interface{}, error) { +// MarshalYAML returns the YAML representation of an InterchainAccount +func (ia InterchainAccount) MarshalYAML() ([]byte, error) { accAddr, err := sdk.AccAddressFromBech32(ia.Address) if err != nil { return nil, err } - bs, err := yaml.Marshal(interchainAccountPretty{ + bz, err := yaml.Marshal(InterchainAccountPretty{ Address: accAddr, PubKey: "", AccountNumber: ia.AccountNumber, @@ -119,28 +119,34 @@ func (ia InterchainAccount) MarshalYAML() (interface{}, error) { return nil, err } - return string(bs), nil + return bz, nil } -// MarshalJSON returns the JSON representation of a InterchainAccount. +// MarshalJSON returns the JSON representation of an InterchainAccount. func (ia InterchainAccount) MarshalJSON() ([]byte, error) { accAddr, err := sdk.AccAddressFromBech32(ia.Address) if err != nil { return nil, err } - return json.Marshal(interchainAccountPretty{ + bz, err := json.Marshal(InterchainAccountPretty{ Address: accAddr, PubKey: "", AccountNumber: ia.AccountNumber, Sequence: ia.Sequence, AccountOwner: ia.AccountOwner, }) + + if err != nil { + return nil, err + } + + return bz, nil } // 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 00d01999ab6..c6638b7778f 100644 --- a/modules/apps/27-interchain-accounts/types/account_test.go +++ b/modules/apps/27-interchain-accounts/types/account_test.go @@ -126,7 +126,7 @@ func (suite *TypesTestSuite) TestInterchainAccount() { pubkey := secp256k1.GenPrivKey().PubKey() addr := sdk.AccAddress(pubkey.Address()) baseAcc := authtypes.NewBaseAccountWithAddress(addr) - interchainAcc := types.NewInterchainAccount(baseAcc, "account-owner-id") + interchainAcc := types.NewInterchainAccount(baseAcc, TestOwnerAddress) // should fail when trying to set the public key or sequence of an interchain account err := interchainAcc.SetPubKey(pubkey) @@ -171,18 +171,21 @@ func (suite *TypesTestSuite) TestGenesisAccountValidate() { } func (suite *TypesTestSuite) TestInterchainAccountMarshalYAML() { - suite.SetupTest() // reset - addr := suite.chainA.SenderAccount.GetAddress() ba := authtypes.NewBaseAccountWithAddress(addr) interchainAcc := types.NewInterchainAccount(ba, suite.chainB.SenderAccount.GetAddress().String()) - - bs, err := yaml.Marshal(interchainAcc) + bz, err := yaml.Marshal(types.InterchainAccountPretty{ + Address: addr, + PubKey: "", + AccountNumber: interchainAcc.AccountNumber, + Sequence: interchainAcc.Sequence, + AccountOwner: interchainAcc.AccountOwner, + }) suite.Require().NoError(err) - want := fmt.Sprintf("|\n address: %s\n public_key: \"\"\n account_number: 0\n sequence: 0\n account_owner: %s\n", addr, interchainAcc.AccountOwner) - suite.Require().Equal(want, string(bs)) + bz1, err := interchainAcc.MarshalYAML() + suite.Require().Equal(string(bz), string(bz1)) } func (suite *TypesTestSuite) TestInterchainAccountJSON() { @@ -200,5 +203,5 @@ func (suite *TypesTestSuite) TestInterchainAccountJSON() { var a types.InterchainAccount suite.Require().NoError(json.Unmarshal(bz, &a)) - suite.Require().Equal(interchainAcc.String(), a.String()) + suite.Require().Equal(a.String(), interchainAcc.String()) }