Skip to content

test: add unit tests for TotalVotingPowerSafe (backport #5570)#5581

Merged
aljo242 merged 2 commits intov0.38.xfrom
mergify/bp/v0.38.x/pr-5570
Jan 21, 2026
Merged

test: add unit tests for TotalVotingPowerSafe (backport #5570)#5581
aljo242 merged 2 commits intov0.38.xfrom
mergify/bp/v0.38.x/pr-5570

Conversation

@mergify
Copy link
Copy Markdown
Contributor

@mergify mergify bot commented Jan 20, 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

  • 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

Written by Cursor Bugbot for commit a1931b6. This will update automatically on new commits. Configure here.


This is an automatic backport of pull request #5570 done by [Mergify](https://mergify.com).

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

Written by Cursor Bugbot for commit bd517d2. This will update automatically on new commits. Configure here.

- Adds TestValidatorSet_TotalVotingPowerSafe table-driven test
- Covers happy paths, boundary conditions, and overflow scenarios
- Verifies nil/empty set handling

Closes #5522

Signed-off-by: bit2swaz <bit2swaz@gmail.com>
(cherry picked from commit c602157)
The 'tc := tc' pattern is no longer needed in modern Go versions (1.22+).
This addresses reviewer feedback to clean up the code.

(cherry picked from commit e030ded)
@aljo242 aljo242 disabled auto-merge January 21, 2026 18:37
@aljo242 aljo242 merged commit 01d5ea5 into v0.38.x Jan 21, 2026
17 of 18 checks passed
@aljo242 aljo242 deleted the mergify/bp/v0.38.x/pr-5570 branch January 21, 2026 18:37
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