-
Notifications
You must be signed in to change notification settings - Fork 642
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
refactor: add support for multiple events of same type in AssertEvents
#2995
refactor: add support for multiple events of same type in AssertEvents
#2995
Conversation
AssertEvents
…for-multiple-events-same-type-assert-events
testing/events.go
Outdated
@@ -12,7 +13,7 @@ import ( | |||
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" | |||
) | |||
|
|||
type EventsMap map[string]map[string]string | |||
type EventsMap map[string][]map[string]string |
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.
I wonder if we need this type, its kind of complex. I would probably opt for just using the sdk.Events
type.
Can't we just write the events assertion like this:
events := res.GetEvents()
expected := sdk.Events{
sdk.NewEvent(
types.EventTypeDistributeFee,
sdk.NewAttribute(types.AttributeKeyReceiver, suite.chainA.SenderAccount.GetAddress().String()),
sdk.NewAttribute(types.AttributeKeyFee, defaultRecvFee.String()),
),
sdk.NewEvent(
types.EventTypeDistributeFee,
sdk.NewAttribute(types.AttributeKeyReceiver, suite.chainA.SenderAccount.GetAddress().String()),
sdk.NewAttribute(types.AttributeKeyFee, defaultAckFee.String()),
),
sdk.NewEvent(
types.EventTypeDistributeFee,
sdk.NewAttribute(types.AttributeKeyReceiver, suite.chainA.SenderAccount.GetAddress().String()),
sdk.NewAttribute(types.AttributeKeyFee, defaultTimeoutFee.String()),
),
}
for _, evt := range expected {
suite.Require().Contains(events, evt)
}
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.
Great idea! Much simpler! :) I guess we don't need AssertEvents
anymore then... I will refactor that in a following PR.
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.
Makes sense. The only reason to have something like a map is to have an easy to read expected values with less boiler plate, because all attribute keys and values are basically only strings.
Description
This comment by @damiannolan got me thinking if we could use the
AssertEvents
(cc: @Anmol1696) function to standardize a bit the way we test events, so I tried to implement a way to be able to assert multiple events of the same type... Looking forward to feedback; happy to close the PR this is not useful.At the moment there's one thing that I think it's not working properly, but I will comment on the code.
closes: #XXXX
Commit Message / Changelog Entry
see the guidelines for commit messages. (view raw markdown for examples)
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
).godoc
comments.Files changed
in the Github PR explorer.Codecov Report
in the comment section below once CI passes.