test: cover execution payload envelope withdrawals mismatch#9252
test: cover execution payload envelope withdrawals mismatch#9252lodekeeper wants to merge 1 commit intoChainSafe:unstablefrom
Conversation
|
@lodekeeper these don't seem useful, closing |
There was a problem hiding this comment.
Code Review
This pull request introduces unit tests for the processExecutionPayloadEnvelope function, covering successful payload processing and error handling for withdrawal mismatches. The review feedback recommends replacing the magic number 8192 with the SLOTS_PER_HISTORICAL_ROOT constant from @lodestar/params to improve code robustness and maintainability across different network configurations.
| @@ -0,0 +1,102 @@ | |||
| import {describe, expect, it, vi} from "vitest"; | |||
There was a problem hiding this comment.
Import SLOTS_PER_HISTORICAL_ROOT from @lodestar/params to avoid using magic numbers in the test assertions. This ensures the test remains correct across different network presets (e.g., mainnet vs minimal).
| import {describe, expect, it, vi} from "vitest"; | |
| import {describe, expect, it, vi} from "vitest"; | |
| import {SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params"; |
| }); | ||
|
|
||
| expect(result.latestBlockHash).toEqual(blockHash); | ||
| expect(result.executionPayloadAvailability.set).toHaveBeenCalledWith(result.slot % 8192, true); |
There was a problem hiding this comment.
Use the SLOTS_PER_HISTORICAL_ROOT constant instead of the hardcoded magic number 8192. This aligns the test with the implementation in processExecutionPayloadEnvelope.ts and makes it more robust.
| expect(result.executionPayloadAvailability.set).toHaveBeenCalledWith(result.slot % 8192, true); | |
| expect(result.executionPayloadAvailability.set).toHaveBeenCalledWith(result.slot % SLOTS_PER_HISTORICAL_ROOT, true); |
|
Ack, thanks — understood. |
Summary
Adds the first direct unit coverage for
processExecutionPayloadEnvelope()inpackages/state-transition. Previously there were zero tests exercising this state-transition seam.Two assertions:
withdrawalshash matchesstate.payloadExpectedWithdrawalsprocesses cleanly and caches the payload hash on the state.withdrawals_rootdiffers fromstate.payloadExpectedWithdrawalsthrows immediately fromprocessExecutionPayloadEnvelope().Context
Surfaced from the v1.42.0 "Withdrawal mismatch at index=0" investigation. The cache-aliasing root cause is addressed in #9246; this PR is test-only coverage pinning the state-transition-side contract so a regression at this seam would fail an isolated unit test, independent of the loadState cache path.
The test uses a minimal mocked Gloas state surface rather than full cached-state construction, since the seam only needs a small subset of
CachedBeaconStateGloaswhen signature/state-root verification are disabled.Test plan
pnpm lint packages/state-transition/test/unit/block/processExecutionPayloadEnvelope.test.tspnpm test:unit packages/state-transition/test/unit/block/processExecutionPayloadEnvelope.test.ts→ 2/2 passingprocessWithdrawals.test.tsunaffected → 7/7 passingAI assistance
Drafted and validated with AI assistance.