Commit 01d5ea5
authored
## 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 -->
1 file changed
Lines changed: 138 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1697 | 1697 | | |
1698 | 1698 | | |
1699 | 1699 | | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
0 commit comments