Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(test) - Three chains path forwarding with unwind #6778

Merged
merged 13 commits into from
Jul 9, 2024
97 changes: 97 additions & 0 deletions e2e/tests/transfer/forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/strangelove-ventures/interchaintest/v8/ibc"
test "github.com/strangelove-ventures/interchaintest/v8/testutil"
bznein marked this conversation as resolved.
Show resolved Hide resolved
testifysuite "github.com/stretchr/testify/suite"

"github.com/cosmos/ibc-go/e2e/testsuite"
Expand Down Expand Up @@ -108,3 +109,99 @@ func (s *TransferForwardingTestSuite) testForwardingThreeChains(lastChainVersion
s.Require().Equal(expected, actualBalance.Int64())
})
}

// TestForwardingWithUnwindSucceeds tests the forwarding scenario in which
// a packet is sent from A to B, then unwound back to A and forwarded to C
// The overall flow of the packet is:
// A ---> B
// B --(unwind)-->A --(forward)-->B --(forward)--> C
func (s *TransferForwardingTestSuite) TestForwardingWithUnwindSucceeds() {
t := s.T()
ctx := context.TODO()
relayer, chains := s.GetRelayer(), s.GetAllChains()

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

channelAtoB := s.GetChainAChannel()
channelBtoC := s.GetChainChannel(testsuite.ChainChannelPair{ChainIdx: 1, ChannelIdx: 1})

chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.FormattedAddress()
chainADenom := chainA.Config().Denom

chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
chainBAddress := chainBWallet.FormattedAddress()

chainCWallet := s.CreateUserOnChainC(ctx, testvalues.StartingTokenAmount)
chainCAddress := chainCWallet.FormattedAddress()

t.Run("IBC transfer from A to B", func(t *testing.T) {
inFiveMinutes := time.Now().Add(5 * time.Minute).UnixNano()

msgTransfer := testsuite.GetMsgTransfer(
channelAtoB.PortID,
channelAtoB.ChannelID,
transfertypes.V2,
testvalues.DefaultTransferCoins(chainADenom),
chainAAddress,
chainBAddress,
clienttypes.ZeroHeight(),
uint64(inFiveMinutes),
"",
nil)
resp := s.BroadcastMessages(ctx, chainA, chainAWallet, msgTransfer)
s.AssertTxSuccess(resp)
})

t.Run("start relayer", func(t *testing.T) {
s.StartRelayer(relayer)
})

chainBDenom := transfertypes.NewDenom(chainADenom, transfertypes.NewHop(channelAtoB.Counterparty.PortID, channelAtoB.Counterparty.ChannelID))
t.Run("packet has reached B", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelAtoB.PortID, channelAtoB.ChannelID, 1)

balance, err := query.Balance(ctx, chainB, chainBAddress, chainBDenom.IBCDenom())
s.Require().NoError(err)

s.Require().Equal(testvalues.IBCTransferAmount, balance.Int64())
})

t.Run("IBC transfer from B (unwind) to C through A", func(t *testing.T) {
inFiveMinutes := time.Now().Add(5 * time.Minute).UnixNano()

forwarding := transfertypes.NewForwarding(
true,
transfertypes.NewHop(channelAtoB.PortID, channelAtoB.ChannelID),
transfertypes.NewHop(channelBtoC.PortID, channelBtoC.ChannelID),
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
)
msgTransfer := testsuite.GetMsgTransfer(
"",
"",
transfertypes.V2,
testvalues.DefaultTransferCoins(chainBDenom.IBCDenom()),
chainBAddress,
chainCAddress,
clienttypes.ZeroHeight(),
uint64(inFiveMinutes),
"",
forwarding)
resp := s.BroadcastMessages(ctx, chainB, chainBWallet, msgTransfer)
s.AssertTxSuccess(resp)
})
t.Run("packet has reached C", func(t *testing.T) {
bznein marked this conversation as resolved.
Show resolved Hide resolved
chainCDenom := transfertypes.NewDenom(chainADenom,
transfertypes.NewHop(channelAtoB.Counterparty.PortID, channelAtoB.Counterparty.ChannelID),
transfertypes.NewHop(channelBtoC.Counterparty.PortID, channelBtoC.Counterparty.ChannelID),
)

err := test.WaitForCondition(time.Minute*10, time.Second*30, func() (bool, error) {
balance, err := query.Balance(ctx, chainC, chainCAddress, chainCDenom.IBCDenom())
if err != nil {
return false, err
}
return balance.Int64() == testvalues.IBCTransferAmount, nil
})
s.Require().NoError(err)
})
bznein marked this conversation as resolved.
Show resolved Hide resolved
}
Loading