test(cache): add unit tests for SlashingsCache#257
test(cache): add unit tests for SlashingsCache#257wemeetagain merged 1 commit intoChainSafe:mainfrom
Conversation
Add comprehensive unit tests covering: - initEmpty creates empty cache with null slot - initFromValidators populates slashed bits correctly - isInitialized checks slot matching - recordValidatorSlashing requires initialization - recordValidatorSlashing grows bitset capacity - clone creates independent copy 🤖 Generated with AI assistance
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a comprehensive suite of unit tests for the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds a solid and comprehensive set of unit tests for SlashingsCache, covering its core functionality like initialization, recording slashings, and cloning. The tests are well-structured and effectively validate the cache's behavior. I've made a few suggestions to use more idiomatic Zig for initialization, to adhere to the comment formatting style, and to add a test for an edge case to further improve test coverage, in line with the repository's style guide on exhaustive testing.
| var validators: [5]Validator = undefined; | ||
| @memset(std.mem.asBytes(&validators), 0); |
| var validators: [5]Validator = undefined; | ||
| @memset(std.mem.asBytes(&validators), 0); | ||
|
|
||
| // Mark validators 1 and 3 as slashed |
There was a problem hiding this comment.
| try std.testing.expect(!cache.isSlashed(2)); | ||
| try std.testing.expect(cache.isSlashed(3)); | ||
| try std.testing.expect(!cache.isSlashed(4)); | ||
| } |
There was a problem hiding this comment.
The tests for initFromValidators are good. To improve test exhaustiveness, as encouraged by the style guide (line 81: "tests must test exhaustively"), please consider adding a test case for when initFromValidators is called with an empty validators slice. This would verify correct handling of this important edge case.
| var validators: [3]Validator = undefined; | ||
| @memset(std.mem.asBytes(&validators), 0); |
Add comprehensive unit tests for
SlashingsCachecovering:initEmptycreates empty cache with null slotinitFromValidatorspopulates slashed bits correctlyisInitializedchecks slot matchingrecordValidatorSlashingrequires initialization (errors on uninitialized)recordValidatorSlashinggrows bitset capacity for high validator indicesclonecreates independent copy (mutations don't cross)These tests exercise the core cache API without needing a full BeaconState, ensuring correctness of the bitset-based slashing tracking.
🤖 Generated with AI assistance