forked from cosmos/ibc-go
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: emit cumulative fees when incentivizing a packet multiple t…
…imes (cosmos#1391) * emit cumulative fees * test: add test for emission of cumulative incentivized fees * add check for nil relayer * reassign sdk.Coins, fix bug
- Loading branch information
1 parent
b7b4400
commit 2ae4f10
Showing
3 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = expRecvFees.Add(fee.RecvFee...) | ||
expAckFees = expAckFees.Add(fee.AckFee...) | ||
expTimeoutFees = expTimeoutFees.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 = expRecvFees.Add(fee.RecvFee...) | ||
expAckFees = expAckFees.Add(fee.AckFee...) | ||
expTimeoutFees = expTimeoutFees.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)) | ||
} | ||
} | ||
} |