test: add unit tests for TotalVotingPowerSafe#5570
Merged
technicallyty merged 3 commits intocometbft:mainfrom Jan 20, 2026
Merged
test: add unit tests for TotalVotingPowerSafe#5570technicallyty merged 3 commits intocometbft:mainfrom
technicallyty merged 3 commits intocometbft:mainfrom
Conversation
- Adds TestValidatorSet_TotalVotingPowerSafe table-driven test - Covers happy paths, boundary conditions, and overflow scenarios - Verifies nil/empty set handling Closes cometbft#5522 Signed-off-by: bit2swaz <bit2swaz@gmail.com>
mattac21
reviewed
Jan 20, 2026
Collaborator
mattac21
left a comment
There was a problem hiding this comment.
just one small comment but looks good, thanks!
The 'tc := tc' pattern is no longer needed in modern Go versions (1.22+). This addresses reviewer feedback to clean up the code.
Contributor
Author
|
@mattac21 my bad. i forgot go 1.22 fixed the loop variable semantics. ive merged main and removed the redundant tc := tc capture. ready for another look :) |
mattac21
approved these changes
Jan 20, 2026
Contributor
|
@mergify backport v0.38.x |
Contributor
✅ Backports have been createdDetails
|
3 tasks
aljo242
added a commit
that referenced
this pull request
Jan 21, 2026
## Summary This PR adds comprehensive unit tests for the `TotalVotingPowerSafe` method in `types/validator_set.go`, addressing the request in issue #5522. ## Changes - Added `TestValidatorSet_TotalVotingPowerSafe` to `types/validator_set_test.go`. - Implemented a table-driven test structure using `testify/require` for strict assertions. - Added 11 test cases covering: - **Happy Path:** Standard validator sets with safe sums. - **Zero State:** Handling of nil and empty validator slices (expects 0, no error). - **Boundaries:** Sums exactly at `MaxTotalVotingPower`. - **Overflow:** Scenarios exceeding `MaxTotalVotingPower` (checking that it returns the expected error). ## Related Issues Closes #5522 #### PR checklist - [x] Tests written/updated - [ ] Changelog entry added in `.changelog` (N/A: `test` only change) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments --- > [!NOTE] > Adds comprehensive unit tests for `TotalVotingPowerSafe` in `types/validator_set_test.go` to validate summation behavior and overflow handling. > > - Introduces `TestValidatorSet_TotalVotingPowerSafe` with 11 cases: normal sums, nil/empty sets, single validator, boundaries at `MaxTotalVotingPower`, and multiple overflow scenarios (ensuring error with "exceeds maximum") > - Verifies correct totals when within limits and zero result with error on overflow, without invoking `NewValidatorSet` to avoid panic > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a1931b6. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <hr>This is an automatic backport of pull request #5570 done by [Mergify](https://mergify.com). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds comprehensive coverage for `TotalVotingPowerSafe` behavior and overflow handling. > > - Introduces `TestValidatorSet_TotalVotingPowerSafe` in `types/validator_set_test.go` > - Covers normal sums, nil/empty sets, single validator, boundaries at `MaxTotalVotingPower`, and multiple overflow cases (asserting error contains "exceeds maximum") > - Bypasses `NewValidatorSet` to avoid panic during overflow scenarios; uses `require` for strict assertions > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit bd517d2. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive unit tests for the
TotalVotingPowerSafemethod intypes/validator_set.go, addressing the request in issue #5522.Changes
TestValidatorSet_TotalVotingPowerSafetotypes/validator_set_test.go.testify/requirefor strict assertions.MaxTotalVotingPower.MaxTotalVotingPower(checking that it returns the expected error).Related Issues
Closes #5522
PR checklist
.changelog(N/A:testonly change)docs/orspec/) and code commentsNote
Adds comprehensive unit tests for
TotalVotingPowerSafeintypes/validator_set_test.goto validate summation behavior and overflow handling.TestValidatorSet_TotalVotingPowerSafewith 11 cases: normal sums, nil/empty sets, single validator, boundaries atMaxTotalVotingPower, and multiple overflow scenarios (ensuring error with "exceeds maximum")NewValidatorSetto avoid panicWritten by Cursor Bugbot for commit a1931b6. This will update automatically on new commits. Configure here.