Skip to content

Commit

Permalink
e2e: ordered ica channel is upgraded to unordered (#5616)
Browse files Browse the repository at this point in the history
  • Loading branch information
charleenfei authored Jan 16, 2024
1 parent 8841699 commit f23ba98
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 9 deletions.
127 changes: 127 additions & 0 deletions e2e/tests/interchain_accounts/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testvalues"
Expand Down Expand Up @@ -406,3 +407,129 @@ func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterReop
s.Require().Equal(expected, balance.Int64())
})
}

func (s *InterchainAccountsTestSuite) TestMsgSendTx_SuccessfulTransfer_AfterUpgradingOrdertoUnordered() {
t := s.T()
ctx := context.TODO()

// setup relayers and connection-0 between two chains
// channel-0 is a transfer channel but it will not be used in this test case
relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil)
chainA, _ := s.GetChains()

// setup 2 accounts: controller account on chain A, a second chain B account.
// host account will be created when the ICA is registered
controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
controllerAddress := controllerAccount.FormattedAddress()
// chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

var (
portID string
hostAccount string

initialChannelID = "channel-1"
)

t.Run("register interchain account", func(t *testing.T) {
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, channeltypes.ORDERED)
s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterInterchainAccount)
portID, err = icatypes.NewControllerPortID(controllerAddress)
s.Require().NoError(err)
})

t.Run("start relayer", func(t *testing.T) {
s.StartRelayer(relayer)
})

t.Run("verify interchain account", func(t *testing.T) {
var err error
hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID)
s.Require().NoError(err)
s.Require().NotZero(len(hostAccount))

_, err = s.QueryChannel(ctx, chainA, portID, initialChannelID)
s.Require().NoError(err)
})

// t.Run("fund interchain account wallet", func(t *testing.T) {
// // fund the host account account so it has some $$ to send
// err := chainB.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{
// Address: hostAccount,
// Amount: sdkmath.NewInt(testvalues.StartingTokenAmount),
// Denom: chainB.Config().Denom,
// })
// s.Require().NoError(err)
// })

// t.Run("broadcast MsgSendTx", func(t *testing.T) {
// // assemble bank transfer message from host account to user account on host chain
// msgSend := &banktypes.MsgSend{
// FromAddress: hostAccount,
// ToAddress: chainBAccount.FormattedAddress(),
// Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)),
// }

// cdc := testsuite.Codec()

// bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}, icatypes.EncodingProtobuf)
// s.Require().NoError(err)

// packetData := icatypes.InterchainAccountPacketData{
// Type: icatypes.EXECUTE_TX,
// Data: bz,
// Memo: "e2e",
// }

// msgSendTx := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(5*time.Minute), packetData)

// resp := s.BroadcastMessages(
// ctx,
// chainA,
// controllerAccount,
// msgSendTx,
// )

// s.AssertTxSuccess(resp)

// // time for the packet to be relayed
// s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB))
// })

// t.Run("verify tokens transferred", func(t *testing.T) {
// balance, err := s.QueryBalance(ctx, chainB, chainBAccount.FormattedAddress(), chainB.Config().Denom)
// s.Require().NoError(err)

// expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount
// s.Require().Equal(expected, balance.Int64())
// })

channel, err := s.QueryChannel(ctx, chainA, portID, initialChannelID)
s.Require().NoError(err)

// upgrade the channel ordering to UNORDERED
upgradeFields := channeltypes.NewUpgradeFields(channeltypes.UNORDERED, channel.ConnectionHops, channel.Version)

t.Run("execute gov proposal to initiate channel upgrade", func(t *testing.T) {
govModuleAddress, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(govModuleAddress)

msg := channeltypes.NewMsgChannelUpgradeInit(portID, initialChannelID, upgradeFields, govModuleAddress.String())
s.ExecuteAndPassGovV1Proposal(ctx, msg, chainA, controllerAccount)
})

t.Run("verify channel A upgraded and is now unordered", func(t *testing.T) {
var channel channeltypes.Channel
waitErr := test.WaitForCondition(time.Minute*2, time.Second*5, func() (bool, error) {
channel, err = s.QueryChannel(ctx, chainA, portID, initialChannelID)
if err != nil {
return false, err
}
return channel.Ordering == channeltypes.UNORDERED, nil
})
s.Require().NoErrorf(waitErr, "channel was not upgraded: expected %s got %s", channeltypes.UNORDERED, channel.Ordering)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,10 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() {

func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeInit() {
var (
path *ibctesting.Path
isNilApp bool
version string
path *ibctesting.Path
isNilApp bool
version string
channelOrder channeltypes.Order
)

testCases := []struct {
Expand All @@ -773,7 +774,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeInit() {
expError error
}{
{
"success", func() {}, nil,
"success w/ ORDERED channel", func() {}, nil,
},
{
"success w/ UNORDERED channel", func() {
channelOrder = channeltypes.UNORDERED
}, nil,
},
{
"success: nil underlying app",
Expand Down Expand Up @@ -839,11 +845,13 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeInit() {
cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper)
}

channelOrder = channeltypes.ORDERED

version, err = cbs.OnChanUpgradeInit(
suite.chainA.GetContext(),
path.EndpointA.ChannelConfig.PortID,
path.EndpointA.ChannelID,
channeltypes.ORDERED,
channelOrder,
[]string{path.EndpointA.ConnectionID},
version,
)
Expand Down Expand Up @@ -957,15 +965,20 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeOpen() {
path *ibctesting.Path
isNilApp bool
counterpartyVersion string
channelOrder channeltypes.Order
)

testCases := []struct {
name string
malleate func()
}{
{
"success",
func() {},
"success w/ ORDERED channel", func() {},
},
{
"success w/ UNORDERED channel", func() {
channelOrder = channeltypes.UNORDERED
},
},
{
"success: nil app",
Expand Down Expand Up @@ -1012,11 +1025,13 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeOpen() {
cbs = controller.NewIBCMiddleware(nil, suite.chainA.GetSimApp().ICAControllerKeeper)
}

channelOrder = channeltypes.ORDERED

cbs.OnChanUpgradeOpen(
suite.chainA.GetContext(),
path.EndpointA.ChannelConfig.PortID,
path.EndpointA.ChannelID,
channeltypes.ORDERED,
channelOrder,
[]string{path.EndpointA.ConnectionID},
counterpartyVersion,
)
Expand Down
7 changes: 6 additions & 1 deletion modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() {
expPass bool
}{
{
"success", func() {}, true,
"success w/ ORDERED channel", func() {}, true,
},
{
"success w/ UNORDERED channel", func() {
channel.Ordering = channeltypes.UNORDERED
}, true,
},
{
"account address generation is block dependent", func() {
Expand Down

0 comments on commit f23ba98

Please sign in to comment.