Skip to content
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

Conversation

crodriguezvega
Copy link
Contributor

@crodriguezvega crodriguezvega commented Jan 11, 2023

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

refactor: add support for multiple events same type in assert events

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.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

testing/events.go Outdated Show resolved Hide resolved
@crodriguezvega crodriguezvega changed the title refactor: add support for multiple events same type in assert events refactor: add support for multiple events of same type in AssertEvents Jan 11, 2023
@crodriguezvega crodriguezvega marked this pull request as ready for review January 16, 2023 12:00
@@ -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
Copy link
Member

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)
}

Copy link
Contributor Author

@crodriguezvega crodriguezvega Jan 19, 2023

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.

Copy link
Contributor

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.

@crodriguezvega crodriguezvega merged commit 85e7c49 into damian/2847-distribute-fee-events Jan 19, 2023
@crodriguezvega crodriguezvega deleted the carlos/support-for-multiple-events-same-type-assert-events branch January 19, 2023 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants