-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: re-creating account.go for controller side for consitency * chore: remove comment * Update modules/apps/27-interchain-accounts/controller/keeper/account.go
- Loading branch information
Showing
4 changed files
with
112 additions
and
99 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
modules/apps/27-interchain-accounts/controller/keeper/account.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,40 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" | ||
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types" | ||
host "github.com/cosmos/ibc-go/v2/modules/core/24-host" | ||
) | ||
|
||
// InitInterchainAccount is the entry point to registering an interchain account. | ||
// It generates a new port identifier using the owner address, connection identifier, | ||
// and counterparty connection identifier. It will bind to the port identifier and | ||
// call 04-channel 'ChanOpenInit'. An error is returned if the port identifier is | ||
// already in use. Gaining access to interchain accounts whose channels have closed | ||
// cannot be done with this function. A regular MsgChanOpenInit must be used. | ||
func (k Keeper) InitInterchainAccount(ctx sdk.Context, connectionID, counterpartyConnectionID, owner string) error { | ||
portID, err := types.GeneratePortID(owner, connectionID, counterpartyConnectionID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if k.portKeeper.IsBound(ctx, portID) { | ||
return sdkerrors.Wrap(types.ErrPortAlreadyBound, portID) | ||
} | ||
|
||
cap := k.BindPort(ctx, portID) | ||
if err := k.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil { | ||
return sdkerrors.Wrap(err, "unable to bind to newly generated portID") | ||
} | ||
|
||
msg := channeltypes.NewMsgChannelOpenInit(portID, types.VersionPrefix, channeltypes.ORDERED, []string{connectionID}, types.PortID, types.ModuleName) | ||
handler := k.msgRouter.Handler(msg) | ||
if _, err := handler(ctx, msg); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
72 changes: 72 additions & 0 deletions
72
modules/apps/27-interchain-accounts/controller/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,72 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" | ||
ibctesting "github.com/cosmos/ibc-go/v2/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestInitInterchainAccount() { | ||
var ( | ||
owner string | ||
path *ibctesting.Path | ||
err error | ||
) | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
"success", func() {}, true, | ||
}, | ||
{ | ||
"port is already bound", | ||
func() { | ||
suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID) | ||
}, | ||
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) | ||
suite.Require().NoError(err) | ||
|
||
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID) | ||
}, | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
|
||
owner = TestOwnerAddress // must be explicitly changed | ||
|
||
path = NewICAPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupConnections(path) | ||
|
||
tc.malleate() // malleate mutates test data | ||
|
||
err = suite.chainA.GetSimApp().ICAControllerKeeper.InitInterchainAccount(suite.chainA.GetContext(), path.EndpointA.ConnectionID, path.EndpointB.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
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