Skip to content

Commit

Permalink
Fix ICA tests between versions v0.3.2 and v0.1.3 (#2082)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton authored Aug 24, 2022
1 parent 05c4bfb commit 0fa2978
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
19 changes: 17 additions & 2 deletions e2e/interchain_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
}
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions e2e/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0fa2978

Please sign in to comment.