Skip to content

test(stf): add unit tests for processDepositRequest#293

Open
lodekeeper-z wants to merge 2 commits intoChainSafe:mainfrom
lodekeeper-z:test/process-deposit-request
Open

test(stf): add unit tests for processDepositRequest#293
lodekeeper-z wants to merge 2 commits intoChainSafe:mainfrom
lodekeeper-z:test/process-deposit-request

Conversation

@lodekeeper-z
Copy link
Copy Markdown
Contributor

Summary

Unit tests for processDepositRequest (Electra deposit request processing).

Tests added:

  • First request sets depositRequestsStartIndex — verifies UNSET → request index
  • Subsequent request preserves start index — second request doesn't overwrite
  • Pending deposit fields match request — amount and slot copied correctly
  • Already-set start index is preserved — non-UNSET value not overwritten

Coverage:

  • Both branches of the UNSET_DEPOSIT_REQUESTS_START_INDEX check
  • PendingDeposit field correctness
  • Append behavior on pendingDeposits list

🤖 Generated with AI assistance

Test coverage for Electra deposit request processing:
- First request sets depositRequestsStartIndex from UNSET
- Subsequent requests preserve existing start index
- Pending deposit fields (amount, slot) match input request
- Already-set start index is not overwritten

🤖 Generated with AI assistance
@lodekeeper-z lodekeeper-z requested a review from a team as a code owner March 28, 2026 12:45
@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 introduces a comprehensive suite of unit tests for the processDepositRequest function, specifically targeting its behavior within the Electra fork. The tests ensure the correct initialization and preservation of the depositRequestsStartIndex, as well as the accurate mapping of deposit request fields to pending deposits, thereby enhancing the reliability and correctness of the state transition logic.

Highlights

  • First request sets depositRequestsStartIndex: Verifies that when the depositRequestsStartIndex is UNSET, the first deposit request correctly initializes it to the request's index.
  • Subsequent request preserves start index: Ensures that processing a second deposit request does not overwrite an already set depositRequestsStartIndex.
  • Pending deposit fields match request: Confirms that the amount and slot fields of a pending deposit are accurately copied from the incoming deposit request.
  • Already-set start index is preserved: Validates that if the depositRequestsStartIndex is already set to a non-UNSET value, it remains unchanged upon processing new deposit requests.

🧠 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 introduces a suite of unit tests for the processDepositRequest function, specifically targeting the Electra fork logic. The tests verify the initialization and persistence of the depositRequestsStartIndex and the correct mapping of request fields to pending deposits. Review feedback suggests increasing assertion density in helper functions to comply with the project's style guide and expanding test coverage to verify all fields of the pending deposit, such as pubkey and signature, rather than just amount and slot.

Comment on lines +34 to +40
return DepositRequest{
.pubkey = [_]u8{@as(u8, @intCast(index & 0xFF))} ** 48,
.withdrawal_credentials = [_]u8{0x01} ++ [_]u8{0} ** 11 ++ [_]u8{0xAA} ** 20,
.amount = 32_000_000_000,
.signature = [_]u8{0} ** 96,
.index = index,
};
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

The style guide (lines 51, 55) mandates assertions on function arguments. This function is missing them. Please add an assertion to validate the index argument, for example, to ensure it's not a sentinel value.

    assert(index != c.UNSET_DEPOSIT_REQUESTS_START_INDEX);
    return DepositRequest{
        .pubkey = [_]u8{@as(u8, @intCast(index & 0xFF))} ** 48,
        .withdrawal_credentials = [_]u8{0x01} ++ [_]u8{0} ** 11 ++ [_]u8{0xAA} ** 20,
        .amount = 32_000_000_000,
        .signature = [_]u8{0} ** 96,
        .index = index,
    };
References
  1. Assert all function arguments and return values, pre/postconditions and invariants. The assertion density of the code must average a minimum of two assertions per function. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a test-only helper — assertions on function arguments in the style guide are for production code paths, not test fixtures. The index value is always a literal in each test. Dismissing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a test-only helper — assertions on function arguments in the style guide are for production code paths, not test fixtures. The index value is always a literal in each test. Dismissing.

Comment on lines +113 to +121
// Verify all fields were copied correctly
// Verify amount and slot were correctly copied from the request

const amount_view = try deposit.get("amount");
try testing.expectEqual(@as(u64, 32_000_000_000), amount_view);

const slot_view = try deposit.get("slot");
const state_slot = try state.slot();
try testing.expectEqual(state_slot, slot_view);
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

This test is incomplete as it only verifies amount and slot. To ensure full correctness and prevent regressions, it should also verify that pubkey, withdrawal_credentials, and signature are copied correctly from the request to the PendingDeposit.

Also, it's better to compare against request.amount instead of a hardcoded value to make the test more resilient to changes in makeDepositRequest.

    // Verify all fields were copied correctly.
    const pubkey_view = try deposit.get("pubkey");
    var actual_pubkey: [48]u8 = undefined;
    _ = try pubkey_view.getAllInto(actual_pubkey[0..]);
    try testing.expectEqualSlices(u8, &request.pubkey, &actual_pubkey);

    const withdrawal_credentials_view = try deposit.get("withdrawal_credentials");
    var actual_withdrawal_credentials: [32]u8 = undefined;
    _ = try withdrawal_credentials_view.getAllInto(actual_withdrawal_credentials[0..]);
    try testing.expectEqualSlices(
        u8,
        &request.withdrawal_credentials,
        &actual_withdrawal_credentials,
    );

    const signature_view = try deposit.get("signature");
    var actual_signature: [96]u8 = undefined;
    _ = try signature_view.getAllInto(actual_signature[0..]);
    try testing.expectEqualSlices(u8, &request.signature, &actual_signature);

    const amount_view = try deposit.get("amount");
    try testing.expectEqual(request.amount, amount_view);

    const slot_view = try deposit.get("slot");
    const state_slot = try state.slot();
    try testing.expectEqual(state_slot, slot_view);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point on field verification. I'll add pubkey, withdrawal_credentials, and signature checks using getAllInto, and reference request.amount instead of the hardcoded value. Pushing a fix.

Verify pubkey, withdrawal_credentials, and signature fields are copied
correctly. Use request.amount instead of hardcoded value for resilience.

Addresses review feedback from gemini-code-assist.

🤖 Generated with AI assistance
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