Skip to content

test(stf): add unit tests for processDeposit#288

Open
lodekeeper-z wants to merge 1 commit intoChainSafe:mainfrom
lodekeeper-z:test/process-deposit-tests
Open

test(stf): add unit tests for processDeposit#288
lodekeeper-z wants to merge 1 commit intoChainSafe:mainfrom
lodekeeper-z:test/process-deposit-tests

Conversation

@lodekeeper-z
Copy link
Copy Markdown
Contributor

Summary

Add 6 unit tests for process_deposit.zig — the largest untested block processor (228 lines, 0 tests).

Tests added

  1. deposit data - phase0 accessors — verifies DepositData union returns correct values from phase0 variant
  2. deposit data - electra accessors — same for electra (DepositRequest) variant
  3. addValidatorToRegistry — verifies new validator has correct effective_balance, FAR_FUTURE_EPOCH fields, inactivity scores + participation entries added
  4. applyDeposit electra - existing validator — verifies existing validator gets pending deposit (not immediate balance increase)
  5. applyDeposit electra - invalid signature — verifies invalid BLS signature is silently skipped
  6. applyDeposit electra - valid signature — verifies new validator added with balance=0 and pending deposit created

Motivation

Improves test coverage for the deposit processing path, which is critical for North Star 1 (native STF correctness).

🤖 Generated with AI assistance

Add inline tests for the deposit processing module covering:
- DepositData union accessors for phase0 and electra variants
- addValidatorToRegistry with correct effective balance, epoch fields,
  and participation entries
- applyDeposit electra path for existing validators (pending deposit)
- applyDeposit with invalid BLS signature (silently skipped)
- applyDeposit with valid signature (new validator + pending deposit)

🤖 Generated with AI assistance

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lodekeeper-z lodekeeper-z requested a review from a team as a code owner March 27, 2026 22:44
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly improves the test coverage for the deposit processing logic, which is a critical component of the state transition function. By introducing these tests, the codebase gains better validation for validator registration and deposit handling, ensuring correctness for the upcoming network upgrades.

Highlights

  • Unit Test Coverage: Added 6 comprehensive unit tests for the process_deposit.zig module, covering deposit data accessors, validator registry updates, and Electra-specific deposit application logic.
  • Documentation Update: Corrected capitalization in a documentation comment referencing the Ethereum consensus specifications.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates a doc comment for capitalization and introduces a comprehensive suite of unit tests for deposit processing in the Electra fork, covering validator registration and deposit application logic. The review feedback focuses on adhering to the repository's style guide regarding punctuation in comments and improving test clarity by replacing magic numbers with named constants.

}

/// refer to https://github.com/ethereum/consensus-specs/blob/v1.5.0/specs/electra/beacon-chain.md#new-is_valid_deposit_signature
/// Refer to https://github.com/ethereum/consensus-specs/blob/v1.5.0/specs/electra/beacon-chain.md#new-is_valid_deposit_signature
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the style guide, comments that are sentences should end with a period. While you've correctly capitalized 'Refer', please also add a period at the end of the line for full compliance.

/// Refer to https://github.com/ethereum/consensus-specs/blob/v1.5.0/specs/electra/beacon-chain.md#new-is_valid_deposit_signature.
References
  1. Comments are sentences, with a space after the slash, with a capital letter and a full stop, or a colon if they relate to something that follows. Comments after the end of a line can be phrases, with no punctuation. (link)

Comment on lines +284 to +286
var new_pubkeys: [257]BLSPubkey = undefined;
try interopPubkeysCached(257, &new_pubkeys);
const new_pubkey = new_pubkeys[256];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve clarity and avoid magic numbers, it's better to define a constant for the new validator's index. This also improves consistency with other tests in this file. You can define the array size based on this constant.

    const new_validator_index: usize = 256;
    var new_pubkeys: [new_validator_index + 1]BLSPubkey = undefined;
    try interopPubkeysCached(new_pubkeys.len, &new_pubkeys);
    const new_pubkey = new_pubkeys[new_validator_index];

Comment on lines +418 to +420
var new_pubkeys: [257]BLSPubkey = undefined;
try interopPubkeysCached(257, &new_pubkeys);
const new_pubkey = new_pubkeys[256];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve clarity and avoid magic numbers, it's better to define a constant for the new validator's index. This also improves consistency with other tests in this file. You can define the array size based on this constant.

    const new_validator_index: usize = 256;
    var new_pubkeys: [new_validator_index + 1]BLSPubkey = undefined;
    try interopPubkeysCached(new_pubkeys.len, &new_pubkeys);
    const new_pubkey = new_pubkeys[new_validator_index];

Comment on lines +474 to +475
var all_pubkeys: [257]BLSPubkey = undefined;
try interopPubkeysCached(257, &all_pubkeys);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid magic numbers and improve clarity, it's better to define the array size and the number of pubkeys to generate based on the new_validator_index constant.

    var all_pubkeys: [new_validator_index + 1]BLSPubkey = undefined;
    try interopPubkeysCached(all_pubkeys.len, &all_pubkeys);

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.

1 participant