Skip to content

Commit 85e7c49

Browse files
refactor: add support for multiple events of same type in AssertEvents (#2995)
* refactor: add support for asserting multiple events of the same type * change condition checking to make test pass * review comment * rename variable
1 parent 2ae2935 commit 85e7c49

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

modules/apps/29-fee/keeper/events_test.go

+20-17
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,26 @@ func (suite *KeeperTestSuite) TestDistributeFeeEvent() {
143143
suite.Require().NoError(err)
144144
suite.Require().NotNil(res)
145145

146-
// calculate the total paid out fees using "distribute_fee" events
147-
var totalPaid sdk.Coins
148-
for _, event := range res.Events {
149-
if event.Type == types.EventTypeDistributeFee {
150-
for _, attr := range event.Attributes {
151-
switch string(attr.Key) {
152-
case types.AttributeKeyFee:
153-
coins, err := sdk.ParseCoinsNormalized(string(attr.Value))
154-
suite.Require().NoError(err)
155-
156-
totalPaid = totalPaid.Add(coins...)
157-
}
158-
}
159-
160-
}
146+
events := res.GetEvents()
147+
expectedEvents := sdk.Events{
148+
sdk.NewEvent(
149+
types.EventTypeDistributeFee,
150+
sdk.NewAttribute(types.AttributeKeyReceiver, suite.chainA.SenderAccount.GetAddress().String()),
151+
sdk.NewAttribute(types.AttributeKeyFee, defaultRecvFee.String()),
152+
),
153+
sdk.NewEvent(
154+
types.EventTypeDistributeFee,
155+
sdk.NewAttribute(types.AttributeKeyReceiver, suite.chainA.SenderAccount.GetAddress().String()),
156+
sdk.NewAttribute(types.AttributeKeyFee, defaultAckFee.String()),
157+
),
158+
sdk.NewEvent(
159+
types.EventTypeDistributeFee,
160+
sdk.NewAttribute(types.AttributeKeyReceiver, suite.chainA.SenderAccount.GetAddress().String()),
161+
sdk.NewAttribute(types.AttributeKeyFee, defaultTimeoutFee.String()),
162+
),
161163
}
162164

163-
// assert the total fees paid out equal the total incentivization fees escrowed
164-
suite.Require().Equal(fee.Total(), totalPaid)
165+
for _, evt := range expectedEvents {
166+
suite.Require().Contains(events, evt)
167+
}
165168
}

modules/apps/transfer/keeper/msg_server_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import (
99
)
1010

1111
func (suite *KeeperTestSuite) TestMsgTransfer() {
12-
var (
13-
msg *types.MsgTransfer
14-
)
12+
var msg *types.MsgTransfer
1513

1614
testCases := []struct {
1715
name string

0 commit comments

Comments
 (0)