Skip to content
Merged
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ff9fdc7
test: adding TestAsyncSingleSenderNoCounterPartyAddress
chatton Jul 20, 2022
f72545d
test: adding TestPayPacketFeeAsyncSingleSenderNoCounterPartyAddress
chatton Jul 20, 2022
3841260
test: correcting refund address
chatton Jul 20, 2022
e1793b9
test: adding sleep after packet incentivization
chatton Jul 20, 2022
6be8aa9
test: registering counter party payee
chatton Jul 20, 2022
44bdab1
removing additional using on chainb
chatton Jul 20, 2022
20ad572
test: fixing packet ID
chatton Jul 20, 2022
3383e27
Merge branch 'main' into cian/issue#1686-fee-middleware-counterparty-…
chatton Jul 21, 2022
dce23ba
Merge branch 'main' into cian/issue#1686-fee-middleware-counterparty-…
chatton Jul 21, 2022
e08565c
chore: removing all gas fees
chatton Jul 21, 2022
fa7685f
Merge branch 'main' into cian/issue#1686-fee-middleware-counterparty-…
chatton Jul 26, 2022
c9a66d3
chore: merge main
chatton Jul 27, 2022
c8e50fe
chore: merge main
chatton Jul 27, 2022
2abfc64
chore: removing wait for blocks
chatton Jul 27, 2022
0d08c7d
Update e2e/fee_middleware_test.go
chatton Aug 8, 2022
767f62f
Merge branch 'main' into cian/issue#1686-fee-middleware-counterparty-…
chatton Aug 8, 2022
1a5c994
Merge branch 'main' into cian/issue#1686-fee-middleware-counterparty-…
chatton Aug 10, 2022
bf97dcd
Merge branch 'main' into cian/issue#1686-fee-middleware-counterparty-…
chatton Aug 10, 2022
dc5bc83
chore: addressing PR feedback
chatton Aug 10, 2022
2b156f9
chore: merge main
chatton Aug 10, 2022
1ffb7a8
chore: reference sequence directly instead of hard coded value
chatton Aug 10, 2022
54c4114
Merge branch 'main' into cian/issue#1686-fee-middleware-counterparty-…
chatton Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions e2e/fee_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,108 @@ func (s *FeeMiddlewareTestSuite) TestMsgPayPacketFee_SingleSender_TimesOut() {
})
}

func (s *FeeMiddlewareTestSuite) TestPayPacketFeeAsync_SingleSender_NoCounterPartyAddress() {
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)

t.Run("relayer wallets recovered", func(t *testing.T) {
err := s.RecoverRelayerWallets(ctx, relayer)
s.Require().NoError(err)
})

chainBWalletAmount := ibc.WalletAmount{
Address: chainAWallet.Bech32Address(chainB.Config().Bech32Prefix), // destination address
Denom: chainADenom,
Amount: testvalues.IBCTransferAmount,
}

t.Run("send IBC transfer", func(t *testing.T) {
var err error
chainATx, err = chainA.SendIBCTransfer(ctx, channelA.ChannelID, chainAWallet.KeyName, chainBWalletAmount, nil)
s.Require().NoError(err)
s.Require().NoError(chainATx.Validate(), "source ibc transfer tx is invalid")
})

t.Run("tokens are escrowed", func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)

expected := testvalues.StartingTokenAmount - chainBWalletAmount.Amount
s.Require().Equal(expected, actualBalance)
})

t.Run("pay packet fee", func(t *testing.T) {
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)
})

packetId := channeltypes.NewPacketId(channelA.PortID, channelA.ChannelID, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
packetId := channeltypes.NewPacketId(channelA.PortID, channelA.ChannelID, 1)
packetId := channeltypes.NewPacketId(chainATx.Packet.GetSourcePort(), chainATx.Packet.GetSourceChannel(), chainATx.Packet.GetSequence())

I think at least modifying the sequence to use the returned chainATx.Packet.GetSequence makes sense, I have no preference on the other arguments, I just figure this code will be copied a lot so might make more sense to derive the values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah definitely, good catch.

packetFee := feetypes.NewPacketFee(testFee, chainAWallet.Bech32Address(chainA.Config().Bech32Prefix), nil)

t.Run("should succeed", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something extra in the description to make it more explicit? Like pay packet fee should succeed?

Copy link
Contributor Author

@chatton chatton Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the nesting, the resulting message will look like TestPayPacketFeeAsync_SingleSender_NoCounterPartyAddress/pay_packet_fee/should_succeed

var err error
payPacketFeeTxResp, err = s.PayPacketFeeAsync(ctx, chainA, chainAWallet, packetId, packetFee)
s.Require().NoError(err)
s.AssertValidTxResponse(payPacketFeeTxResp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this helper function ❤️

})

t.Run("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 - chainBWalletAmount.Amount - testFee.Total().AmountOf(chainADenom).Int64()
s.Require().Equal(expected, actualBalance)
})

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

t.Run("with no counter party address", func(t *testing.T) {
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("timeout and recv fee are refunded", func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)

// once the relayer has relayed the packets, the timeout and recv fee should be refunded.
expected := testvalues.StartingTokenAmount - chainBWalletAmount.Amount - testFee.AckFee.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) {
Expand Down