-
Notifications
You must be signed in to change notification settings - Fork 620
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
refactor: always set ics27 ports regardless of whether the capability exists #4640
Changes from all commits
62b0fb3
69cb39f
dbf18a7
12de9b9
cc239e2
ec56a19
a36a978
7e22c19
b8c2927
05bd205
0c72f48
f981eb7
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 |
---|---|---|
|
@@ -62,7 +62,8 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, | |
case k.portKeeper.IsBound(ctx, portID) && !k.hasCapability(ctx, portID): | ||
return "", errorsmod.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID) | ||
case !k.portKeeper.IsBound(ctx, portID): | ||
capability := k.BindPort(ctx, portID) | ||
k.setPort(ctx, portID) | ||
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. ideally gets removed #4638 in the future |
||
capability := k.portKeeper.BindPort(ctx, portID) | ||
if err := k.ClaimCapability(ctx, capability, host.PortPath(portID)); err != nil { | ||
return "", errorsmod.Wrapf(err, "unable to bind to newly generated portID: %s", portID) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,29 @@ import ( | |
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" | ||
genesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types" | ||
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" | ||
host "github.com/cosmos/ibc-go/v8/modules/core/24-host" | ||
ibctesting "github.com/cosmos/ibc-go/v8/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestInitGenesis() { | ||
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. Table tests ++ 💪 |
||
suite.SetupTest() | ||
ports := []string{"port1", "port2", "port3"} | ||
|
||
testCases := []struct { | ||
name string | ||
malleate func() | ||
}{ | ||
{ | ||
"success", func() {}, | ||
}, | ||
{ | ||
"success: capabilities already initialized for first port", | ||
func() { | ||
capability := suite.chainA.GetSimApp().IBCKeeper.PortKeeper.BindPort(suite.chainA.GetContext(), ports[0]) | ||
err := suite.chainA.GetSimApp().ICAControllerKeeper.ClaimCapability(suite.chainA.GetContext(), capability, host.PortPath(ports[0])) | ||
suite.Require().NoError(err) | ||
}, | ||
}, | ||
} | ||
|
||
interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) | ||
genesisState := genesistypes.ControllerGenesisState{ | ||
|
@@ -34,28 +52,46 @@ func (suite *KeeperTestSuite) TestInitGenesis() { | |
AccountAddress: interchainAccAddr.String(), | ||
}, | ||
}, | ||
Ports: []string{TestPortID}, | ||
Ports: ports, | ||
} | ||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper, genesisState) | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
|
||
channelID, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) | ||
suite.Require().True(found) | ||
suite.Require().Equal(ibctesting.FirstChannelID, channelID) | ||
tc.malleate() | ||
|
||
isMiddlewareEnabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareEnabled(suite.chainA.GetContext(), TestPortID, ibctesting.FirstConnectionID) | ||
suite.Require().True(isMiddlewareEnabled) | ||
keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAControllerKeeper, genesisState) | ||
|
||
isMiddlewareDisabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareDisabled(suite.chainA.GetContext(), "test-port-1", "connection-1") | ||
suite.Require().True(isMiddlewareDisabled) | ||
channelID, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) | ||
suite.Require().True(found) | ||
suite.Require().Equal(ibctesting.FirstChannelID, channelID) | ||
|
||
accountAdrr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) | ||
suite.Require().True(found) | ||
suite.Require().Equal(interchainAccAddr.String(), accountAdrr) | ||
isMiddlewareEnabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareEnabled(suite.chainA.GetContext(), TestPortID, ibctesting.FirstConnectionID) | ||
suite.Require().True(isMiddlewareEnabled) | ||
|
||
expParams := types.NewParams(false) | ||
params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext()) | ||
suite.Require().Equal(expParams, params) | ||
isMiddlewareDisabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareDisabled(suite.chainA.GetContext(), "test-port-1", "connection-1") | ||
suite.Require().True(isMiddlewareDisabled) | ||
|
||
accountAdrr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) | ||
suite.Require().True(found) | ||
suite.Require().Equal(interchainAccAddr.String(), accountAdrr) | ||
|
||
expParams := types.NewParams(false) | ||
params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext()) | ||
suite.Require().Equal(expParams, params) | ||
|
||
for _, port := range ports { | ||
store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(types.StoreKey)) | ||
suite.Require().True(store.Has(icatypes.KeyPort(port))) | ||
|
||
capability, found := suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), host.PortPath(port)) | ||
suite.Require().True(found) | ||
suite.Require().NotNil(capability) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestExportGenesis() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,12 @@ import ( | |
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper" | ||
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" | ||
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" | ||
host "github.com/cosmos/ibc-go/v8/modules/core/24-host" | ||
ibctesting "github.com/cosmos/ibc-go/v8/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestInitGenesis() { | ||
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. it's really hard to test both setups of capabilities already being initialized or not being initialized as the testing pkg will call init genesis first and the portID is hard coded. I personally think this sort of integration testing is better handled by the e2e's which is why I added coverage there |
||
suite.SetupTest() | ||
|
||
interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) | ||
|
||
genesisState := genesistypes.HostGenesisState{ | ||
ActiveChannels: []genesistypes.ActiveChannel{ | ||
{ | ||
|
@@ -44,6 +42,13 @@ func (suite *KeeperTestSuite) TestInitGenesis() { | |
expParams := genesisState.GetParams() | ||
params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) | ||
suite.Require().Equal(expParams, params) | ||
|
||
store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(types.StoreKey)) | ||
suite.Require().True(store.Has(icatypes.KeyPort(icatypes.HostPortID))) | ||
|
||
capability, found := suite.chainA.GetSimApp().ScopedICAHostKeeper.GetCapability(suite.chainA.GetContext(), host.PortPath(icatypes.HostPortID)) | ||
suite.Require().True(found) | ||
suite.Require().NotNil(capability) | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestGenesisParams() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ import ( | |
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/simulation" | ||
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" | ||
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" | ||
ibchost "github.com/cosmos/ibc-go/v8/modules/core/24-host" | ||
) | ||
|
||
var ( | ||
|
@@ -126,19 +125,20 @@ func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkee | |
// called once and as an alternative to InitGenesis. | ||
func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes.Params, hostParams hosttypes.Params) { | ||
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. |
||
if am.controllerKeeper != nil { | ||
am.controllerKeeper.SetParams(ctx, controllerParams) | ||
controllerkeeper.InitGenesis(ctx, *am.controllerKeeper, genesistypes.ControllerGenesisState{ | ||
Params: controllerParams, | ||
}) | ||
} | ||
|
||
if am.hostKeeper != nil { | ||
if err := hostParams.Validate(); err != nil { | ||
panic(fmt.Sprintf("could not set ica host params at initialization: %v", err)) | ||
} | ||
am.hostKeeper.SetParams(ctx, hostParams) | ||
|
||
capability := am.hostKeeper.BindPort(ctx, types.HostPortID) | ||
if err := am.hostKeeper.ClaimCapability(ctx, capability, ibchost.PortPath(types.HostPortID)); err != nil { | ||
panic(fmt.Sprintf("could not claim port capability: %v", err)) | ||
} | ||
hostkeeper.InitGenesis(ctx, *am.hostKeeper, genesistypes.HostGenesisState{ | ||
Params: hostParams, | ||
Port: types.HostPortID, | ||
}) | ||
} | ||
} | ||
|
||
|
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.
copy/pasted from ics27 tests