-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into damian/add-ica-address-query
- Loading branch information
Showing
8 changed files
with
5,521 additions
and
6,372 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
41 changes: 41 additions & 0 deletions
41
modules/apps/27-interchain-accounts/controller/keeper/migrations.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,41 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" | ||
|
||
"github.com/cosmos/ibc-go/v5/modules/core/23-commitment/types" | ||
host "github.com/cosmos/ibc-go/v5/modules/core/24-host" | ||
) | ||
|
||
// Migrator is a struct for handling in-place store migrations. | ||
type Migrator struct { | ||
keeper *Keeper | ||
} | ||
|
||
// NewMigrator returns a new Migrator. | ||
func NewMigrator(keeper *Keeper) Migrator { | ||
return Migrator{keeper: keeper} | ||
} | ||
|
||
// AssertChannelCapabilityMigrations checks that all channel capabilities generated using the interchain accounts controller port prefix | ||
// are owned by the controller submodule and ibc. | ||
func (m Migrator) AssertChannelCapabilityMigrations(ctx sdk.Context) error { | ||
for _, ch := range m.keeper.GetAllActiveChannels(ctx) { | ||
name := host.ChannelCapabilityPath(ch.PortId, ch.ChannelId) | ||
cap, found := m.keeper.scopedKeeper.GetCapability(ctx, name) | ||
if !found { | ||
return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotFound, "failed to find capability: %s", name) | ||
} | ||
|
||
isAuthenticated := m.keeper.scopedKeeper.AuthenticateCapability(ctx, cap, name) | ||
if !isAuthenticated { | ||
return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", types.SubModuleName) | ||
} | ||
|
||
m.keeper.SetMiddlewareEnabled(ctx, ch.PortId, ch.ChannelId) | ||
} | ||
|
||
return nil | ||
} |
63 changes: 63 additions & 0 deletions
63
modules/apps/27-interchain-accounts/controller/keeper/migrations_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,63 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper" | ||
ibctesting "github.com/cosmos/ibc-go/v5/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestAssertChannelCapabilityMigrations() { | ||
testCases := []struct { | ||
name string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
"success", | ||
func() {}, | ||
true, | ||
}, | ||
{ | ||
"capability not found", | ||
func() { | ||
suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID( | ||
suite.chainA.GetContext(), | ||
ibctesting.FirstConnectionID, | ||
ibctesting.MockPort, | ||
ibctesting.FirstChannelID, | ||
) | ||
}, | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
|
||
path := NewICAPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupConnections(path) | ||
|
||
err := SetupICAPath(path, ibctesting.TestAccAddress) | ||
suite.Require().NoError(err) | ||
|
||
tc.malleate() | ||
|
||
migrator := keeper.NewMigrator(&suite.chainA.GetSimApp().ICAControllerKeeper) | ||
err = migrator.AssertChannelCapabilityMigrations(suite.chainA.GetContext()) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
|
||
isMiddlewareEnabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareEnabled( | ||
suite.chainA.GetContext(), | ||
path.EndpointA.ChannelConfig.PortID, | ||
path.EndpointA.ChannelID, | ||
) | ||
|
||
suite.Require().True(isMiddlewareEnabled) | ||
} 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