Skip to content

Commit

Permalink
test: add test for emission of cumulative incentivized fees
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed May 16, 2022
1 parent acda4e9 commit dabac81
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions modules/apps/29-fee/keeper/events_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package keeper_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
abcitypes "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
)

func (suite *KeeperTestSuite) TestIncentivizePacketEvent() {
var (
expRecvFees sdk.Coins
expAckFees sdk.Coins
expTimeoutFees sdk.Coins
)

suite.coordinator.Setup(suite.path)

fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)
msg := types.NewMsgPayPacketFee(
fee,
suite.path.EndpointA.ChannelConfig.PortID,
suite.path.EndpointA.ChannelID,
suite.chainA.SenderAccount.GetAddress().String(),
nil,
)

expRecvFees.Add(fee.RecvFee...)
expAckFees.Add(fee.AckFee...)
expAckFees.Add(fee.TimeoutFee...)

result, err := suite.chainA.SendMsgs(msg)
suite.Require().NoError(err)

var incentivizedPacketEvent abcitypes.Event
for _, event := range result.Events {
if event.Type == types.EventTypeIncentivizedPacket {
incentivizedPacketEvent = event
}
}

for _, attr := range incentivizedPacketEvent.Attributes {
switch string(attr.Key) {
case types.AttributeKeyRecvFee:
suite.Require().Equal(expRecvFees.String(), string(attr.Value))

case types.AttributeKeyAckFee:
suite.Require().Equal(expAckFees.String(), string(attr.Value))

case types.AttributeKeyTimeoutFee:
suite.Require().Equal(expTimeoutFees.String(), string(attr.Value))
}
}

// send the same messages again a few times
for i := 0; i < 3; i++ {
expRecvFees.Add(fee.RecvFee...)
expAckFees.Add(fee.AckFee...)
expAckFees.Add(fee.TimeoutFee...)

result, err = suite.chainA.SendMsgs(msg)
suite.Require().NoError(err)
}

for _, event := range result.Events {
if event.Type == types.EventTypeIncentivizedPacket {
incentivizedPacketEvent = event
}
}

for _, attr := range incentivizedPacketEvent.Attributes {
switch string(attr.Key) {
case types.AttributeKeyRecvFee:
suite.Require().Equal(expRecvFees.String(), string(attr.Value))

case types.AttributeKeyAckFee:
suite.Require().Equal(expAckFees.String(), string(attr.Value))

case types.AttributeKeyTimeoutFee:
suite.Require().Equal(expTimeoutFees.String(), string(attr.Value))
}
}
}

0 comments on commit dabac81

Please sign in to comment.