-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interchain account OnChanOpenInit and InitInterchainAccount tests (…
…#287) * add OnChanOpenInit test * add InitInterchainAccount test * Update modules/apps/27-interchain-accounts/keeper/relay.go
- Loading branch information
1 parent
b870be4
commit c3be169
Showing
7 changed files
with
213 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
modules/apps/27-interchain-accounts/keeper/account_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package keeper_test | ||
|
||
import ( | ||
ibctesting "github.com/cosmos/ibc-go/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestInitInterchainAccount() { | ||
var ( | ||
owner string | ||
path *ibctesting.Path | ||
err error | ||
) | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
|
||
{ | ||
"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, | ||
}, | ||
*/ | ||
{ | ||
"MsgChanOpenInit fails - channel is already active", func() { | ||
portID := suite.chainA.GetSimApp().ICAKeeper.GeneratePortId(owner, path.EndpointA.ConnectionID) | ||
suite.chainA.GetSimApp().ICAKeeper.SetActiveChannel(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID) | ||
}, false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
suite.Run(tc.name, func() { | ||
suite.SetupTest() // reset | ||
owner = "owner" // must be explicitly changed | ||
path = NewICAPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupConnections(path) | ||
|
||
tc.malleate() // explicitly change fields in channel and testChannel | ||
|
||
err = suite.chainA.GetSimApp().ICAKeeper.InitInterchainAccount(suite.chainA.GetContext(), path.EndpointA.ConnectionID, owner) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
modules/apps/27-interchain-accounts/keeper/handshake_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,98 @@ | ||
package keeper_test | ||
|
||
import ( | ||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" | ||
|
||
"github.com/cosmos/ibc-go/modules/apps/27-interchain-accounts/types" | ||
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" | ||
host "github.com/cosmos/ibc-go/modules/core/24-host" | ||
ibctesting "github.com/cosmos/ibc-go/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestOnChanOpenInit() { | ||
var ( | ||
channel *channeltypes.Channel | ||
path *ibctesting.Path | ||
chanCap *capabilitytypes.Capability | ||
err error | ||
) | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
|
||
{ | ||
"success", func() {}, true, | ||
}, | ||
{ | ||
"invalid order - UNORDERED", func() { | ||
channel.Ordering = channeltypes.UNORDERED | ||
}, false, | ||
}, | ||
{ | ||
"invalid counterparty port ID", func() { | ||
channel.Counterparty.PortId = ibctesting.MockPort | ||
}, false, | ||
}, | ||
{ | ||
"invalid version", func() { | ||
channel.Version = "version" | ||
}, false, | ||
}, | ||
{ | ||
"channel is already active", func() { | ||
suite.chainA.GetSimApp().ICAKeeper.SetActiveChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) | ||
}, false, | ||
}, | ||
{ | ||
"capability already claimed", func() { | ||
err := suite.chainA.GetSimApp().ScopedICAKeeper.ClaimCapability(suite.chainA.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) | ||
suite.Require().NoError(err) | ||
}, false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
suite.Run(tc.name, func() { | ||
suite.SetupTest() // reset | ||
path = NewICAPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupConnections(path) | ||
|
||
// mock init interchain account | ||
portID := suite.chainA.GetSimApp().ICAKeeper.GeneratePortId("owner", path.EndpointA.ConnectionID) | ||
portCap := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), portID) | ||
suite.chainA.GetSimApp().ICAKeeper.ClaimCapability(suite.chainA.GetContext(), portCap, host.PortPath(portID)) | ||
path.EndpointA.ChannelConfig.PortID = portID | ||
|
||
// default values | ||
counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) | ||
channel = &channeltypes.Channel{ | ||
State: channeltypes.INIT, | ||
Ordering: channeltypes.ORDERED, | ||
Counterparty: counterparty, | ||
ConnectionHops: []string{path.EndpointA.ConnectionID}, | ||
Version: types.Version, | ||
} | ||
|
||
chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(portID, path.EndpointA.ChannelID)) | ||
suite.Require().NoError(err) | ||
|
||
tc.malleate() // explicitly change fields in channel and testChannel | ||
|
||
err = suite.chainA.GetSimApp().ICAKeeper.OnChanOpenInit(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(), | ||
path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, chanCap, channel.Counterparty, channel.GetVersion(), | ||
) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters