Skip to content

Commit

Permalink
address feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Apr 19, 2023
1 parent 2f06da4 commit 5ba660d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
5 changes: 2 additions & 3 deletions e2e/tests/interchain_accounts/intertx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ type InterTxTestSuite struct {
}

// RegisterInterchainAccount will attempt to register an interchain account on the counterparty chain.
func (s *InterTxTestSuite) RegisterInterchainAccount(ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, msgRegisterAccount *intertxtypes.MsgRegisterAccount) {
txResp := s.BroadcastMessages(ctx, chain, user, msgRegisterAccount)
s.AssertTxSuccess(txResp)
func (s *InterTxTestSuite) RegisterInterchainAccount(ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, msgRegisterAccount *intertxtypes.MsgRegisterAccount) sdk.TxResponse {
return s.BroadcastMessages(ctx, chain, user, msgRegisterAccount)
}

func (s *InterTxTestSuite) TestMsgSubmitTx_SuccessfulTransfer() {
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/transfer/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (suite *AuthzTransferTestSuite) TestAuthz_MsgTransfer_Succeeds() {
}

resp := suite.BroadcastMessages(context.TODO(), chainA, granteeWallet, msgExec)
suite.AssertTxFailure(resp, authz.ErrNoAuthorizationFound.Error())
suite.AssertTxFailure(resp, authz.ErrNoAuthorizationFound)
})
}

Expand Down Expand Up @@ -248,7 +248,7 @@ func (suite *AuthzTransferTestSuite) TestAuthz_InvalidTransferAuthorizations() {
}

resp := suite.BroadcastMessages(context.TODO(), chainA, granteeWallet, msgExec)
suite.AssertTxFailure(resp, sdkerrors.ErrInsufficientFunds.Error())
suite.AssertTxFailure(resp, sdkerrors.ErrInsufficientFunds)
})

t.Run("verify granter wallet amount", func(t *testing.T) {
Expand Down Expand Up @@ -300,7 +300,7 @@ func (suite *AuthzTransferTestSuite) TestAuthz_InvalidTransferAuthorizations() {
}

resp := suite.BroadcastMessages(context.TODO(), chainA, granteeWallet, msgExec)
suite.AssertTxFailure(resp, sdkerrors.ErrInvalidAddress.Error())
suite.AssertTxFailure(resp, sdkerrors.ErrInvalidAddress)
})
})
}
Expand Down
3 changes: 2 additions & 1 deletion e2e/tests/transfer/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"

"github.com/strangelove-ventures/interchaintest/v7/ibc"
test "github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -417,7 +418,7 @@ func (s *TransferTestSuite) TestMsgTransfer_WithMemo() {
s.AssertTxSuccess(transferTxResp)
} else {
s.Require().Equal(uint32(2), transferTxResp.Code)
s.AssertTxFailure(transferTxResp, "errUnknownField")
s.Require().Contains("errUnknownField", transferTxResp.RawLog)
}
})

Expand Down
6 changes: 4 additions & 2 deletions e2e/tests/transfer/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() {
})

t.Run("send packet localhost ibc transfer", func(t *testing.T) {
var err error
txResp := s.Transfer(ctx, chainA, userAWallet, transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), testvalues.DefaultTransferAmount(chainADenom), userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), clienttypes.NewHeight(1, 100), 0, "")
s.AssertTxSuccess(txResp)

events := testsuite.ABCIToSDKEvents(txResp.Events)
packet, err := ibctesting.ParsePacketFromEvents(events)
packet, err = ibctesting.ParsePacketFromEvents(events)
s.Require().NoError(err)
s.Require().NotNil(packet)
})
Expand All @@ -132,13 +133,14 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() {
})

t.Run("recv packet localhost ibc transfer", func(t *testing.T) {
var err error
msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress())

txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket)
s.AssertTxSuccess(txResp)

events := testsuite.ABCIToSDKEvents(txResp.Events)
ack, err := ibctesting.ParseAckFromEvents(events)
ack, err = ibctesting.ParseAckFromEvents(events)
s.Require().NoError(err)
s.Require().NotNil(ack)
})
Expand Down
7 changes: 6 additions & 1 deletion e2e/tests/upgrades/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (s *UpgradeTestSuite) TestV5ToV6ChainUpgrade() {
t.Run("register interchain account", func(t *testing.T) {
version := getICAVersion(testconfig.GetChainATag(), testconfig.GetChainBTag())
msgRegisterAccount := intertxtypes.NewMsgRegisterAccount(controllerAccount.FormattedAddress(), ibctesting.FirstConnectionID, version)
txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount)
txResp := s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterAccount)
s.AssertTxSuccess(txResp)
})

Expand Down Expand Up @@ -625,6 +625,11 @@ func (s *UpgradeTestSuite) TestV7ChainUpgradeAddLocalhost() {
})
}

// RegisterInterchainAccount will attempt to register an interchain account on the counterparty chain.
func (s *UpgradeTestSuite) RegisterInterchainAccount(ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, msgRegisterAccount *intertxtypes.MsgRegisterAccount) sdk.TxResponse {
return s.BroadcastMessages(ctx, chain, user, msgRegisterAccount)
}

// getICAVersion returns the version which should be used in the MsgRegisterAccount broadcast from the
// controller chain.
func getICAVersion(chainAVersion, chainBVersion string) string {
Expand Down
16 changes: 9 additions & 7 deletions e2e/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -91,17 +92,18 @@ func containsMessage(s string, messages []string) bool {
return false
}

// TODO: Maybe Allow specified error code too, see ensure ics20 transfer fails in base test (and there's one more)
func (s *E2ETestSuite) AssertTxFailure(resp sdk.TxResponse, expectedMsg string) {
errorMsg := fmt.Sprintf("expected tx to fail with error: %s, got: %s", expectedMsg, resp.RawLog)
s.Require().NotEqual(resp.Code, 0)
s.Require().Contains(resp.RawLog, expectedMsg, errorMsg)
// AssertTxFailure verifies that an sdk.TxResponse has failed.
func (s *E2ETestSuite) AssertTxFailure(resp sdk.TxResponse, expectedError *errorsmod.Error) {
errorMsg := fmt.Sprintf("%+v", resp)
s.Require().Equal(resp.Code, expectedError.ABCICode(), errorMsg)
s.Require().Equal(resp.Codespace, expectedError.Codespace(), errorMsg)
s.Require().Contains(resp.RawLog, expectedError.Error(), errorMsg)
}

// AssertTxSuccess verifies that an sdk.TxResponse
// has non-empty values.
// AssertTxSuccess verifies that an sdk.TxResponse has succeeded.
func (s *E2ETestSuite) AssertTxSuccess(resp sdk.TxResponse) {
errorMsg := fmt.Sprintf("%+v", resp)
s.Require().Equal(resp.Code, uint32(0), errorMsg)
s.Require().NotEmpty(resp.TxHash, errorMsg)
s.Require().NotEqual(int64(0), resp.GasUsed, errorMsg)
s.Require().NotEqual(int64(0), resp.GasWanted, errorMsg)
Expand Down

0 comments on commit 5ba660d

Please sign in to comment.