Skip to content

Commit

Permalink
refactor: move ica unordered field conditionals to santize.Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Jan 29, 2024
1 parent da73c65 commit c949d5b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 85 deletions.
46 changes: 5 additions & 41 deletions e2e/tests/interchain_accounts/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func (s *InterchainAccountsTestSuite) testMsgSendTxSuccessfulTransfer(order chan
// channel-0 is a transfer channel but it will not be used in this test case
relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil)
chainA, chainB := s.GetChains()
chainAVersion := chainA.Config().Images[0].Version

// setup 2 accounts: controller account on chain A, a second chain B account.
// host account will be created when the ICA is registered
Expand All @@ -73,16 +72,9 @@ func (s *InterchainAccountsTestSuite) testMsgSendTxSuccessfulTransfer(order chan
var hostAccount string

t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) {
// Must broadcast MsgRegisterInterchainAccount with default value for order field
// for those versions where MsgRegisterInterchainAccount does not have the order field
msgOrder := order
if !testvalues.UnorderedICAChannelFeatureReleases.IsSupported(chainAVersion) {
msgOrder = channeltypes.NONE
}

// explicitly set the version string because we don't want to use incentivized channels.
version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, msgOrder)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, order)

txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount)
s.AssertTxSuccess(txResp)
Expand All @@ -103,12 +95,7 @@ func (s *InterchainAccountsTestSuite) testMsgSendTxSuccessfulTransfer(order chan
s.Require().Equal(len(channels), 2)
icaChannel := channels[0]

// for the versions that don't support unordered channels, the ordering will default to ordered
orderKey := order
if !testvalues.UnorderedICAChannelFeatureReleases.IsSupported(chainAVersion) {
orderKey = channeltypes.ORDERED
}
s.Require().Contains(orderMapping[orderKey], icaChannel.Ordering)
s.Require().Contains(orderMapping[order], icaChannel.Ordering)
})

t.Run("interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) {
Expand Down Expand Up @@ -175,7 +162,6 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_FailedTransfer_InsufficientF
// channel-0 is a transfer channel but it will not be used in this test case
relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil)
chainA, chainB := s.GetChains()
chainAVersion := chainA.Config().Images[0].Version

// setup 2 accounts: controller account on chain A, a second chain B account.
// host account will be created when the ICA is registered
Expand All @@ -185,16 +171,9 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_FailedTransfer_InsufficientF
var hostAccount string

t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) {
// Must broadcast MsgRegisterInterchainAccount with default value for order field
// for those versions where MsgRegisterInterchainAccount does not have the order field
msgOrder := channeltypes.ORDERED
if !testvalues.UnorderedICAChannelFeatureReleases.IsSupported(chainAVersion) {
msgOrder = channeltypes.NONE
}

// explicitly set the version string because we don't want to use incentivized channels.
version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, msgOrder)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED)

txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount)
s.AssertTxSuccess(txResp)
Expand Down Expand Up @@ -273,7 +252,6 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReop
// channel-0 is a transfer channel but it will not be used in this test case
relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil)
chainA, chainB := s.GetChains()
chainAVersion := chainA.Config().Images[0].Version

// setup 2 accounts: controller account on chain A, a second chain B account.
// host account will be created when the ICA is registered
Expand All @@ -290,17 +268,10 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReop
)

t.Run("register interchain account", func(t *testing.T) {
// Must broadcast MsgRegisterInterchainAccount with default value for order field
// for those versions where MsgRegisterInterchainAccount does not have the order field
msgOrder := channeltypes.ORDERED
if !testvalues.UnorderedICAChannelFeatureReleases.IsSupported(chainAVersion) {
msgOrder = channeltypes.NONE
}

var err error
// explicitly set the version string because we don't want to use incentivized channels.
version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, msgOrder)
msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED)
s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterInterchainAccount)
portID, err = icatypes.NewControllerPortID(controllerAddress)
s.Require().NoError(err)
Expand Down Expand Up @@ -396,16 +367,9 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReop
// re-register interchain account to reopen the channel now that it has been closed due to timeout
// on an ordered channel
t.Run("register interchain account", func(t *testing.T) {
// Must broadcast MsgRegisterInterchainAccount with default value for order field
// for those versions where MsgRegisterInterchainAccount does not have the order field
msgOrder := channeltypes.ORDERED
if !testvalues.UnorderedICAChannelFeatureReleases.IsSupported(chainAVersion) {
msgOrder = channeltypes.NONE
}

// explicitly set the version string because we don't want to use incentivized channels.
version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, msgOrder)
msgRegisterInterchainAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.ORDERED)
s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterInterchainAccount)

s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB))
Expand Down
10 changes: 1 addition & 9 deletions e2e/tests/interchain_accounts/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (s *InterchainAccountsGovTestSuite) TestInterchainAccountsGovIntegration()
// channel-0 is a transfer channel but it will not be used in this test case
relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil)
chainA, chainB := s.GetChains()
chainAVersion := chainA.Config().Images[0].Version
controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)

chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
Expand All @@ -54,15 +53,8 @@ func (s *InterchainAccountsGovTestSuite) TestInterchainAccountsGovIntegration()
s.Require().NotNil(govModuleAddress)

t.Run("execute proposal for MsgRegisterInterchainAccount", func(t *testing.T) {
// Must broadcast MsgRegisterInterchainAccount with default value for order field
// for those versions where MsgRegisterInterchainAccount does not have the order field
msgOrder := channeltypes.ORDERED
if !testvalues.UnorderedICAChannelFeatureReleases.IsSupported(chainAVersion) {
msgOrder = channeltypes.NONE
}

version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, govModuleAddress.String(), version, msgOrder)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, govModuleAddress.String(), version, channeltypes.ORDERED)
s.ExecuteAndPassGovV1Proposal(ctx, msgRegisterAccount, chainA, controllerAccount)
})

Expand Down
10 changes: 1 addition & 9 deletions e2e/tests/interchain_accounts/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (s *InterchainAccountsGroupsTestSuite) TestInterchainAccountsGroupsIntegrat
// channel-0 is a transfer channel but it will not be used in this test case
relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil)
chainA, chainB := s.GetChains()
chainAVersion := chainA.Config().Images[0].Version

chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.FormattedAddress()
Expand All @@ -115,15 +114,8 @@ func (s *InterchainAccountsGroupsTestSuite) TestInterchainAccountsGroupsIntegrat
})

t.Run("submit proposal for MsgRegisterInterchainAccount", func(t *testing.T) {
// Must broadcast MsgRegisterInterchainAccount with default value for order field
// for those versions where MsgRegisterInterchainAccount does not have the order field
msgOrder := channeltypes.ORDERED
if !testvalues.UnorderedICAChannelFeatureReleases.IsSupported(chainAVersion) {
msgOrder = channeltypes.NONE
}

groupPolicyAddr = s.QueryGroupPolicyAddress(ctx, chainA)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, groupPolicyAddr, icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID), msgOrder)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, groupPolicyAddr, icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID), channeltypes.ORDERED)

msgSubmitProposal, err := grouptypes.NewMsgSubmitProposal(groupPolicyAddr, []string{chainAAddress}, []sdk.Msg{msgRegisterAccount}, DefaultMetadata, grouptypes.Exec_EXEC_UNSPECIFIED, "e2e groups proposal: for MsgRegisterInterchainAccount", "e2e groups proposal: for MsgRegisterInterchainAccount")
s.Require().NoError(err)
Expand Down
20 changes: 2 additions & 18 deletions e2e/tests/interchain_accounts/incentivized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (s *IncentivizedInterchainAccountsTestSuite) TestMsgSendTx_SuccessfulBankSe
// channel-0 is a transfer channel but it will not be used in this test case
relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil)
chainA, chainB := s.GetChains()
chainAVersion := chainA.Config().Images[0].Version

var (
chainADenom = chainA.Config().Denom
Expand Down Expand Up @@ -72,15 +71,8 @@ func (s *IncentivizedInterchainAccountsTestSuite) TestMsgSendTx_SuccessfulBankSe
chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) {
// Must broadcast MsgRegisterInterchainAccount with default value for order field
// for those versions where MsgRegisterInterchainAccount does not have the order field
msgOrder := channeltypes.ORDERED
if !testvalues.UnorderedICAChannelFeatureReleases.IsSupported(chainAVersion) {
msgOrder = channeltypes.NONE
}

version := "" // allow version to be specified by the controller chain since both chains should support incentivized channels
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAccount.FormattedAddress(), version, msgOrder)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAccount.FormattedAddress(), version, channeltypes.ORDERED)

txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount)
s.AssertTxSuccess(txResp)
Expand Down Expand Up @@ -229,7 +221,6 @@ func (s *IncentivizedInterchainAccountsTestSuite) TestMsgSendTx_FailedBankSend_I
// channel-0 is a transfer channel but it will not be used in this test case
relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil)
chainA, chainB := s.GetChains()
chainAVersion := chainA.Config().Images[0].Version

var (
chainADenom = chainA.Config().Denom
Expand Down Expand Up @@ -258,15 +249,8 @@ func (s *IncentivizedInterchainAccountsTestSuite) TestMsgSendTx_FailedBankSend_I
chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) {
// Must broadcast MsgRegisterInterchainAccount with default value for order field
// for those versions where MsgRegisterInterchainAccount does not have the order field
msgOrder := channeltypes.ORDERED
if !testvalues.UnorderedICAChannelFeatureReleases.IsSupported(chainAVersion) {
msgOrder = channeltypes.NONE
}

version := "" // allow version to be specified by the controller chain since both chains should support incentivized channels
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAccount.FormattedAddress(), version, msgOrder)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAccount.FormattedAddress(), version, channeltypes.ORDERED)

txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount)
s.AssertTxSuccess(txResp)
Expand Down
14 changes: 14 additions & 0 deletions e2e/testsuite/sanitize/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
grouptypes "github.com/cosmos/cosmos-sdk/x/group"

icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

"github.com/cosmos/ibc-go/e2e/semverutil"
)

Expand All @@ -17,6 +20,13 @@ var (
govv1ProposalTitleAndSummary = semverutil.FeatureReleases{
MajorVersion: "v7",
}
// icaUnorderedChannelFeatureReleases represents the releasees that support the new ordering field.
icaUnorderedChannelFeatureReleases = semverutil.FeatureReleases{
MajorVersion: "v9",
MinorVersions: []string{
"v8.1",
},
}
)

// Messages removes any fields that are not supported by the chain version.
Expand Down Expand Up @@ -45,6 +55,10 @@ func removeUnknownFields(tag string, msg sdk.Msg) sdk.Msg {
msg.Summary = ""
}
return msg
case *icacontrollertypes.MsgRegisterInterchainAccount:
if !icaUnorderedChannelFeatureReleases.IsSupported(tag) {
msg.Ordering = channeltypes.NONE
}
}
return msg
}
8 changes: 0 additions & 8 deletions e2e/testvalues/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ var GovV1MessagesFeatureReleases = semverutil.FeatureReleases{
MajorVersion: "v8",
}

// UnorderedICAChannelFeatureReleases represents the releases the support for unordered ICA channels was released in.
var UnorderedICAChannelFeatureReleases = semverutil.FeatureReleases{
MajorVersion: "v9",
MinorVersions: []string{
"v8.1",
},
}

// CapitalEfficientFeeEscrowFeatureReleases represents the releases the support for capital efficient fee escrow was released in.
var CapitalEfficientFeeEscrowFeatureReleases = semverutil.FeatureReleases{
MajorVersion: "v9",
Expand Down

0 comments on commit c949d5b

Please sign in to comment.