From 0fa2978b0edad338f995790b5ab3a517ff302351 Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Wed, 24 Aug 2022 11:17:27 +0100 Subject: [PATCH] Fix ICA tests between versions v0.3.2 and v0.1.3 (#2082) --- e2e/interchain_accounts_test.go | 19 +++++++++++++++++-- e2e/testconfig/testconfig.go | 16 ++++++++++++++++ e2e/testsuite/testsuite.go | 8 ++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/e2e/interchain_accounts_test.go b/e2e/interchain_accounts_test.go index e52f3f26b1e..d01d1c1891d 100644 --- a/e2e/interchain_accounts_test.go +++ b/e2e/interchain_accounts_test.go @@ -9,11 +9,13 @@ import ( "github.com/strangelove-ventures/ibctest/ibc" "github.com/strangelove-ventures/ibctest/test" "github.com/stretchr/testify/suite" + "golang.org/x/mod/semver" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types" + "github.com/cosmos/ibc-go/e2e/testconfig" "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" @@ -33,6 +35,7 @@ type InterchainAccountsTestSuite struct { // RegisterInterchainAccount will attempt to register an interchain account on the counterparty chain. func (s *InterchainAccountsTestSuite) RegisterInterchainAccount(ctx context.Context, chain *cosmos.CosmosChain, user *ibctest.User, msgRegisterAccount *intertxtypes.MsgRegisterAccount) error { txResp, err := s.BroadcastMessages(ctx, chain, user, msgRegisterAccount) + s.Require().NoError(err) s.AssertValidTxResponse(txResp) return err } @@ -44,6 +47,18 @@ func (s *InterchainAccountsTestSuite) RegisterCounterPartyPayee(ctx context.Cont return s.BroadcastMessages(ctx, chain, user, msg) } +// getICAVersion returns the version which should be used in the MsgRegisterAccount broadcast from the +// controller chain. +func getICAVersion(chainAVersion, chainBVersion string) string { + chainBIsGreaterThanChainA := semver.Compare(chainAVersion, chainBVersion) == -1 + if chainBIsGreaterThanChainA { + // allow version to be specified by the controller chain + return "" + } + // explicitly set the version string because the host chain might not yet support incentivized channels. + return icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) +} + func (s *InterchainAccountsTestSuite) TestMsgSubmitTx_SuccessfulTransfer() { t := s.T() ctx := context.TODO() @@ -60,7 +75,7 @@ func (s *InterchainAccountsTestSuite) TestMsgSubmitTx_SuccessfulTransfer() { var hostAccount string t.Run("register interchain account", func(t *testing.T) { - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + version := getICAVersion(testconfig.GetChainATag(), testconfig.GetChainBTag()) msgRegisterAccount := intertxtypes.NewMsgRegisterAccount(controllerAccount.Bech32Address(chainA.Config().Bech32Prefix), ibctesting.FirstConnectionID, version) err := s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterAccount) s.Require().NoError(err) @@ -154,7 +169,7 @@ func (s *InterchainAccountsTestSuite) TestMsgSubmitTx_FailedTransfer_Insufficien var hostAccount string t.Run("register interchain account", func(t *testing.T) { - version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) + version := getICAVersion(testconfig.GetChainATag(), testconfig.GetChainBTag()) msgRegisterAccount := intertxtypes.NewMsgRegisterAccount(controllerAccount.Bech32Address(chainA.Config().Bech32Prefix), ibctesting.FirstConnectionID, version) err := s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterAccount) s.Require().NoError(err) diff --git a/e2e/testconfig/testconfig.go b/e2e/testconfig/testconfig.go index 9128eed9bf8..4e87e6f0cc0 100644 --- a/e2e/testconfig/testconfig.go +++ b/e2e/testconfig/testconfig.go @@ -90,6 +90,22 @@ func FromEnv() TestConfig { } } +func GetChainATag() string { + chainATag, ok := os.LookupEnv(ChainATagEnv) + if !ok { + panic(fmt.Sprintf("no environment variable specified for %s", ChainATagEnv)) + } + return chainATag +} + +func GetChainBTag() string { + chainBTag, ok := os.LookupEnv(ChainBTagEnv) + if !ok { + return GetChainATag() + } + return chainBTag +} + // ChainOptions stores chain configurations for the chains that will be // created for the tests. They can be modified by passing ChainOptionConfiguration // to E2ETestSuite.GetChains. diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 6592590a26b..ea1a72adb02 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -31,6 +31,11 @@ const ( ChainARelayerName = "rlyA" // ChainBRelayerName is the name given to the relayer wallet on ChainB ChainBRelayerName = "rlyB" + + // emptyLogs is the string value returned from `BroadcastMessages`. There are some situations in which + // the result is empty, when this happens we include the raw logs instead to get as much information + // amount the failure as possible. + emptyLogs = "[]" ) // E2ETestSuite has methods and functionality which can be shared among all test suites. @@ -297,6 +302,9 @@ func (s *E2ETestSuite) initGRPCClients(chain *cosmos.CosmosChain) { // has non-empty values. func (s *E2ETestSuite) AssertValidTxResponse(resp sdk.TxResponse) { respLogsMsg := resp.Logs.String() + if respLogsMsg == emptyLogs { + respLogsMsg = resp.RawLog + } s.Require().NotEqual(int64(0), resp.GasUsed, respLogsMsg) s.Require().NotEqual(int64(0), resp.GasWanted, respLogsMsg) s.Require().NotEmpty(resp.Events, respLogsMsg)