-
Notifications
You must be signed in to change notification settings - Fork 657
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
E2E Test: TestMsgPayPacketFeeSingleSenderTimesOut #1751
Changes from 3 commits
ec6f55b
61395dd
c6d7677
5411b91
9ef560b
980ae0d
a52e5e7
d0b239b
39db520
d9b55da
fcb1fab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package e2e | |
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/strangelove-ventures/ibctest/broadcast" | ||
|
@@ -79,7 +80,7 @@ func (s *FeeMiddlewareTestSuite) QueryIncentivizedPacketsForChannel( | |
return res.IncentivizedPackets, err | ||
} | ||
|
||
func (s *FeeMiddlewareTestSuite) TestMsgPayPacketFeeAsyncSingleSender() { | ||
func (s *FeeMiddlewareTestSuite) TestMsgPayPacketFee_AsyncSingleSender_Succeeds() { | ||
t := s.T() | ||
ctx := context.TODO() | ||
|
||
|
@@ -309,6 +310,130 @@ func (s *FeeMiddlewareTestSuite) TestMultiMsg_MsgPayPacketFeeSingleSender() { | |
}) | ||
} | ||
|
||
func (s *FeeMiddlewareTestSuite) TestMsgPayPacket_FeeSingleSender_TimesOut() { | ||
t := s.T() | ||
ctx := context.TODO() | ||
|
||
relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, feeMiddlewareChannelOptions()) | ||
chainA, chainB := s.GetChains() | ||
|
||
var ( | ||
chainADenom = chainA.Config().Denom | ||
testFee = testvalues.DefaultFee(chainADenom) | ||
chainATx ibc.Tx | ||
payPacketFeeTxResp sdk.TxResponse | ||
) | ||
|
||
chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) | ||
chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) | ||
|
||
t.Run("relayer wallets recovered", func(t *testing.T) { | ||
s.Require().NoError(s.RecoverRelayerWallets(ctx, relayer)) | ||
}) | ||
|
||
chainARelayerWallet, chainBRelayerWallet, err := s.GetRelayerWallets(relayer) | ||
t.Run("relayer wallets fetched", func(t *testing.T) { | ||
s.Require().NoError(err) | ||
}) | ||
|
||
s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why waiting for blocks here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point this probably is not required. |
||
|
||
_, chainBRelayerUser := s.GetRelayerUsers(ctx) | ||
|
||
t.Run("register counter party payee", func(t *testing.T) { | ||
resp, err := s.RegisterCounterPartyPayee(ctx, chainB, chainBRelayerUser, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, chainBRelayerWallet.Address, chainARelayerWallet.Address) | ||
s.Require().NoError(err) | ||
s.AssertValidTxResponse(resp) | ||
}) | ||
|
||
t.Run("verify counter party payee", func(t *testing.T) { | ||
address, err := s.QueryCounterPartyPayee(ctx, chainB, chainBRelayerWallet.Address, channelA.Counterparty.ChannelID) | ||
s.Require().NoError(err) | ||
s.Require().Equal(chainARelayerWallet.Address, address) | ||
}) | ||
|
||
walletAmount := ibc.WalletAmount{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe more explicit naming here, it's actually a chainBWalletAmount -- |
||
Address: chainBWallet.Bech32Address(chainB.Config().Bech32Prefix), // destination address | ||
Denom: chainA.Config().Denom, | ||
Amount: testvalues.IBCTransferAmount, | ||
} | ||
|
||
t.Run("Send IBC transfer", func(t *testing.T) { | ||
var err error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
chainATx, err = chainA.SendIBCTransfer(ctx, channelA.ChannelID, chainAWallet.KeyName, walletAmount, &ibc.IBCTimeout{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. walletAmount gets a bit confusing here bc it was set as a chainB wallet amount but now youre sending a chainA tx? |
||
NanoSeconds: testvalues.ImmediatelyTimeout, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comment in the const file |
||
}) | ||
s.Require().NoError(err) | ||
s.Require().NoError(chainATx.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 - walletAmount.Amount | ||
s.Require().Equal(expected, actualBalance) | ||
}) | ||
|
||
t.Run("pay packet fee", func(t *testing.T) { | ||
|
||
packetId := channeltypes.NewPacketId(channelA.PortID, channelA.ChannelID, 1) | ||
packetFee := feetypes.NewPacketFee(testFee, chainAWallet.Bech32Address(chainA.Config().Bech32Prefix), nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chainAWallet.Address? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, i left the issue in the strangelove repo :) |
||
|
||
t.Run("no incentivized packets", func(t *testing.T) { | ||
packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) | ||
s.Require().NoError(err) | ||
s.Require().Empty(packets) | ||
}) | ||
|
||
t.Run("should succeed", func(t *testing.T) { | ||
payPacketFeeTxResp, err = s.PayPacketFeeAsync(ctx, chainA, chainAWallet, packetId, packetFee) | ||
s.Require().NoError(err) | ||
s.AssertValidTxResponse(payPacketFeeTxResp) | ||
}) | ||
|
||
t.Run("there should be incentivized packets", func(t *testing.T) { | ||
packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) | ||
s.Require().NoError(err) | ||
s.Require().Len(packets, 1) | ||
actualFee := packets[0].PacketFees[0].Fee | ||
|
||
s.Require().True(actualFee.RecvFee.IsEqual(testFee.RecvFee)) | ||
s.Require().True(actualFee.AckFee.IsEqual(testFee.AckFee)) | ||
s.Require().True(actualFee.TimeoutFee.IsEqual(testFee.TimeoutFee)) | ||
}) | ||
|
||
t.Run("balance should be lowered by sum of recv ack and timeout", func(t *testing.T) { | ||
// The balance should be lowered by the sum of the recv, ack and timeout fees. | ||
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) | ||
s.Require().NoError(err) | ||
|
||
expected := testvalues.StartingTokenAmount - walletAmount.Amount - testFee.Total().AmountOf(chainADenom).Int64() | ||
s.Require().Equal(expected, actualBalance) | ||
}) | ||
|
||
}) | ||
|
||
t.Run("start relayer", func(t *testing.T) { | ||
s.StartRelayer(relayer) | ||
}) | ||
|
||
t.Run("packets are relayed", func(t *testing.T) { | ||
packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelA.PortID, channelA.ChannelID) | ||
s.Require().NoError(err) | ||
s.Require().Empty(packets) | ||
}) | ||
|
||
t.Run("recv and ack should be refunded", func(t *testing.T) { | ||
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet) | ||
s.Require().NoError(err) | ||
|
||
expected := testvalues.StartingTokenAmount - testFee.TimeoutFee.AmountOf(chainADenom).Int64() | ||
s.Require().Equal(expected, actualBalance) | ||
}) | ||
} | ||
|
||
// feeMiddlewareChannelOptions configures both of the chains to have fee middleware enabled. | ||
func feeMiddlewareChannelOptions() func(options *ibc.CreateChannelOptions) { | ||
return func(opts *ibc.CreateChannelOptions) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,9 @@ import ( | |
) | ||
|
||
const ( | ||
StartingTokenAmount int64 = 10_000_000 | ||
IBCTransferAmount int64 = 10_000 | ||
StartingTokenAmount int64 = 10_000_000 | ||
IBCTransferAmount int64 = 10_000 | ||
ImmediatelyTimeout uint64 = 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if this makes sense in the const file as we wouldnt necessarily change this value (changing the value would change the function) -- maybe you could just add a comment in the code above the line this value is used to explain that it means immediate timeout? |
||
) | ||
|
||
func DefaultFee(denom string) feetypes.Fee { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added underscores to make the names a little more readable.