From 2325143f84b2bd1483c8c957ac37b2a0d5783a2e Mon Sep 17 00:00:00 2001 From: bznein Date: Wed, 3 Jul 2024 15:17:37 +0100 Subject: [PATCH 1/5] Create new forwarding test --- e2e/tests/transfer/forwarding_test.go | 27 +++++++++++++++++++++------ e2e/testsuite/testsuite.go | 15 +++++++++++++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/e2e/tests/transfer/forwarding_test.go b/e2e/tests/transfer/forwarding_test.go index 23a8dde01b1..a04e841060f 100644 --- a/e2e/tests/transfer/forwarding_test.go +++ b/e2e/tests/transfer/forwarding_test.go @@ -33,6 +33,26 @@ func (s *TransferForwardingTestSuite) SetupSuite() { // TestForwarding_WithLastChainBeingICS20v1_Succeeds tests the case where a token is forwarded and successfully // received on a destination chain that is on ics20-v1 version. func (s *TransferForwardingTestSuite) TestForwarding_WithLastChainBeingICS20v1_Succeeds() { + channelBToCCallback := func() ibc.ChannelOutput { + ctx := context.TODO() + // Creating a new path between chain B and chain C with a ICS20-v1 channel + opts := s.TransferChannelOptions() + opts.Version = transfertypes.V1 + chains := s.GetAllChains() + channelBtoC, _ := s.CreatePath(ctx, chains[1], chains[2], ibc.DefaultClientOpts(), opts) + s.Require().Equal(transfertypes.V1, channelBtoC.Version, "the channel version is not ics20-1") + return channelBtoC + } + s.testForwardingThreeChains(channelBToCCallback) +} + +// TestForwarding_Succeeds tests the case where a token is forwarded and successfully +// received on a destination chain. +func (s *TransferForwardingTestSuite) TestForwarding_Succeeds() { + s.testForwardingThreeChains(func() ibc.ChannelOutput { return s.GetChainChannel(1) }) +} + +func (s *TransferForwardingTestSuite) testForwardingThreeChains(channelBToCCallback func() ibc.ChannelOutput) { ctx := context.TODO() t := s.T() @@ -41,12 +61,7 @@ func (s *TransferForwardingTestSuite) TestForwarding_WithLastChainBeingICS20v1_S chainA, chainB, chainC := chains[0], chains[1], chains[2] channelAtoB := s.GetChainAChannel() - - // Creating a new path between chain B and chain C with a ICS20-v1 channel - opts := s.TransferChannelOptions() - opts.Version = transfertypes.V1 - channelBtoC, _ := s.CreatePath(ctx, chainB, chainC, ibc.DefaultClientOpts(), opts) - s.Require().Equal(transfertypes.V1, channelBtoC.Version, "the channel version is not ics20-1") + channelBtoC := channelBToCCallback() chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) chainAAddress := chainAWallet.FormattedAddress() diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 7b1d5ff4c7b..565b9b83394 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -262,8 +262,19 @@ func (s *E2ETestSuite) CreatePath( // this defaults to the first entry in the list, and will be what is needed in the case of // a single channel test. func (s *E2ETestSuite) GetChainAChannel() ibc.ChannelOutput { - chainA := s.GetAllChains()[0] - return s.GetChannels(chainA)[0] + return s.GetChainChannel(0) +} + +// GetChainChannel returns the ibc.ChannelOutput for a specific +// entry in the list of chains. It defaults to the first entry +// in the list of channels for that chain. +func (s *E2ETestSuite) GetChainChannel(chainIdx int) ibc.ChannelOutput { + chains := s.GetAllChains() + s.Require().Less(chainIdx, len(chains), "required index %d is larger than the last index in the list of chains (%d)", chainIdx, len(chains)-1) + chain := chains[chainIdx] + channels := s.GetChannels(chain) + s.Require().NotEmpty(channels, "found no channels for chain %s", chain.Config().Name) + return channels[0] } // GetChannels returns all channels for the current test. From 7b162daf1f00f3ee75ce57d04a919177c0250a01 Mon Sep 17 00:00:00 2001 From: bznein Date: Wed, 3 Jul 2024 15:42:35 +0100 Subject: [PATCH 2/5] Use a struct rather than raw fields --- e2e/tests/transfer/forwarding_test.go | 4 +++- e2e/testsuite/testsuite.go | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/e2e/tests/transfer/forwarding_test.go b/e2e/tests/transfer/forwarding_test.go index a04e841060f..b06e00688f4 100644 --- a/e2e/tests/transfer/forwarding_test.go +++ b/e2e/tests/transfer/forwarding_test.go @@ -49,7 +49,9 @@ func (s *TransferForwardingTestSuite) TestForwarding_WithLastChainBeingICS20v1_S // TestForwarding_Succeeds tests the case where a token is forwarded and successfully // received on a destination chain. func (s *TransferForwardingTestSuite) TestForwarding_Succeeds() { - s.testForwardingThreeChains(func() ibc.ChannelOutput { return s.GetChainChannel(1) }) + s.testForwardingThreeChains(func() ibc.ChannelOutput { + return s.GetChainChannel(testsuite.ChainChannelPair{ChainIdx: 1, ChannelIdx: 1}) + }) } func (s *TransferForwardingTestSuite) testForwardingThreeChains(channelBToCCallback func() ibc.ChannelOutput) { diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 565b9b83394..e8f8ee349d2 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -258,23 +258,28 @@ func (s *E2ETestSuite) CreatePath( return channelsA[len(channelsA)-1], channelsB[len(channelsB)-1] } +type ChainChannelPair struct { + ChainIdx int + ChannelIdx int +} + // GetChainAChannel returns the ibc.ChannelOutput for the current test. // this defaults to the first entry in the list, and will be what is needed in the case of // a single channel test. func (s *E2ETestSuite) GetChainAChannel() ibc.ChannelOutput { - return s.GetChainChannel(0) + return s.GetChainChannel(ChainChannelPair{ChainIdx: 0, ChannelIdx: 0}) } // GetChainChannel returns the ibc.ChannelOutput for a specific -// entry in the list of chains. It defaults to the first entry -// in the list of channels for that chain. -func (s *E2ETestSuite) GetChainChannel(chainIdx int) ibc.ChannelOutput { +// entry in the list of chains. +func (s *E2ETestSuite) GetChainChannel(id ChainChannelPair) ibc.ChannelOutput { chains := s.GetAllChains() - s.Require().Less(chainIdx, len(chains), "required index %d is larger than the last index in the list of chains (%d)", chainIdx, len(chains)-1) - chain := chains[chainIdx] + s.Require().Less(id.ChainIdx, len(chains), "required index %d is larger than the last index in the list of chains (%d)", id.ChainIdx, len(chains)-1) + + chain := chains[id.ChainIdx] channels := s.GetChannels(chain) - s.Require().NotEmpty(channels, "found no channels for chain %s", chain.Config().Name) - return channels[0] + s.Require().Less(id.ChannelIdx, len(channels), "required channel index %d is larger than the last index in the list of channels (%d)", id.ChannelIdx, len(channels)-1) + return channels[id.ChannelIdx] } // GetChannels returns all channels for the current test. From 328d4d01540312527855ec5f8561be5ec5c00987 Mon Sep 17 00:00:00 2001 From: bznein Date: Wed, 3 Jul 2024 15:51:29 +0100 Subject: [PATCH 3/5] better docstring --- e2e/testsuite/testsuite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index e8f8ee349d2..c512e6440e4 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -270,7 +270,7 @@ func (s *E2ETestSuite) GetChainAChannel() ibc.ChannelOutput { return s.GetChainChannel(ChainChannelPair{ChainIdx: 0, ChannelIdx: 0}) } -// GetChainChannel returns the ibc.ChannelOutput for a specific +// GetChainChannel returns the ibc.ChannelOutput at the specified index for a specific // entry in the list of chains. func (s *E2ETestSuite) GetChainChannel(id ChainChannelPair) ibc.ChannelOutput { chains := s.GetAllChains() From 811c7075afe006f5f5c98a649af3767e34dfa5e4 Mon Sep 17 00:00:00 2001 From: bznein Date: Mon, 8 Jul 2024 09:02:04 +0100 Subject: [PATCH 4/5] Change a type and remove callback --- e2e/tests/transfer/forwarding_test.go | 29 ++++++++++++--------------- e2e/testsuite/testsuite.go | 4 ++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/e2e/tests/transfer/forwarding_test.go b/e2e/tests/transfer/forwarding_test.go index b06e00688f4..ed1e07ec958 100644 --- a/e2e/tests/transfer/forwarding_test.go +++ b/e2e/tests/transfer/forwarding_test.go @@ -33,28 +33,16 @@ func (s *TransferForwardingTestSuite) SetupSuite() { // TestForwarding_WithLastChainBeingICS20v1_Succeeds tests the case where a token is forwarded and successfully // received on a destination chain that is on ics20-v1 version. func (s *TransferForwardingTestSuite) TestForwarding_WithLastChainBeingICS20v1_Succeeds() { - channelBToCCallback := func() ibc.ChannelOutput { - ctx := context.TODO() - // Creating a new path between chain B and chain C with a ICS20-v1 channel - opts := s.TransferChannelOptions() - opts.Version = transfertypes.V1 - chains := s.GetAllChains() - channelBtoC, _ := s.CreatePath(ctx, chains[1], chains[2], ibc.DefaultClientOpts(), opts) - s.Require().Equal(transfertypes.V1, channelBtoC.Version, "the channel version is not ics20-1") - return channelBtoC - } - s.testForwardingThreeChains(channelBToCCallback) + s.testForwardingThreeChains(transfertypes.V1) } // TestForwarding_Succeeds tests the case where a token is forwarded and successfully // received on a destination chain. func (s *TransferForwardingTestSuite) TestForwarding_Succeeds() { - s.testForwardingThreeChains(func() ibc.ChannelOutput { - return s.GetChainChannel(testsuite.ChainChannelPair{ChainIdx: 1, ChannelIdx: 1}) - }) + s.testForwardingThreeChains(transfertypes.V2) } -func (s *TransferForwardingTestSuite) testForwardingThreeChains(channelBToCCallback func() ibc.ChannelOutput) { +func (s *TransferForwardingTestSuite) testForwardingThreeChains(lastChainVersion string) { ctx := context.TODO() t := s.T() @@ -62,8 +50,17 @@ func (s *TransferForwardingTestSuite) testForwardingThreeChains(channelBToCCallb chainA, chainB, chainC := chains[0], chains[1], chains[2] + var channelBtoC ibc.ChannelOutput channelAtoB := s.GetChainAChannel() - channelBtoC := channelBToCCallback() + if lastChainVersion == transfertypes.V2 { + channelBtoC = s.GetChainChannel(testsuite.ChainChannelPair{ChainIdx: 1, ChannelIdx: 1}) + } else { + opts := s.TransferChannelOptions() + opts.Version = transfertypes.V1 + chains := s.GetAllChains() + channelBtoC, _ = s.CreatePath(ctx, chains[1], chains[2], ibc.DefaultClientOpts(), opts) + s.Require().Equal(transfertypes.V1, channelBtoC.Version, "the channel version is not ics20-1") + } chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) chainAAddress := chainAWallet.FormattedAddress() diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index c512e6440e4..9ba244affa0 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -259,8 +259,8 @@ func (s *E2ETestSuite) CreatePath( } type ChainChannelPair struct { - ChainIdx int - ChannelIdx int + ChainIdx uint64 + ChannelIdx uint64 } // GetChainAChannel returns the ibc.ChannelOutput for the current test. From 57d98771432e62d1ffb698616aa4fee8509c93c6 Mon Sep 17 00:00:00 2001 From: bznein Date: Mon, 8 Jul 2024 11:02:23 +0100 Subject: [PATCH 5/5] Fix type --- e2e/testsuite/testsuite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index 9ba244affa0..4f5812bb432 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -274,11 +274,11 @@ func (s *E2ETestSuite) GetChainAChannel() ibc.ChannelOutput { // entry in the list of chains. func (s *E2ETestSuite) GetChainChannel(id ChainChannelPair) ibc.ChannelOutput { chains := s.GetAllChains() - s.Require().Less(id.ChainIdx, len(chains), "required index %d is larger than the last index in the list of chains (%d)", id.ChainIdx, len(chains)-1) + s.Require().Less(id.ChainIdx, uint64(len(chains)), "required index %d is larger than the last index in the list of chains (%d)", id.ChainIdx, len(chains)-1) chain := chains[id.ChainIdx] channels := s.GetChannels(chain) - s.Require().Less(id.ChannelIdx, len(channels), "required channel index %d is larger than the last index in the list of channels (%d)", id.ChannelIdx, len(channels)-1) + s.Require().Less(id.ChannelIdx, uint64(len(channels)), "required channel index %d is larger than the last index in the list of channels (%d)", id.ChannelIdx, len(channels)-1) return channels[id.ChannelIdx] }