Skip to content
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

e2e: ordered ica channel is upgraded to unordered #5616

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we wanna rm these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, im waiting for another relayer image to hopefully be able to enable this logic, as currently this test fails with this logic in (for some reason)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so im keeping it in but commented out for now :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah gotcha, someone was bound to leave this comment 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we open an issue to track? Feels like something that could get lost in the weeds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can open an issue to track this!

// // 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linking #5611

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)
Comment on lines +525 to +533
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is waiting for a while not possible here? I.e similar to Carlos's PR

s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB), "failed to wait for blocks")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was part of the debugging efforts actually, so this kind of polling made more sense. basically the situation was that if we tried to do a transfer before upgrading the ICA channel, the test would fail at hanging on ChanUpgradeAck, thus the polling. I'd also be in favour of leaving this in for now until we get a relayer image that is verified to not have a regression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm as long as its tracked!

})
}
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
Loading