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

Events unit testing across the board #2823

Closed
5 of 9 tasks
Anmol1696 opened this issue Nov 24, 2022 · 3 comments · Fixed by #5706
Closed
5 of 9 tasks

Events unit testing across the board #2823

Anmol1696 opened this issue Nov 24, 2022 · 3 comments · Fixed by #5706
Assignees
Labels
testing Testing package and unit/integration tests

Comments

@Anmol1696
Copy link
Contributor

Anmol1696 commented Nov 24, 2022

Summary

Currently there is no tests for events emitted by any of the msgs. The following proposal is a way to have easy testablity in unit tests for events emitted per msg.

Problem Definition

Why do we need this feature?

  • Events are slowly becoming source of truth for many downstream applications, we need a way to make sure there are no regressions happening on events
  • Events produced is untested code, we will also increase the code coverage

What benefits does the ibc-go stand to gain by including this feature?

  • Programatic way to catch regressions on events faster

Are there any disadvantages of including this feature?

  • More overhead for developers as testing events has more boiler plate
  • Benifits might be minimal compared to the efforts

Proposal

The proposal is to add a testutil function which can assert events.

package testutil

assertEvents(suite suite.Suite, expected map[string]map[string]string, actual sdk.Events)

To make this function importable, I propose we create a new package testutil at the root level, where we can have multiple test utils that can then be imported. Something like testutil. package in cosmos-sdk

In the test functions where the events are emmited we can call the above function as:

// Create expected event
expEvents := map[string]map[string]string{
  "ibc_transfer": {
	  "sender":   suite.chainA.SenderAccount.GetAddress().String(),
	  "receiver": suite.chainB.SenderAccount.GetAddress().String(),
	  "amount":   coin.Amount.String(),
	  "denom":    coin.Denom,
  },
  "send": {
    ...
  }
}

// Actual event
events := ctx.EventManager().Events()

// Perform the assert
assertEvents(suite, expEvents, events)

Points of disucssion

  • As per the current proposal we hardcode the event types and attribute keys per test, so as to make the test case itself brittle, if the default strings changes the test should fail as well. But this is a point of dicussion, open to changing it to less hard coded.
  • For this proposal we need to make assertEvents function an importable function which can be used by various functions. Creating a new package might be an overkill, but can go a long way in the future to have common test utils.

PRs


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged/assigned
@crodriguezvega crodriguezvega added the testing Testing package and unit/integration tests label Nov 24, 2022
@colin-axner
Copy link
Contributor

Thanks @Anmol1696. I like the addition 👍 We can add the function into the ibc testing package. @damiannolan @chatton what do y'all think?

As per the current proposal we hardcode the event types and attribute keys per test, so as to make the test case itself brittle, if the default strings changes the test should fail as well.

This makes sense. Given that changing the key value would likely be very disruptive to external users and thus should rarely change

@Anmol1696
Copy link
Contributor Author

Sorry for the hurry, but can this PR: #2829 be reviewd? So i can then open all the small PRs for various parts of the code. This PR has the main function needed, after which we can have parallel PRs, they can be reviewd slowly.

From what i can tell there will be these PRs

  • 03-connection
  • 02-client
  • core (keeper and msg server)
  • apps/27-ica
  • apps/29-fee

@colin-axner
Copy link
Contributor

We had a regression in event behaviour (v5.2, v6.1, v7+) for no-op relays which affected hermes which shows that increased event testing would have been useful in being aware of the issue before it reaches production code

Would be nice if we could split up this issue and prioritize some of its work over the months cc @crodriguezvega

@crodriguezvega crodriguezvega moved this to Backlog in ibc-go Aug 1, 2023
@crodriguezvega crodriguezvega moved this from Backlog to Todo in ibc-go Jan 21, 2024
@chatton chatton self-assigned this Jan 22, 2024
@chatton chatton moved this from Todo to In review in ibc-go Jan 23, 2024
@chatton chatton mentioned this issue Jan 24, 2024
9 tasks
@github-project-automation github-project-automation bot moved this from In review 👀 to Done 🥳 in ibc-go Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Testing package and unit/integration tests
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants