-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: account/keeper tests for ICA #420
Changes from 4 commits
670f139
a5ada7d
61eae32
4c27d87
4b63f25
c85b8c7
b2a61ec
d9d2392
af21f8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,15 +187,15 @@ 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @colin-axner updating chan closing capabilities |
||
} | ||
|
||
func (am AppModule) OnChanCloseConfirm( | ||
ctx sdk.Context, | ||
portID, | ||
channelID string, | ||
) error { | ||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") | ||
return nil | ||
} | ||
|
||
func (am AppModule) OnRecvPacket( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto, is this what the SDK does for accounts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. This code was grandfathered in from the previous work on ICA. I assumed up to now that the override here for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets revisit during the internal audit. I'm wondering how this will interact with module accounts (if we even need this type) |
||
} | ||
|
||
// 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") | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return ia.BaseAccount.Validate() | ||
} | ||
|
||
type ibcAccountPretty struct { | ||
type interchainAccountPretty struct { | ||
Address sdk.AccAddress `json:"address" yaml:"address"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Updated. |
||
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 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
package types_test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"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 +95,83 @@ 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") | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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", | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 := suite.chainA.SenderAccount.GetAddress() | ||
ba := authtypes.NewBaseAccountWithAddress(addr) | ||
|
||
interchainAcc := types.NewInterchainAccount(ba, suite.chainB.SenderAccount.GetAddress().String()) | ||
|
||
bs, err := yaml.Marshal(interchainAcc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to test the I think the function signature of From:
To:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated this. For some reason, I needed to use |
||
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)) | ||
} | ||
|
||
func (suite *TypesTestSuite) TestInterchainAccountJSON() { | ||
addr := suite.chainA.SenderAccount.GetAddress() | ||
ba := authtypes.NewBaseAccountWithAddress(addr) | ||
|
||
interchainAcc := types.NewInterchainAccount(ba, suite.chainB.SenderAccount.GetAddress().String()) | ||
|
||
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)) | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used anywhere. Some leftover code from the previous implementation I think.