-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit 5a67efc) # Conflicts: # .github/workflows/golangci.yml # .golangci.yml # modules/apps/27-interchain-accounts/controller/keeper/account.go # modules/apps/27-interchain-accounts/controller/keeper/genesis.go # modules/apps/27-interchain-accounts/controller/migrations/v6/migrations_test.go # modules/apps/27-interchain-accounts/controller/types/params.go # modules/apps/27-interchain-accounts/host/keeper/genesis.go # modules/apps/27-interchain-accounts/module.go # modules/apps/transfer/keeper/relay_test.go # modules/core/02-client/migrations/v7/store.go # modules/core/04-channel/keeper/handshake_test.go # modules/core/keeper/migrations.go # modules/core/keeper/msg_server.go # modules/core/module.go # modules/light-clients/06-solomachine/misbehaviour_handle.go # modules/light-clients/07-tendermint/client_state.go # testing/chain.go # testing/endpoint.go
- Loading branch information
1 parent
6b281bd
commit 03f545c
Showing
39 changed files
with
1,072 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,10 @@ jobs: | |
- name: golangci-lint | ||
uses: golangci/[email protected] | ||
with: | ||
<<<<<<< HEAD | ||
version: latest | ||
args: --timeout 5m | ||
args: --timeout 5m | ||
======= | ||
version: v1.52.0 | ||
args: --timeout 5m | ||
>>>>>>> 5a67efc4 (chore: fix linter warnings (#3311)) |
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
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
196 changes: 196 additions & 0 deletions
196
modules/apps/27-interchain-accounts/controller/migrations/v6/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,196 @@ | ||
package v6_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" | ||
"github.com/stretchr/testify/suite" | ||
|
||
v6 "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/migrations/v6" | ||
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" | ||
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" | ||
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" | ||
host "github.com/cosmos/ibc-go/v7/modules/core/24-host" | ||
ibctesting "github.com/cosmos/ibc-go/v7/testing" | ||
ibcmock "github.com/cosmos/ibc-go/v7/testing/mock" | ||
) | ||
|
||
type MigrationsTestSuite struct { | ||
suite.Suite | ||
|
||
chainA *ibctesting.TestChain | ||
chainB *ibctesting.TestChain | ||
|
||
coordinator *ibctesting.Coordinator | ||
path *ibctesting.Path | ||
} | ||
|
||
func (suite *MigrationsTestSuite) SetupTest() { | ||
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) | ||
|
||
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) | ||
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) | ||
|
||
suite.path = ibctesting.NewPath(suite.chainA, suite.chainB) | ||
suite.path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID | ||
suite.path.EndpointB.ChannelConfig.PortID = icatypes.HostPortID | ||
suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED | ||
suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED | ||
suite.path.EndpointA.ChannelConfig.Version = icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) | ||
suite.path.EndpointB.ChannelConfig.Version = icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) | ||
} | ||
|
||
func (suite *MigrationsTestSuite) SetupPath() error { | ||
if err := suite.RegisterInterchainAccount(suite.path.EndpointA, ibctesting.TestAccAddress); err != nil { | ||
return err | ||
} | ||
|
||
if err := suite.path.EndpointB.ChanOpenTry(); err != nil { | ||
return err | ||
} | ||
|
||
if err := suite.path.EndpointA.ChanOpenAck(); err != nil { | ||
return err | ||
} | ||
|
||
return suite.path.EndpointB.ChanOpenConfirm() | ||
} | ||
|
||
func (suite *MigrationsTestSuite) RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) error { | ||
portID, err := icatypes.NewControllerPortID(owner) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
channelSequence := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(endpoint.Chain.GetContext()) | ||
|
||
if err := endpoint.Chain.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(endpoint.Chain.GetContext(), endpoint.ConnectionID, owner, endpoint.ChannelConfig.Version); err != nil { | ||
return err | ||
} | ||
|
||
// commit state changes for proof verification | ||
endpoint.Chain.NextBlock() | ||
|
||
// update port/channel ids | ||
endpoint.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence) | ||
endpoint.ChannelConfig.PortID = portID | ||
|
||
return nil | ||
} | ||
|
||
func TestKeeperTestSuite(t *testing.T) { | ||
suite.Run(t, new(MigrationsTestSuite)) | ||
} | ||
|
||
func (suite *MigrationsTestSuite) TestMigrateICS27ChannelCapability() { | ||
suite.SetupTest() | ||
suite.coordinator.SetupConnections(suite.path) | ||
|
||
err := suite.SetupPath() | ||
suite.Require().NoError(err) | ||
|
||
// create additional capabilities to cover edge cases | ||
suite.CreateMockCapabilities() | ||
|
||
// create and claim a new capability with ibc/mock for "channel-1" | ||
// note: suite.SetupPath() now claims the chanel capability using icacontroller for "channel-0" | ||
capName := host.ChannelCapabilityPath(suite.path.EndpointA.ChannelConfig.PortID, channeltypes.FormatChannelIdentifier(1)) | ||
|
||
capability, err := suite.chainA.GetSimApp().ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), capName) | ||
suite.Require().NoError(err) | ||
|
||
err = suite.chainA.GetSimApp().ScopedICAMockKeeper.ClaimCapability(suite.chainA.GetContext(), capability, capName) | ||
suite.Require().NoError(err) | ||
|
||
// assert the capability is owned by the mock module | ||
capability, found := suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(suite.chainA.GetContext(), capName) | ||
suite.Require().NotNil(capability) | ||
suite.Require().True(found) | ||
|
||
isAuthenticated := suite.chainA.GetSimApp().ScopedICAMockKeeper.AuthenticateCapability(suite.chainA.GetContext(), capability, capName) | ||
suite.Require().True(isAuthenticated) | ||
|
||
capability, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName) | ||
suite.Require().Nil(capability) | ||
suite.Require().False(found) | ||
|
||
suite.ResetMemStore() // empty the x/capability in-memory store | ||
|
||
err = v6.MigrateICS27ChannelCapability( | ||
suite.chainA.GetContext(), | ||
suite.chainA.Codec, | ||
suite.chainA.GetSimApp().GetKey(capabilitytypes.StoreKey), | ||
suite.chainA.GetSimApp().CapabilityKeeper, | ||
ibcmock.ModuleName+types.SubModuleName, | ||
) | ||
|
||
suite.Require().NoError(err) | ||
|
||
// assert the capability is now owned by the ICS27 controller submodule | ||
capability, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName) | ||
suite.Require().NotNil(capability) | ||
suite.Require().True(found) | ||
|
||
isAuthenticated = suite.chainA.GetSimApp().ScopedICAControllerKeeper.AuthenticateCapability(suite.chainA.GetContext(), capability, capName) | ||
suite.Require().True(isAuthenticated) | ||
|
||
capability, found = suite.chainA.GetSimApp().ScopedICAMockKeeper.GetCapability(suite.chainA.GetContext(), capName) | ||
suite.Require().Nil(capability) | ||
suite.Require().False(found) | ||
|
||
// ensure channel capability for "channel-0" is still owned by the controller | ||
capName = host.ChannelCapabilityPath(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID) | ||
capability, found = suite.chainA.GetSimApp().ScopedICAControllerKeeper.GetCapability(suite.chainA.GetContext(), capName) | ||
suite.Require().NotNil(capability) | ||
suite.Require().True(found) | ||
|
||
isAuthenticated = suite.chainA.GetSimApp().ScopedICAControllerKeeper.AuthenticateCapability(suite.chainA.GetContext(), capability, capName) | ||
suite.Require().True(isAuthenticated) | ||
|
||
suite.AssertMockCapabiltiesUnchanged() | ||
} | ||
|
||
// CreateMockCapabilities creates an additional two capabilities used for testing purposes: | ||
// 1. A capability with a single owner | ||
// 2. A capability with two owners, neither of which is "ibc" | ||
func (suite *MigrationsTestSuite) CreateMockCapabilities() { | ||
capability, err := suite.chainA.GetSimApp().ScopedIBCMockKeeper.NewCapability(suite.chainA.GetContext(), "mock_one") | ||
suite.Require().NoError(err) | ||
suite.Require().NotNil(capability) | ||
|
||
capability, err = suite.chainA.GetSimApp().ScopedICAMockKeeper.NewCapability(suite.chainA.GetContext(), "mock_two") | ||
suite.Require().NoError(err) | ||
suite.Require().NotNil(capability) | ||
|
||
err = suite.chainA.GetSimApp().ScopedIBCMockKeeper.ClaimCapability(suite.chainA.GetContext(), capability, "mock_two") | ||
suite.Require().NoError(err) | ||
} | ||
|
||
// AssertMockCapabiltiesUnchanged authenticates the mock capabilities created at the start of the test to ensure they remain unchanged | ||
func (suite *MigrationsTestSuite) AssertMockCapabiltiesUnchanged() { | ||
capability, found := suite.chainA.GetSimApp().ScopedIBCMockKeeper.GetCapability(suite.chainA.GetContext(), "mock_one") | ||
suite.Require().True(found) | ||
suite.Require().NotNil(capability) | ||
|
||
capability, found = suite.chainA.GetSimApp().ScopedIBCMockKeeper.GetCapability(suite.chainA.GetContext(), "mock_two") | ||
suite.Require().True(found) | ||
suite.Require().NotNil(capability) | ||
|
||
isAuthenticated := suite.chainA.GetSimApp().ScopedICAMockKeeper.AuthenticateCapability(suite.chainA.GetContext(), capability, "mock_two") | ||
suite.Require().True(isAuthenticated) | ||
} | ||
|
||
// ResetMemstore removes all existing fwd and rev capability kv pairs and deletes `KeyMemInitialised` from the x/capability memstore. | ||
// This effectively mocks a new chain binary being started. Migration code is run against persisted state only and allows the memstore to be reinitialised. | ||
func (suite *MigrationsTestSuite) ResetMemStore() { | ||
memStore := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetMemKey(capabilitytypes.MemStoreKey)) | ||
memStore.Delete(capabilitytypes.KeyMemInitialized) | ||
|
||
iterator := memStore.Iterator(nil, nil) | ||
defer sdk.LogDeferred(suite.chainA.GetContext().Logger(), func() error { return iterator.Close() }) | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
memStore.Delete(iterator.Key()) | ||
} | ||
} |
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
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
Oops, something went wrong.