test(stf): add unit tests for isValidIndexedAttestationIndices#287
test(stf): add unit tests for isValidIndexedAttestationIndices#287lodekeeper-z wants to merge 1 commit intoChainSafe:mainfrom
Conversation
Cover edge cases for the indexed attestation validation logic: - Valid sorted unique indices - Empty indices (reject) - Single index (accept) - Duplicate indices (reject) - Unsorted indices (reject) - Out-of-bounds index (reject) - Boundary index (validators_count - 1 valid, validators_count invalid) - Electra vs phase0 max indices limit 🤖 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 suite of unit tests for a critical validation function used during attestation processing. By ensuring the correctness of index validation across different protocol versions and edge cases, these tests help maintain the integrity of the state transition logic. 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 introduces a comprehensive suite of unit tests for the isValidIndexedAttestationIndices function, covering edge cases such as empty indices, duplicates, unsorted lists, and boundary conditions for both Phase0 and Electra forks. Feedback was provided to replace a magic number in the Electra test case with a named constant to improve maintainability and adhere to the style guide's principles regarding compile-time constants.
| test "isValidIndexedAttestationIndices - electra allows more indices" { | ||
| // Phase0 max = MAX_VALIDATORS_PER_COMMITTEE (2048) | ||
| // Electra max = MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT | ||
| var indices: [2049]ValidatorIndex = undefined; |
There was a problem hiding this comment.
To improve maintainability and clarity, it's better to use the preset.MAX_VALIDATORS_PER_COMMITTEE constant instead of the magic number 2049. This makes the test's intent explicit—to test one element over the phase0 limit—and ensures the test remains correct if the preset value changes.
This also aligns with the style guide's principle of using compile-time constants to document and enforce invariants.
const indices_len = preset.MAX_VALIDATORS_PER_COMMITTEE + 1;
var indices: [indices_len]ValidatorIndex = undefined;
References
- The style guide encourages asserting relationships of compile-time constants to document and enforce invariants. While not a direct assertion, using the constant here makes the relationship explicit and the code more maintainable. (link)
Add 9 unit tests for
isValidIndexedAttestationIndices, covering:validators_count - 1→ truevalidators_count→ falseThis is a pure validation function on the critical path for attestation processing — every block calls it for each attestation.
🤖 Generated with AI assistance