From fb191759310458f54c32256c8bb2edca896adda7 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 6 Feb 2023 14:04:29 +0100 Subject: [PATCH 01/12] use temporary relayer tag for e2e testing localhost --- e2e/scripts/run-e2e.sh | 2 +- e2e/testconfig/testconfig.go | 2 +- e2e/testsuite/relayer.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/scripts/run-e2e.sh b/e2e/scripts/run-e2e.sh index 2703dd50e0d..e0afbe5abbf 100755 --- a/e2e/scripts/run-e2e.sh +++ b/e2e/scripts/run-e2e.sh @@ -13,7 +13,7 @@ export CHAIN_BINARY="${CHAIN_BINARY:-simd}" # context for building the image is one directory up. if [ "${CI:-}" != "true" ] then - (cd ..; docker build . -t "${CHAIN_IMAGE}:${CHAIN_A_TAG}") + (cd ..; docker build . -t "${CHAIN_IMAGE}:${CHAIN_A_TAG}" --build-arg="IBC_GO_VERSION=${CHAIN_A_TAG}") fi go test -v ./tests/... --run ${ENTRY_POINT} -testify.m ^${TEST}$ diff --git a/e2e/testconfig/testconfig.go b/e2e/testconfig/testconfig.go index 6c96c5942ba..226833fab67 100644 --- a/e2e/testconfig/testconfig.go +++ b/e2e/testconfig/testconfig.go @@ -89,7 +89,7 @@ func FromEnv() TestConfig { } // TODO: remove hard coded value - rlyTag = "andrew-tendermint_v0.37" + rlyTag = "latest" chainAImage := getChainImage(chainBinary) specifiedChainImage, ok := os.LookupEnv(ChainImageEnv) diff --git a/e2e/testsuite/relayer.go b/e2e/testsuite/relayer.go index dcf20a15548..f6175d7bbed 100644 --- a/e2e/testsuite/relayer.go +++ b/e2e/testsuite/relayer.go @@ -13,7 +13,7 @@ import ( ) const ( - cosmosRelayerRepository = "ghcr.io/cosmos/relayer" + cosmosRelayerRepository = "damiannolan/rly" cosmosRelayerUser = "100:1000" // docker run -it --rm --entrypoint echo ghcr.io/cosmos/relayer "$(id -u):$(id -g)" ) From 6e55843acf2a23d309c77b24b528694dd3977382 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 7 Feb 2023 10:27:51 +0100 Subject: [PATCH 02/12] WIP commiting --- e2e/tests/transfer/localhost_test.go | 151 +++++++++++++++++++++++++++ e2e/testsuite/testsuite.go | 1 + go.mod | 2 +- 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 e2e/tests/transfer/localhost_test.go diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go new file mode 100644 index 00000000000..1b81a950e81 --- /dev/null +++ b/e2e/tests/transfer/localhost_test.go @@ -0,0 +1,151 @@ +package transfer + +import ( + "context" + "testing" + + transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + "github.com/cosmos/ibc-go/e2e/testvalues" + test "github.com/strangelove-ventures/interchaintest/v7/testutil" +) + +// TestMsgTransfer_Localhost creates two wallets on a single chain and performs MsgTransfers back and forth +// to ensure ibc functions as expected on localhost. This test is largely the same as TestMsgTransfer_Succeeds_Nonincentivized +// except that chain B is replaced with an additional wallet on chainA. +func (s *TransferTestSuite) TestMsgTransfer_Localhost() { + t := s.T() + ctx := context.TODO() + + _, _ = s.SetupChainsRelayerAndChannel(ctx, transferChannelOptions()) + chainA, _ := s.GetChains() + + // chainADenom := chainA.Config().Denom + rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + + t.Run("channel open init localhost", func(t *testing.T) { + msgChannelOpenInit := channeltypes.NewMsgChannelOpenInit( + transfertypes.PortID, transfertypes.Version, + channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, + transfertypes.PortID, rlyWallet.FormattedAddress(), + ) + + s.Require().NoError(msgChannelOpenInit.ValidateBasic()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenInit) + s.AssertValidTxResponse(txResp) + s.Require().NoError(err) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + }) + + t.Run("channel open try localhost", func(t *testing.T) { + msgChannelOpenTry := channeltypes.NewMsgChannelOpenTry( + transfertypes.PortID, transfertypes.Version, + channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, + transfertypes.PortID, "channel-1", // TODO: parse channel ID from response + transfertypes.Version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + _, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenTry) + s.Require().NoError(err) + // s.AssertValidTxResponse(txResp) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + }) + + t.Run("channel open ack localhost", func(t *testing.T) { + msgChannelOpenAck := channeltypes.NewMsgChannelOpenAck( + transfertypes.PortID, "channel-1", // TODO: Parse channel ID from response + "channel-2", transfertypes.Version, + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + _, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenAck) + s.Require().NoError(err) + // s.AssertValidTxResponse(txResp) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + }) + + t.Run("channel open confirm localhost", func(t *testing.T) { + msgChannelOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + transfertypes.PortID, "channel-2", + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + _, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenConfirm) + s.Require().NoError(err) + // s.AssertValidTxResponse(txResp) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + }) + + t.Run("query localhost transfer channel", func(t *testing.T) { + channel, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, "channel-1") + s.Require().NoError(err) + s.Require().NotNil(channel) + + t.Logf("output channel response: %v", channel) + }) + + // t.Run("localhost IBC token transfer", func(t *testing.T) { + // transferTxResp, err := s.Transfer(ctx, chainA, chainAWallet1, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAWallet1.FormattedAddress(), chainAWallet2.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, "") + // s.Require().NoError(err) + // s.AssertValidTxResponse(transferTxResp) + // }) + + // t.Run("tokens are escrowed", func(t *testing.T) { + // actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet1) + // s.Require().NoError(err) + + // expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount + // s.Require().Equal(expected, actualBalance) + // }) + + // t.Run("start relayer", func(t *testing.T) { + // s.StartRelayer(relayer) + // }) + + // ibcToken := testsuite.GetIBCToken(chainADenom, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID) + + // t.Run("packets are relayed", func(t *testing.T) { + // s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1) + + // actualBalance, err := chainA.GetBalance(ctx, chainAWallet2.FormattedAddress(), ibcToken.IBCDenom()) + // s.Require().NoError(err) + + // expected := testvalues.IBCTransferAmount + // s.Require().Equal(expected, actualBalance) + // }) + + // t.Run("non-native IBC token transfer using localhost receiver is source of tokens", func(t *testing.T) { + // transferTxResp, err := s.Transfer(ctx, chainA, chainAWallet2, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, testvalues.DefaultTransferAmount(ibcToken.IBCDenom()), chainAWallet2.FormattedAddress(), chainAWallet1.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, "") + // s.Require().NoError(err) + // s.AssertValidTxResponse(transferTxResp) + // }) + + // t.Run("tokens are escrowed", func(t *testing.T) { + // actualBalance, err := chainA.GetBalance(ctx, chainAWallet2.FormattedAddress(), ibcToken.IBCDenom()) + // s.Require().NoError(err) + + // s.Require().Equal(int64(0), actualBalance) + // }) + + // s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA), "failed to wait for blocks") + + // t.Run("packets are relayed", func(t *testing.T) { + // s.AssertPacketRelayed(ctx, chainA, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, 1) + + // actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet1) + // s.Require().NoError(err) + + // expected := testvalues.StartingTokenAmount + // s.Require().Equal(expected, actualBalance) + // }) +} diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 23558bae5e4..d38ee47d8af 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -403,6 +403,7 @@ func (s *E2ETestSuite) InitGRPCClients(chain *cosmos.CosmosChain) { // AssertValidTxResponse verifies that an sdk.TxResponse // has non-empty values. func (s *E2ETestSuite) AssertValidTxResponse(resp sdk.TxResponse) { + s.T().Logf("response dump: %v", resp) respLogsMsg := resp.Logs.String() if respLogsMsg == emptyLogs { respLogsMsg = resp.RawLog diff --git a/go.mod b/go.mod index 24c60c0705c..692c949614c 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/stretchr/testify v1.8.1 github.com/tendermint/tendermint v0.37.0-rc2 github.com/tendermint/tm-db v0.6.7 - golang.org/x/exp v0.0.0-20221019170559-20944726eadf google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef google.golang.org/grpc v1.52.3 google.golang.org/protobuf v1.28.1 @@ -147,6 +146,7 @@ require ( go.etcd.io/bbolt v1.3.6 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.4.0 // indirect + golang.org/x/exp v0.0.0-20221019170559-20944726eadf // indirect golang.org/x/net v0.4.0 // indirect golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect golang.org/x/sys v0.3.0 // indirect From cd72d064a2aa78c925c843a694d113b2bd30e73c Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 7 Feb 2023 12:52:20 +0100 Subject: [PATCH 03/12] updating codec and handling txResp --- e2e/tests/transfer/localhost_test.go | 54 ++++++++++++++++++---------- e2e/testsuite/codec.go | 2 ++ e2e/testsuite/testsuite.go | 4 +-- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 1b81a950e81..f5d1e961efd 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -4,6 +4,8 @@ import ( "context" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/gogoproto/proto" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" @@ -13,6 +15,24 @@ import ( test "github.com/strangelove-ventures/interchaintest/v7/testutil" ) +func parseChannelIDFromResponse(res sdk.TxResponse) string { + var txMsgData sdk.TxMsgData + if err := proto.Unmarshal([]byte(res.Data), &txMsgData); err != nil { + panic(err) + } + + for _, msgResp := range txMsgData.MsgResponses { + switch res := msgResp.GetCachedValue().(type) { + case *channeltypes.MsgChannelOpenInitResponse: + return res.ChannelId + case *channeltypes.MsgChannelOpenTryResponse: + // TODO: return channel id + } + } + + return "" +} + // TestMsgTransfer_Localhost creates two wallets on a single chain and performs MsgTransfers back and forth // to ensure ibc functions as expected on localhost. This test is largely the same as TestMsgTransfer_Succeeds_Nonincentivized // except that chain B is replaced with an additional wallet on chainA. @@ -38,10 +58,8 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { s.Require().NoError(msgChannelOpenInit.ValidateBasic()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenInit) - s.AssertValidTxResponse(txResp) s.Require().NoError(err) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + s.AssertValidTxResponse(txResp) }) t.Run("channel open try localhost", func(t *testing.T) { @@ -52,11 +70,9 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { transfertypes.Version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) - _, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenTry) + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenTry) s.Require().NoError(err) - // s.AssertValidTxResponse(txResp) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + s.AssertValidTxResponse(txResp) }) t.Run("channel open ack localhost", func(t *testing.T) { @@ -66,11 +82,9 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) - _, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenAck) + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenAck) s.Require().NoError(err) - // s.AssertValidTxResponse(txResp) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + s.AssertValidTxResponse(txResp) }) t.Run("channel open confirm localhost", func(t *testing.T) { @@ -79,19 +93,21 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) - _, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenConfirm) + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenConfirm) s.Require().NoError(err) - // s.AssertValidTxResponse(txResp) - - s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + s.AssertValidTxResponse(txResp) }) - t.Run("query localhost transfer channel", func(t *testing.T) { - channel, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, "channel-1") + t.Run("query localhost transfer channel ends", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, "channel-1") + s.Require().NoError(err) + s.Require().NotNil(channelEndA) + + channelEndB, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, "channel-2") s.Require().NoError(err) - s.Require().NotNil(channel) + s.Require().NotNil(channelEndB) - t.Logf("output channel response: %v", channel) + s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) }) // t.Run("localhost IBC token transfer", func(t *testing.T) { diff --git a/e2e/testsuite/codec.go b/e2e/testsuite/codec.go index db0fa340b6c..65c59918234 100644 --- a/e2e/testsuite/codec.go +++ b/e2e/testsuite/codec.go @@ -15,6 +15,7 @@ import ( feetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" simappparams "github.com/cosmos/ibc-go/v7/testing/simapp/params" ) @@ -42,6 +43,7 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, simappparams.EncodingConfig) { authz.RegisterInterfaces(cfg.InterfaceRegistry) transfertypes.RegisterInterfaces(cfg.InterfaceRegistry) clienttypes.RegisterInterfaces(cfg.InterfaceRegistry) + channeltypes.RegisterInterfaces(cfg.InterfaceRegistry) cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) return cdc, cfg diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index d38ee47d8af..88686c08594 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -2,7 +2,6 @@ package testsuite import ( "context" - "errors" "fmt" "strconv" "strings" @@ -403,7 +402,6 @@ func (s *E2ETestSuite) InitGRPCClients(chain *cosmos.CosmosChain) { // AssertValidTxResponse verifies that an sdk.TxResponse // has non-empty values. func (s *E2ETestSuite) AssertValidTxResponse(resp sdk.TxResponse) { - s.T().Logf("response dump: %v", resp) respLogsMsg := resp.Logs.String() if respLogsMsg == emptyLogs { respLogsMsg = resp.RawLog @@ -550,7 +548,7 @@ func (s *E2ETestSuite) QueryModuleAccountAddress(ctx context.Context, moduleName } moduleAccount, ok := account.(authtypes.ModuleAccountI) if !ok { - return nil, errors.New(fmt.Sprintf("failed to cast account: %T as ModuleAccount", moduleAccount)) + return nil, fmt.Errorf("failed to cast account: %T as ModuleAccount", moduleAccount) } return moduleAccount.GetAddress(), nil From 5cef091c09d8fb822300b927466eff45ddeb5601 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 7 Feb 2023 15:23:19 +0100 Subject: [PATCH 04/12] WIP scaffold happy path out --- e2e/tests/transfer/localhost_test.go | 104 +++++++++++++++------------ 1 file changed, 59 insertions(+), 45 deletions(-) diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index f5d1e961efd..4b71d111379 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -11,6 +11,7 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" test "github.com/strangelove-ventures/interchaintest/v7/testutil" ) @@ -43,8 +44,13 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { _, _ = s.SetupChainsRelayerAndChannel(ctx, transferChannelOptions()) chainA, _ := s.GetChains() - // chainADenom := chainA.Config().Denom + chainADenom := chainA.Config().Denom + rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + + var packet channeltypes.Packet s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") @@ -63,10 +69,11 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { }) t.Run("channel open try localhost", func(t *testing.T) { + // TODO: parse channel ID from response msgChannelOpenTry := channeltypes.NewMsgChannelOpenTry( transfertypes.PortID, transfertypes.Version, channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, - transfertypes.PortID, "channel-1", // TODO: parse channel ID from response + transfertypes.PortID, "channel-1", transfertypes.Version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) @@ -76,8 +83,9 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { }) t.Run("channel open ack localhost", func(t *testing.T) { + // TODO: Parse channel ID from response msgChannelOpenAck := channeltypes.NewMsgChannelOpenAck( - transfertypes.PortID, "channel-1", // TODO: Parse channel ID from response + transfertypes.PortID, "channel-1", "channel-2", transfertypes.Version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) @@ -110,58 +118,64 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) }) - // t.Run("localhost IBC token transfer", func(t *testing.T) { - // transferTxResp, err := s.Transfer(ctx, chainA, chainAWallet1, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAWallet1.FormattedAddress(), chainAWallet2.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, "") - // s.Require().NoError(err) - // s.AssertValidTxResponse(transferTxResp) - // }) - - // t.Run("tokens are escrowed", func(t *testing.T) { - // actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet1) - // s.Require().NoError(err) - - // expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount - // s.Require().Equal(expected, actualBalance) - // }) + t.Run("send packet - localhost ibc transfer", func(t *testing.T) { + txResp, err := s.Transfer(ctx, chainA, userAWallet, transfertypes.PortID, "channel-1", testvalues.DefaultTransferAmount(chainADenom), userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), clienttypes.NewHeight(1, 100), 0, "") + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) - // t.Run("start relayer", func(t *testing.T) { - // s.StartRelayer(relayer) - // }) + // t.Logf("transfer events: %v", txResp.Events) + // var events sdk.Events + // for _, evt := range txResp.Events { + // var attributes []sdk.Attribute + // for _, attr := range evt.GetAttributes() { + // attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) + // } - // ibcToken := testsuite.GetIBCToken(chainADenom, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID) + // events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) + // } - // t.Run("packets are relayed", func(t *testing.T) { - // s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1) + // packet, err = ibctesting.ParsePacketFromEvents(events) + // s.Require().NoError(err) + // s.Require().NotNil(packet) + }) - // actualBalance, err := chainA.GetBalance(ctx, chainAWallet2.FormattedAddress(), ibcToken.IBCDenom()) - // s.Require().NoError(err) + t.Run("tokens are escrowed", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, userAWallet) + s.Require().NoError(err) - // expected := testvalues.IBCTransferAmount - // s.Require().Equal(expected, actualBalance) - // }) + expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance) + }) - // t.Run("non-native IBC token transfer using localhost receiver is source of tokens", func(t *testing.T) { - // transferTxResp, err := s.Transfer(ctx, chainA, chainAWallet2, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, testvalues.DefaultTransferAmount(ibcToken.IBCDenom()), chainAWallet2.FormattedAddress(), chainAWallet1.FormattedAddress(), s.GetTimeoutHeight(ctx, chainA), 0, "") - // s.Require().NoError(err) - // s.AssertValidTxResponse(transferTxResp) - // }) + t.Run("recv packet - localhost ibc transfer", func(t *testing.T) { + packet = channeltypes.NewPacket(transfertypes.NewFungibleTokenPacketData(chainADenom, "10000", userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), "").GetBytes(), 1, "transfer", "channel-1", "transfer", "channel-2", clienttypes.NewHeight(1, 100), 0) + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) - // t.Run("tokens are escrowed", func(t *testing.T) { - // actualBalance, err := chainA.GetBalance(ctx, chainAWallet2.FormattedAddress(), ibcToken.IBCDenom()) - // s.Require().NoError(err) + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) - // s.Require().Equal(int64(0), actualBalance) - // }) + t.Run("acknowledge packet - localhost ibc transfer", func(t *testing.T) { + packet = channeltypes.NewPacket(transfertypes.NewFungibleTokenPacketData(chainADenom, "10000", userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), "").GetBytes(), 1, "transfer", "channel-1", "transfer", "channel-2", clienttypes.NewHeight(1, 100), 0) + msgAcknowledgement := channeltypes.NewMsgAcknowledgement( + packet, channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) - // s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA), "failed to wait for blocks") + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) - // t.Run("packets are relayed", func(t *testing.T) { - // s.AssertPacketRelayed(ctx, chainA, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, 1) + t.Run("packets are relayed", func(t *testing.T) { + s.AssertPacketRelayed(ctx, chainA, transfertypes.PortID, "channel-1", 1) - // actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet1) - // s.Require().NoError(err) + ibcToken := testsuite.GetIBCToken(chainADenom, transfertypes.PortID, "channel-2") + actualBalance, err := chainA.GetBalance(ctx, userBWallet.FormattedAddress(), ibcToken.IBCDenom()) + s.Require().NoError(err) - // expected := testvalues.StartingTokenAmount - // s.Require().Equal(expected, actualBalance) - // }) + expected := testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance) + }) } From 36a55fca9f30f566bdb76b9e429aa75db9a4c5c5 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 7 Feb 2023 17:28:01 +0100 Subject: [PATCH 05/12] adding some temporary todos --- e2e/tests/transfer/localhost_test.go | 39 +++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 4b71d111379..3b9d401377e 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -16,24 +16,6 @@ import ( test "github.com/strangelove-ventures/interchaintest/v7/testutil" ) -func parseChannelIDFromResponse(res sdk.TxResponse) string { - var txMsgData sdk.TxMsgData - if err := proto.Unmarshal([]byte(res.Data), &txMsgData); err != nil { - panic(err) - } - - for _, msgResp := range txMsgData.MsgResponses { - switch res := msgResp.GetCachedValue().(type) { - case *channeltypes.MsgChannelOpenInitResponse: - return res.ChannelId - case *channeltypes.MsgChannelOpenTryResponse: - // TODO: return channel id - } - } - - return "" -} - // TestMsgTransfer_Localhost creates two wallets on a single chain and performs MsgTransfers back and forth // to ensure ibc functions as expected on localhost. This test is largely the same as TestMsgTransfer_Succeeds_Nonincentivized // except that chain B is replaced with an additional wallet on chainA. @@ -123,6 +105,7 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { s.Require().NoError(err) s.AssertValidTxResponse(txResp) + // TODO: revisit parsing packet from events // t.Logf("transfer events: %v", txResp.Events) // var events sdk.Events // for _, evt := range txResp.Events { @@ -148,6 +131,7 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { }) t.Run("recv packet - localhost ibc transfer", func(t *testing.T) { + // TODO: currently building the packet manually, should be possible to parse from events packet = channeltypes.NewPacket(transfertypes.NewFungibleTokenPacketData(chainADenom, "10000", userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), "").GetBytes(), 1, "transfer", "channel-1", "transfer", "channel-2", clienttypes.NewHeight(1, 100), 0) msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) @@ -157,6 +141,7 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { }) t.Run("acknowledge packet - localhost ibc transfer", func(t *testing.T) { + // TODO: currently building the packet manually, should be possible to parse from events packet = channeltypes.NewPacket(transfertypes.NewFungibleTokenPacketData(chainADenom, "10000", userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), "").GetBytes(), 1, "transfer", "channel-1", "transfer", "channel-2", clienttypes.NewHeight(1, 100), 0) msgAcknowledgement := channeltypes.NewMsgAcknowledgement( packet, channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement(), @@ -179,3 +164,21 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { s.Require().Equal(expected, actualBalance) }) } + +func parseChannelIDFromResponse(res sdk.TxResponse) string { + var txMsgData sdk.TxMsgData + if err := proto.Unmarshal([]byte(res.Data), &txMsgData); err != nil { + panic(err) + } + + for _, msgResp := range txMsgData.MsgResponses { + switch res := msgResp.GetCachedValue().(type) { + case *channeltypes.MsgChannelOpenInitResponse: + return res.ChannelId + case *channeltypes.MsgChannelOpenTryResponse: + // TODO: Add channelID to response - https://github.com/cosmos/ibc-go/pull/3117 + } + } + + return "" +} From 5cb965a0de1e91ebecf61431ecf4c92409a08d53 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 8 Feb 2023 15:05:07 +0100 Subject: [PATCH 06/12] adding msg response unmarshalling, and adding interchain accounts handshake test --- .../interchain_accounts/localhost_test.go | 105 ++++++++++++++++++ e2e/tests/transfer/localhost_test.go | 62 ++++------- e2e/testsuite/codec.go | 32 ++++++ 3 files changed, 161 insertions(+), 38 deletions(-) create mode 100644 e2e/tests/interchain_accounts/localhost_test.go diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go new file mode 100644 index 00000000000..7797a205772 --- /dev/null +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -0,0 +1,105 @@ +package interchain_accounts + +import ( + "context" + "testing" + + controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" + test "github.com/strangelove-ventures/interchaintest/v7/testutil" +) + +func (s *InterchainAccountsTestSuite) TestInterchainAccounts_Localhost() { + t := s.T() + ctx := context.TODO() + + _, _ = s.SetupChainsRelayerAndChannel(ctx) + chainA, _ := s.GetChains() + + // chainADenom := chainA.Config().Denom + + rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + // userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + + var ( + msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse + msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse + ) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") + + version := icatypes.NewDefaultMetadataString(connectiontypes.LocalhostID, connectiontypes.LocalhostID) + controllerPortID, err := icatypes.NewControllerPortID(userAWallet.FormattedAddress()) + s.Require().NoError(err) + + t.Run("channel open init localhost - broadcast MsgRegisterInterchainAccount", func(t *testing.T) { + msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(connectiontypes.LocalhostID, userAWallet.FormattedAddress(), version) + + txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgRegisterAccount) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) + }) + + t.Run("channel open try localhost", func(t *testing.T) { + msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( + icatypes.HostPortID, icatypes.Version, + channeltypes.ORDERED, []string{connectiontypes.LocalhostID}, + controllerPortID, msgChanOpenInitRes.GetChannelId(), + version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) + }) + + t.Run("channel open ack localhost", func(t *testing.T) { + msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( + controllerPortID, msgChanOpenInitRes.GetChannelId(), + msgChanOpenTryRes.GetChannelId(), msgChanOpenTryRes.GetVersion(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("channel open confirm localhost", func(t *testing.T) { + msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + icatypes.HostPortID, msgChanOpenTryRes.GetChannelId(), + nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), + ) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("query localhost interchain accounts channel ends", func(t *testing.T) { + channelEndA, err := s.QueryChannel(ctx, chainA, controllerPortID, msgChanOpenInitRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndA) + + t.Logf("controller channel end: %v", channelEndA) + + channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.GetChannelId()) + s.Require().NoError(err) + s.Require().NotNil(channelEndB) + + t.Logf("host channel end: %v", channelEndB) + + s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) + }) +} diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 3b9d401377e..4559f1b8713 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -4,8 +4,6 @@ import ( "context" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/gogoproto/proto" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" @@ -32,68 +30,74 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - var packet channeltypes.Packet + var ( + msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse + msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse + packet channeltypes.Packet + ) s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") t.Run("channel open init localhost", func(t *testing.T) { - msgChannelOpenInit := channeltypes.NewMsgChannelOpenInit( + msgChanOpenInit := channeltypes.NewMsgChannelOpenInit( transfertypes.PortID, transfertypes.Version, channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, transfertypes.PortID, rlyWallet.FormattedAddress(), ) - s.Require().NoError(msgChannelOpenInit.ValidateBasic()) + s.Require().NoError(msgChanOpenInit.ValidateBasic()) - txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenInit) + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenInit) s.Require().NoError(err) s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenInitRes)) }) t.Run("channel open try localhost", func(t *testing.T) { - // TODO: parse channel ID from response - msgChannelOpenTry := channeltypes.NewMsgChannelOpenTry( + msgChanOpenTry := channeltypes.NewMsgChannelOpenTry( transfertypes.PortID, transfertypes.Version, channeltypes.UNORDERED, []string{connectiontypes.LocalhostID}, - transfertypes.PortID, "channel-1", + transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), transfertypes.Version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) - txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenTry) + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenTry) s.Require().NoError(err) s.AssertValidTxResponse(txResp) + + s.Require().NoError(testsuite.UnmarshalMsgResponses(txResp, &msgChanOpenTryRes)) }) t.Run("channel open ack localhost", func(t *testing.T) { - // TODO: Parse channel ID from response - msgChannelOpenAck := channeltypes.NewMsgChannelOpenAck( - transfertypes.PortID, "channel-1", - "channel-2", transfertypes.Version, + msgChanOpenAck := channeltypes.NewMsgChannelOpenAck( + transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), + msgChanOpenTryRes.GetChannelId(), transfertypes.Version, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) - txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenAck) + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenAck) s.Require().NoError(err) s.AssertValidTxResponse(txResp) }) t.Run("channel open confirm localhost", func(t *testing.T) { - msgChannelOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( - transfertypes.PortID, "channel-2", + msgChanOpenConfirm := channeltypes.NewMsgChannelOpenConfirm( + transfertypes.PortID, msgChanOpenTryRes.GetChannelId(), nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), ) - txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChannelOpenConfirm) + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgChanOpenConfirm) s.Require().NoError(err) s.AssertValidTxResponse(txResp) }) t.Run("query localhost transfer channel ends", func(t *testing.T) { - channelEndA, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, "channel-1") + channelEndA, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, msgChanOpenInitRes.GetChannelId()) s.Require().NoError(err) s.Require().NotNil(channelEndA) - channelEndB, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, "channel-2") + channelEndB, err := s.QueryChannel(ctx, chainA, transfertypes.PortID, msgChanOpenTryRes.GetChannelId()) s.Require().NoError(err) s.Require().NotNil(channelEndB) @@ -164,21 +168,3 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { s.Require().Equal(expected, actualBalance) }) } - -func parseChannelIDFromResponse(res sdk.TxResponse) string { - var txMsgData sdk.TxMsgData - if err := proto.Unmarshal([]byte(res.Data), &txMsgData); err != nil { - panic(err) - } - - for _, msgResp := range txMsgData.MsgResponses { - switch res := msgResp.GetCachedValue().(type) { - case *channeltypes.MsgChannelOpenInitResponse: - return res.ChannelId - case *channeltypes.MsgChannelOpenTryResponse: - // TODO: Add channelID to response - https://github.com/cosmos/ibc-go/pull/3117 - } - } - - return "" -} diff --git a/e2e/testsuite/codec.go b/e2e/testsuite/codec.go index 65c59918234..0d2a8569823 100644 --- a/e2e/testsuite/codec.go +++ b/e2e/testsuite/codec.go @@ -1,8 +1,12 @@ package testsuite import ( + "encoding/hex" + "fmt" + "github.com/cosmos/cosmos-sdk/codec" sdkcodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -19,11 +23,13 @@ import ( simappparams "github.com/cosmos/ibc-go/v7/testing/simapp/params" ) +// Codec returns the global E2E protobuf codec. func Codec() *codec.ProtoCodec { cdc, _ := codecAndEncodingConfig() return cdc } +// EncodingConfig returns the global E2E encoding config. func EncodingConfig() simappparams.EncodingConfig { _, cfg := codecAndEncodingConfig() return cfg @@ -48,3 +54,29 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, simappparams.EncodingConfig) { cdc := codec.NewProtoCodec(cfg.InterfaceRegistry) return cdc, cfg } + +// UnmarshalMsgResponses attempts to unmarshal the tx msg responses into the provided message types. +func UnmarshalMsgResponses(txResp sdk.TxResponse, msgs ...codec.ProtoMarshaler) error { + cdc := Codec() + bz, err := hex.DecodeString(txResp.Data) + if err != nil { + return err + } + + var txMsgData sdk.TxMsgData + if err := cdc.Unmarshal(bz, &txMsgData); err != nil { + return err + } + + if len(msgs) != len(txMsgData.MsgResponses) { + return fmt.Errorf("expected %d message responses but got %d", len(msgs), len(txMsgData.MsgResponses)) + } + + for i, msg := range msgs { + if err := cdc.Unmarshal(txMsgData.MsgResponses[i].Value, msg); err != nil { + return err + } + } + + return nil +} From 5a9dd4edc2f854689c1ef963c7f4611079449460 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 8 Feb 2023 17:52:19 +0100 Subject: [PATCH 07/12] adding ica send packet testing, cleanup..etc --- .../interchain_accounts/localhost_test.go | 111 +++++++++++++++++- e2e/tests/transfer/localhost_test.go | 66 ++++++----- 2 files changed, 142 insertions(+), 35 deletions(-) diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index 7797a205772..954321fd19f 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -3,15 +3,22 @@ package interchain_accounts import ( "context" "testing" + "time" + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/gogoproto/proto" controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" + "github.com/strangelove-ventures/interchaintest/v7" + "github.com/strangelove-ventures/interchaintest/v7/ibc" test "github.com/strangelove-ventures/interchaintest/v7/testutil" ) @@ -22,15 +29,17 @@ func (s *InterchainAccountsTestSuite) TestInterchainAccounts_Localhost() { _, _ = s.SetupChainsRelayerAndChannel(ctx) chainA, _ := s.GetChains() - // chainADenom := chainA.Config().Denom + chainADenom := chainA.Config().Denom rlyWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) userAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) - // userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + userBWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) var ( msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse + ack []byte + packet channeltypes.Packet ) s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks") @@ -92,14 +101,104 @@ func (s *InterchainAccountsTestSuite) TestInterchainAccounts_Localhost() { s.Require().NoError(err) s.Require().NotNil(channelEndA) - t.Logf("controller channel end: %v", channelEndA) - channelEndB, err := s.QueryChannel(ctx, chainA, icatypes.HostPortID, msgChanOpenTryRes.GetChannelId()) s.Require().NoError(err) s.Require().NotNil(channelEndB) - t.Logf("host channel end: %v", channelEndB) - s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) }) + + t.Run("verify interchain account registration and deposit funds", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + walletAmount := ibc.WalletAmount{ + Address: interchainAccAddress, + Amount: testvalues.StartingTokenAmount, + Denom: chainADenom, + } + + s.Require().NoError(chainA.SendFunds(ctx, interchaintest.FaucetAccountKeyName, walletAmount)) + }) + + t.Run("send packet localhost interchain accounts", func(t *testing.T) { + interchainAccAddress, err := s.QueryInterchainAccount(ctx, chainA, userAWallet.FormattedAddress(), connectiontypes.LocalhostID) + s.Require().NoError(err) + s.Require().NotZero(len(interchainAccAddress)) + + msgSend := &banktypes.MsgSend{ + FromAddress: interchainAccAddress, + ToAddress: userBWallet.FormattedAddress(), + Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainADenom)), + } + + cdc := testsuite.Codec() + bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgSend}) + s.Require().NoError(err) + + packetData := icatypes.InterchainAccountPacketData{ + Type: icatypes.EXECUTE_TX, + Data: bz, + Memo: "e2e", + } + + msgSendTx := controllertypes.NewMsgSendTx(userAWallet.FormattedAddress(), connectiontypes.LocalhostID, uint64(time.Hour.Nanoseconds()), packetData) + + txResp, err := s.BroadcastMessages(ctx, chainA, userAWallet, msgSendTx) + s.AssertValidTxResponse(txResp) + s.Require().NoError(err) + + var events sdk.Events + for _, evt := range txResp.Events { + var attributes []sdk.Attribute + for _, attr := range evt.GetAttributes() { + attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) + } + + events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) + } + + packet, err = ibctesting.ParsePacketFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(packet) + }) + + t.Run("recv packet localhost interchain accounts", func(t *testing.T) { + msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + + var events sdk.Events + for _, evt := range txResp.Events { + var attributes []sdk.Attribute + for _, attr := range evt.GetAttributes() { + attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) + } + + events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) + } + + ack, err = ibctesting.ParseAckFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(ack) + }) + + t.Run("acknowledge packet localhost interchain accounts", func(t *testing.T) { + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) + + txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) + s.Require().NoError(err) + s.AssertValidTxResponse(txResp) + }) + + t.Run("verify tokens transferred", func(t *testing.T) { + balance, err := chainA.GetBalance(ctx, userBWallet.FormattedAddress(), chainADenom) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount + s.Require().Equal(expected, balance) + }) } diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 4559f1b8713..71ca9808712 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -4,10 +4,12 @@ import ( "context" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" @@ -33,6 +35,7 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { var ( msgChanOpenInitRes channeltypes.MsgChannelOpenInitResponse msgChanOpenTryRes channeltypes.MsgChannelOpenTryResponse + ack []byte packet channeltypes.Packet ) @@ -104,26 +107,24 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { s.Require().Equal(channelEndA.GetConnectionHops(), channelEndB.GetConnectionHops()) }) - t.Run("send packet - localhost ibc transfer", func(t *testing.T) { - txResp, err := s.Transfer(ctx, chainA, userAWallet, transfertypes.PortID, "channel-1", testvalues.DefaultTransferAmount(chainADenom), userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), clienttypes.NewHeight(1, 100), 0, "") + t.Run("send packet localhost ibc transfer", func(t *testing.T) { + txResp, err := s.Transfer(ctx, chainA, userAWallet, transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), testvalues.DefaultTransferAmount(chainADenom), userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), clienttypes.NewHeight(1, 100), 0, "") s.Require().NoError(err) s.AssertValidTxResponse(txResp) - // TODO: revisit parsing packet from events - // t.Logf("transfer events: %v", txResp.Events) - // var events sdk.Events - // for _, evt := range txResp.Events { - // var attributes []sdk.Attribute - // for _, attr := range evt.GetAttributes() { - // attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) - // } - - // events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) - // } - - // packet, err = ibctesting.ParsePacketFromEvents(events) - // s.Require().NoError(err) - // s.Require().NotNil(packet) + var events sdk.Events + for _, evt := range txResp.Events { + var attributes []sdk.Attribute + for _, attr := range evt.GetAttributes() { + attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) + } + + events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) + } + + packet, err = ibctesting.ParsePacketFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(packet) }) t.Run("tokens are escrowed", func(t *testing.T) { @@ -134,23 +135,30 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { s.Require().Equal(expected, actualBalance) }) - t.Run("recv packet - localhost ibc transfer", func(t *testing.T) { - // TODO: currently building the packet manually, should be possible to parse from events - packet = channeltypes.NewPacket(transfertypes.NewFungibleTokenPacketData(chainADenom, "10000", userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), "").GetBytes(), 1, "transfer", "channel-1", "transfer", "channel-2", clienttypes.NewHeight(1, 100), 0) + t.Run("recv packet localhost ibc transfer", func(t *testing.T) { msgRecvPacket := channeltypes.NewMsgRecvPacket(packet, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgRecvPacket) s.Require().NoError(err) s.AssertValidTxResponse(txResp) + + var events sdk.Events + for _, evt := range txResp.Events { + var attributes []sdk.Attribute + for _, attr := range evt.GetAttributes() { + attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) + } + + events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) + } + + ack, err = ibctesting.ParseAckFromEvents(events) + s.Require().NoError(err) + s.Require().NotNil(ack) }) - t.Run("acknowledge packet - localhost ibc transfer", func(t *testing.T) { - // TODO: currently building the packet manually, should be possible to parse from events - packet = channeltypes.NewPacket(transfertypes.NewFungibleTokenPacketData(chainADenom, "10000", userAWallet.FormattedAddress(), userBWallet.FormattedAddress(), "").GetBytes(), 1, "transfer", "channel-1", "transfer", "channel-2", clienttypes.NewHeight(1, 100), 0) - msgAcknowledgement := channeltypes.NewMsgAcknowledgement( - packet, channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement(), - nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), - ) + t.Run("acknowledge packet localhost ibc transfer", func(t *testing.T) { + msgAcknowledgement := channeltypes.NewMsgAcknowledgement(packet, ack, nil, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress()) txResp, err := s.BroadcastMessages(ctx, chainA, rlyWallet, msgAcknowledgement) s.Require().NoError(err) @@ -158,9 +166,9 @@ func (s *TransferTestSuite) TestMsgTransfer_Localhost() { }) t.Run("packets are relayed", func(t *testing.T) { - s.AssertPacketRelayed(ctx, chainA, transfertypes.PortID, "channel-1", 1) + s.AssertPacketRelayed(ctx, chainA, transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), 1) - ibcToken := testsuite.GetIBCToken(chainADenom, transfertypes.PortID, "channel-2") + ibcToken := testsuite.GetIBCToken(chainADenom, transfertypes.PortID, msgChanOpenTryRes.GetChannelId()) actualBalance, err := chainA.GetBalance(ctx, userBWallet.FormattedAddress(), ibcToken.IBCDenom()) s.Require().NoError(err) From f1fa2f61a1c135da699d5d28dcf1921927771909 Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Tue, 14 Feb 2023 13:59:30 +0000 Subject: [PATCH 08/12] adding separate test suite for localhost transfer tests (#3144) --- e2e/tests/transfer/localhost_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 71ca9808712..604efb78f3a 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -3,23 +3,33 @@ package transfer import ( "context" "testing" + "github.com/stretchr/testify/suite" sdk "github.com/cosmos/cosmos-sdk/types" + transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + test "github.com/strangelove-ventures/interchaintest/v7/testutil" ibctesting "github.com/cosmos/ibc-go/v7/testing" "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" - test "github.com/strangelove-ventures/interchaintest/v7/testutil" ) +func TestTransferLocalhostTestSuite(t *testing.T) { + suite.Run(t, new(LocalhostTransferTestSuite)) +} + +type LocalhostTransferTestSuite struct { + *TransferTestSuite +} + // TestMsgTransfer_Localhost creates two wallets on a single chain and performs MsgTransfers back and forth // to ensure ibc functions as expected on localhost. This test is largely the same as TestMsgTransfer_Succeeds_Nonincentivized // except that chain B is replaced with an additional wallet on chainA. -func (s *TransferTestSuite) TestMsgTransfer_Localhost() { +func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { t := s.T() ctx := context.TODO() From e8cbde7746b9a6079e3715af630b79e9b68f845d Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 14 Feb 2023 16:46:39 +0100 Subject: [PATCH 09/12] add separate test suite struct for ICA localhost --- e2e/tests/interchain_accounts/localhost_test.go | 11 ++++++++++- e2e/tests/transfer/localhost_test.go | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index 954321fd19f..9edd4b13c77 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -14,6 +14,7 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" + "github.com/stretchr/testify/suite" "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" @@ -22,7 +23,15 @@ import ( test "github.com/strangelove-ventures/interchaintest/v7/testutil" ) -func (s *InterchainAccountsTestSuite) TestInterchainAccounts_Localhost() { +func TestInterchainAccountsLocalhostTestSuite(t *testing.T) { + suite.Run(t, new(LocalhostInterchainAccountsTestSuite)) +} + +type LocalhostInterchainAccountsTestSuite struct { + *InterchainAccountsTestSuite +} + +func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost() { t := s.T() ctx := context.TODO() diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 604efb78f3a..408266ea0fd 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -3,6 +3,7 @@ package transfer import ( "context" "testing" + "github.com/stretchr/testify/suite" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,8 +12,8 @@ import ( clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - test "github.com/strangelove-ventures/interchaintest/v7/testutil" ibctesting "github.com/cosmos/ibc-go/v7/testing" + test "github.com/strangelove-ventures/interchaintest/v7/testutil" "github.com/cosmos/ibc-go/e2e/testsuite" "github.com/cosmos/ibc-go/e2e/testvalues" From 8e8c34cac4a1c5f602f5f2600d9231226ed30fc3 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 14 Feb 2023 17:17:35 +0100 Subject: [PATCH 10/12] fixing testsuite embedding --- e2e/tests/interchain_accounts/localhost_test.go | 2 +- e2e/tests/transfer/localhost_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index 9edd4b13c77..e87eff2c1d7 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -28,7 +28,7 @@ func TestInterchainAccountsLocalhostTestSuite(t *testing.T) { } type LocalhostInterchainAccountsTestSuite struct { - *InterchainAccountsTestSuite + testsuite.E2ETestSuite } func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost() { diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 408266ea0fd..24b33757cf1 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -24,7 +24,7 @@ func TestTransferLocalhostTestSuite(t *testing.T) { } type LocalhostTransferTestSuite struct { - *TransferTestSuite + testsuite.E2ETestSuite } // TestMsgTransfer_Localhost creates two wallets on a single chain and performs MsgTransfers back and forth From a557dd4b34abf1e05b90e819c01a8205b5eac4c0 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 15 Feb 2023 10:42:26 +0100 Subject: [PATCH 11/12] review suggestions - events func and nits --- .../interchain_accounts/localhost_test.go | 24 ++++--------------- e2e/tests/transfer/localhost_test.go | 24 ++----------------- e2e/testsuite/events.go | 21 ++++++++++++++++ 3 files changed, 27 insertions(+), 42 deletions(-) create mode 100644 e2e/testsuite/events.go diff --git a/e2e/tests/interchain_accounts/localhost_test.go b/e2e/tests/interchain_accounts/localhost_test.go index e87eff2c1d7..bb334d4e798 100644 --- a/e2e/tests/interchain_accounts/localhost_test.go +++ b/e2e/tests/interchain_accounts/localhost_test.go @@ -158,16 +158,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( s.AssertValidTxResponse(txResp) s.Require().NoError(err) - var events sdk.Events - for _, evt := range txResp.Events { - var attributes []sdk.Attribute - for _, attr := range evt.GetAttributes() { - attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) - } - - events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) - } - + events := testsuite.ABCIToSDKEvents(txResp.Events) packet, err = ibctesting.ParsePacketFromEvents(events) s.Require().NoError(err) s.Require().NotNil(packet) @@ -180,16 +171,7 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( s.Require().NoError(err) s.AssertValidTxResponse(txResp) - var events sdk.Events - for _, evt := range txResp.Events { - var attributes []sdk.Attribute - for _, attr := range evt.GetAttributes() { - attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) - } - - events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) - } - + events := testsuite.ABCIToSDKEvents(txResp.Events) ack, err = ibctesting.ParseAckFromEvents(events) s.Require().NoError(err) s.Require().NotNil(ack) @@ -204,6 +186,8 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_Localhost( }) t.Run("verify tokens transferred", func(t *testing.T) { + s.AssertPacketRelayed(ctx, chainA, controllerPortID, msgChanOpenInitRes.GetChannelId(), 1) + balance, err := chainA.GetBalance(ctx, userBWallet.FormattedAddress(), chainADenom) s.Require().NoError(err) diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 24b33757cf1..267f3857cda 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -6,8 +6,6 @@ import ( "github.com/stretchr/testify/suite" - sdk "github.com/cosmos/cosmos-sdk/types" - transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" @@ -123,16 +121,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { s.Require().NoError(err) s.AssertValidTxResponse(txResp) - var events sdk.Events - for _, evt := range txResp.Events { - var attributes []sdk.Attribute - for _, attr := range evt.GetAttributes() { - attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) - } - - events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) - } - + events := testsuite.ABCIToSDKEvents(txResp.Events) packet, err = ibctesting.ParsePacketFromEvents(events) s.Require().NoError(err) s.Require().NotNil(packet) @@ -153,16 +142,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { s.Require().NoError(err) s.AssertValidTxResponse(txResp) - var events sdk.Events - for _, evt := range txResp.Events { - var attributes []sdk.Attribute - for _, attr := range evt.GetAttributes() { - attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) - } - - events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) - } - + events := testsuite.ABCIToSDKEvents(txResp.Events) ack, err = ibctesting.ParseAckFromEvents(events) s.Require().NoError(err) s.Require().NotNil(ack) diff --git a/e2e/testsuite/events.go b/e2e/testsuite/events.go new file mode 100644 index 00000000000..feb79372123 --- /dev/null +++ b/e2e/testsuite/events.go @@ -0,0 +1,21 @@ +package testsuite + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" +) + +// ABCIToSDKEvents converts a list of ABCI events to Cosmos SDK events. +func ABCIToSDKEvents(abciEvents []abci.Event) sdk.Events { + var events sdk.Events + for _, evt := range abciEvents { + var attributes []sdk.Attribute + for _, attr := range evt.GetAttributes() { + attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value)) + } + + events = events.AppendEvent(sdk.NewEvent(evt.GetType(), attributes...)) + } + + return events +} From 5ad7dd312efaef5ae1b53213f3e85183c4b99cc6 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 15 Feb 2023 11:21:48 +0100 Subject: [PATCH 12/12] testcase naming --- e2e/tests/transfer/localhost_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 267f3857cda..3464c1eccd1 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -156,7 +156,7 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { s.AssertValidTxResponse(txResp) }) - t.Run("packets are relayed", func(t *testing.T) { + t.Run("verify tokens transferred", func(t *testing.T) { s.AssertPacketRelayed(ctx, chainA, transfertypes.PortID, msgChanOpenInitRes.GetChannelId(), 1) ibcToken := testsuite.GetIBCToken(chainADenom, transfertypes.PortID, msgChanOpenTryRes.GetChannelId())