Skip to content
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

ICA: Adding tests for relay.go #337

Merged
merged 6 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenConfirm() {

tc.malleate() // explicitly change fields in channel and testChannel

err = suite.chainB.GetSimApp().ICAKeeper.OnChanOpenConfirm(suite.chainA.GetContext(),
err = suite.chainB.GetSimApp().ICAKeeper.OnChanOpenConfirm(suite.chainB.GetContext(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random fix

path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

if tc.expPass {
Expand Down
21 changes: 21 additions & 0 deletions modules/apps/27-interchain-accounts/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,24 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() {
suite.Require().True(found)
suite.Require().Equal(expectedAddr, retrievedAddr)
}

func (suite *KeeperTestSuite) SetupICAPath(path *ibctesting.Path, owner string) error {
if err := InitInterchainAccount(path.EndpointA, owner); err != nil {
return err
}

if err := path.EndpointB.ChanOpenTry(); err != nil {
return err
}

if err := path.EndpointA.ChanOpenAck(); err != nil {
return err
}

if err := suite.chainB.GetSimApp().ICAKeeper.OnChanOpenConfirm(suite.chainA.GetContext(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.EndpointA.ChanOpenConfirm() didn't seem to work here for me. I needed to use simApp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.EndpointA.ChanOpenConfirm() didn't seem to work here for me. I needed to use simApp

It was a bug on my part (and a good sign it didn't work). It should be:

path.EndpointB.ChanOpenConfirm()

not

path.EndpointA.ChanOpenConfirm()

A -> B

Would be good to switch back since you are using the Keeper on chainB and the context on chainA

path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID); err != nil {
return err
}

return nil
}
1 change: 0 additions & 1 deletion modules/apps/27-interchain-accounts/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (k Keeper) createOutgoingPacket(
destinationChannel string,
data interface{},
) ([]byte, error) {

if data == nil {
return []byte{}, types.ErrInvalidOutgoingData
}
Expand Down
93 changes: 93 additions & 0 deletions modules/apps/27-interchain-accounts/keeper/relay_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package keeper_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

ibctesting "github.com/cosmos/ibc-go/testing"
)

func (suite *KeeperTestSuite) TestTrySendTx() {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
var (
path *ibctesting.Path
msg interface{}
portID string
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success", func() {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
amount, _ := sdk.ParseCoinsNormalized("100stake")
interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID)
msg = &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount}
}, true,
},
{
"success with []sdk.Message", func() {
amount, _ := sdk.ParseCoinsNormalized("100stake")
interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID)
msg1 := &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount}
msg2 := &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount}
msg = []sdk.Msg{msg1, msg2}
}, true,
},
{
"incorrect outgoing data", func() {
msg = []byte{}
}, false,
},
{
"active channel not found", func() {
amount, _ := sdk.ParseCoinsNormalized("100stake")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could probably be a var defined at the top of the test? (reduce code)

interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID)
msg = &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount}
portID = "incorrect portID"
}, false,
},
{
"channel does not exist", func() {
amount, _ := sdk.ParseCoinsNormalized("100stake")
interchainAccountAddr, _ := suite.chainB.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointA.ChannelConfig.PortID)
msg = &banktypes.MsgSend{FromAddress: interchainAccountAddr, ToAddress: suite.chainB.SenderAccount.GetAddress().String(), Amount: amount}
suite.chainA.GetSimApp().ICAKeeper.SetActiveChannel(suite.chainA.GetContext(), portID, "channel-100")
}, false,
},
{
"data is nil", func() {
msg = nil
}, false,
},
{
"data is not an SDK message", func() {
msg = "not an sdk message"
}, false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
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
tc.malleate()
_, err = suite.chainA.GetSimApp().ICAKeeper.TrySendTx(suite.chainA.GetContext(), portID, msg)

if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
}
}
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import "fmt"

const (
// ModuleName defines the IBC transfer name
// ModuleName defines the Interchain Account module name
ModuleName = "interchainaccounts"

// Version defines the current version the IBC tranfer
Expand Down
2 changes: 1 addition & 1 deletion testing/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))

}

// set validators and delegations
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations)
genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis)
Expand Down