test(stf): add unit tests for processDepositRequest#293
test(stf): add unit tests for processDepositRequest#293lodekeeper-z wants to merge 2 commits intoChainSafe:mainfrom
Conversation
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
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 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.
| 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, | ||
| }; |
There was a problem hiding this comment.
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
- 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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| // 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); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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
Summary
Unit tests for
processDepositRequest(Electra deposit request processing).Tests added:
Coverage:
UNSET_DEPOSIT_REQUESTS_START_INDEXcheckpendingDepositslist🤖 Generated with AI assistance