-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
test(gov): add test for Tally
function
#17142
Conversation
Although rather complex, the `govKeeper.Tally` function has no unit tests. This change adds a test that covers around 91% of the code, only some unexpected errors are not covered. If this change is accepted, another will follow to refactor the function into smaller parts (without changing the test). This will address the TODO on top, reduce complexity, improve readability and reusability. This test should also help for issues like cosmos#11422 and cosmos#10353. It's more comfortable to improve performance or completely rewrite the implementation with a high code coverage. The `setupGovKeeper` had to be modified because it was registering some mocks expectations that cannot be overridden. It now takes an additional variadic argument that can be used to better customize the mocks expectations. Also, to improve readability, the mocks are all gathered in a new specific `mocks` struct.
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.
Nice! Yeah, units tests weren't created when we moved the previous tests to the integration folder (https://github.com/cosmos/cosmos-sdk/blob/6b4774266eeb03748937faf28663019ac332cc9c/tests/integration/gov/keeper/tally_test.go).
Oh I hadn't noticed those tests before, thanks for bringing them to my attention. I assume both unit and integration tests are welcome :). |
For sure! |
Cherry pick of cosmos/cosmos-sdk#17142
Cherry pick of cosmos/cosmos-sdk#17142
Cherry pick of cosmos/cosmos-sdk#17142
Cherry pick of cosmos/cosmos-sdk#17142
Description
Although rather complex, the
govKeeper.Tally
function has no unit tests. This change adds a test that covers around 91% of the code, only some unexpected errors are not covered.If this change is accepted, another will follow to refactor the function into smaller parts (without changing the test). This will address the TODO on top, reduce complexity, improve readability and reusability.
This test should also help for issues like #11422 and #10353. It's more comfortable to improve performance or completely rewrite the implementation with a high code coverage.
The
setupGovKeeper
had to be modified because it was registering some mocks expectations that cannot be overridden. It now takes an additional variadic argument that can be used to better customize the mocks expectations. Also, to improve readability, the mocks are all gathered in a new specificmocks
struct.Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
make lint
andmake test
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change