From eafa4969174dc0cb4eb1c4a2c9cfd6d1d71458b9 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 11 Aug 2022 16:24:15 +0200 Subject: [PATCH 1/3] test: e2e test for timeout of ics20 packet --- e2e/transfer_test.go | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 e2e/transfer_test.go diff --git a/e2e/transfer_test.go b/e2e/transfer_test.go new file mode 100644 index 00000000000..b82c5f6e9c5 --- /dev/null +++ b/e2e/transfer_test.go @@ -0,0 +1,77 @@ +package e2e + +import ( + "context" + "testing" + "time" + + "github.com/strangelove-ventures/ibctest/ibc" + "github.com/stretchr/testify/suite" + + "github.com/cosmos/ibc-go/e2e/testsuite" + "github.com/cosmos/ibc-go/e2e/testvalues" +) + +func TestTransferTestSuite(t *testing.T) { + suite.Run(t, new(TransferTestSuite)) +} + +type TransferTestSuite struct { + testsuite.E2ETestSuite +} + +func (s *TransferTestSuite) TestMsgTransfer_Timeout_Nonincentivized() { + t := s.T() + ctx := context.TODO() + + relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, transferChannelOptions()) + chainA, chainB := s.GetChains() + chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + chainBWalletAmount := ibc.WalletAmount{ + Address: chainBWallet.Bech32Address(chainB.Config().Bech32Prefix), // destination address + Denom: chainA.Config().Denom, + Amount: testvalues.IBCTransferAmount, + } + + t.Run("IBC transfer packet timesout", func(t *testing.T) { + tx, err := chainA.SendIBCTransfer(ctx, channelA.ChannelID, chainAWallet.KeyName, chainBWalletAmount, testvalues.ImmediatelyTimeout()) + s.Require().NoError(err) + s.Require().NoError(tx.Validate(), "source ibc transfer tx is invalid") + time.Sleep(time.Nanosecond * 1) // want it to timeout immediately + }) + + t.Run("tokens are escrowed", func(t *testing.T) { + actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) + 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) + }) + + t.Run("ensure escrowed tokens have been refunded to sender due to timeout", func(t *testing.T) { + // ensure destination address did not recieve any tokens + bal, err := s.GetChainBNativeBalance(ctx, chainBWallet) + s.Require().NoError(err) + s.Require().Equal(testvalues.StartingTokenAmount, bal) + + // ensure that the sender address has been successfully refunded the full amount + bal, err = s.GetChainANativeBalance(ctx, chainAWallet) + s.Require().NoError(err) + s.Require().Equal(testvalues.StartingTokenAmount, bal) + }) +} + +// transferChannelOptions configures both of the chains to have non-incentivized transfer channels. +func transferChannelOptions() func(options *ibc.CreateChannelOptions) { + return func(opts *ibc.CreateChannelOptions) { + opts.Version = "ics20-1" + opts.SourcePortName = "transfer" + opts.DestPortName = "transfer" + } +} From d7d515a62a583f371b11d7797c026ec5b9a2f079 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 11 Aug 2022 16:26:10 +0200 Subject: [PATCH 2/3] chore: adding option for manual testing --- .github/workflows/e2e-manual.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/e2e-manual.yaml b/.github/workflows/e2e-manual.yaml index 65be1c8f8e2..f92aa6e8dfc 100644 --- a/.github/workflows/e2e-manual.yaml +++ b/.github/workflows/e2e-manual.yaml @@ -11,6 +11,7 @@ on: type: choice options: - TestFeeMiddlewareTestSuite + - TestTransferTestSuite chain-a-image: description: 'The image to use for chain A' required: true From 38b0ac043d922e6351e1a1a414625b5386db1f98 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 16 Aug 2022 11:37:58 +0200 Subject: [PATCH 3/3] nits --- .github/workflows/e2e-manual.yaml | 1 - e2e/transfer_test.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/e2e-manual.yaml b/.github/workflows/e2e-manual.yaml index 7a5a87dd217..519c3b5d4f4 100644 --- a/.github/workflows/e2e-manual.yaml +++ b/.github/workflows/e2e-manual.yaml @@ -12,7 +12,6 @@ on: options: - TestTransferTestSuite - TestFeeMiddlewareTestSuite - - TestTransferTestSuite chain-a-image: description: 'The image to use for chain A' required: true diff --git a/e2e/transfer_test.go b/e2e/transfer_test.go index 5627a70582e..e484620833a 100644 --- a/e2e/transfer_test.go +++ b/e2e/transfer_test.go @@ -130,7 +130,7 @@ func (s *TransferTestSuite) TestMsgTransfer_Timeout_Nonincentivized() { Amount: testvalues.IBCTransferAmount, } - t.Run("IBC transfer packet timesout", func(t *testing.T) { + t.Run("IBC transfer packet times out", func(t *testing.T) { tx, err := chainA.SendIBCTransfer(ctx, channelA.ChannelID, chainAWallet.KeyName, chainBWalletAmount, testvalues.ImmediatelyTimeout()) s.Require().NoError(err) s.Require().NoError(tx.Validate(), "source ibc transfer tx is invalid")