Skip to content

Commit

Permalink
(test) Test that tokens are successfully forwarded from A to C throug…
Browse files Browse the repository at this point in the history
…h B (#6758)

* Create new forwarding test

* Use a struct rather than raw fields

* better docstring

* Change a type and remove callback

* Fix type
  • Loading branch information
bznein authored Jul 8, 2024
1 parent f41cb31 commit d0305b6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
26 changes: 20 additions & 6 deletions e2e/tests/transfer/forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,34 @@ 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() {
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(transfertypes.V2)
}

func (s *TransferForwardingTestSuite) testForwardingThreeChains(lastChainVersion string) {
ctx := context.TODO()
t := s.T()

relayer, chains := s.GetRelayer(), s.GetAllChains()

chainA, chainB, chainC := chains[0], chains[1], chains[2]

var channelBtoC ibc.ChannelOutput
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")
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()
Expand Down
20 changes: 18 additions & 2 deletions e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,28 @@ func (s *E2ETestSuite) CreatePath(
return channelsA[len(channelsA)-1], channelsB[len(channelsB)-1]
}

type ChainChannelPair struct {
ChainIdx uint64
ChannelIdx uint64
}

// 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 {
chainA := s.GetAllChains()[0]
return s.GetChannels(chainA)[0]
return s.GetChainChannel(ChainChannelPair{ChainIdx: 0, ChannelIdx: 0})
}

// 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()
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, 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]
}

// GetChannels returns all channels for the current test.
Expand Down

0 comments on commit d0305b6

Please sign in to comment.