Skip to content

Conversation

richardgreg
Copy link

@richardgreg richardgreg commented Sep 16, 2025

feat: improve randomize_state field coverage for fork transition testing

Description

  • This PR improves the randomize_state function to populate beacon state fields with realistic non-default values during testing.
  • Currently, when clients forget to copy fields during upgrades, tests don't catch these
    bugs because 0 == 0 assertions still pass, as demonstrated in the issue description with the Teku client. By using realistic test values, missing field copies now cause test failures
  • randomize_state field population now extended to all forks

Relations

Fixes #4535

Co-authored by Claude

@richardgreg
Copy link
Author

@jtraglia, do you think it is necessary to populate the fields for previous forks?

@jtraglia
Copy link
Member

@jtraglia, do you think it is necessary to populate the fields for previous forks?

Yes, it would be valuable to do this. Please complete the TODO items you've stated in the functions.

Sorry I just haven't had enough time to properly review your PR. Given that this change will affect lots tests for several forks, it will require a more extensive review. In the mean time, I've started the CI checks for this.

I would like for @leolara to review it too. He's in charge of testing here.

@jtraglia jtraglia requested a review from leolara September 19, 2025 14:58
@jtraglia jtraglia added the testing CI, actions, tests label Sep 19, 2025
@richardgreg richardgreg force-pushed the feat/state-field-randomization-improvement branch 2 times, most recently from 5c00326 to 537e0d0 Compare September 26, 2025 18:24
@richardgreg
Copy link
Author

Hi @leolara, what are your thoughts?


def _randomize_phase0_fields(spec, state):
"""Set Phase0-specific fields to realistic non-default values."""
if is_post_altair(spec):
Copy link
Member

Choose a reason for hiding this comment

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

@richardgreg I think this ìf` either should not be here or throw an exception. Like it should not be allowed to call this function in the phase that is not supposed to be used. I search our code base and there are no examples like this, I think.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

You're right, Leo. It's a counterproductive measure

@leolara
Copy link
Member

leolara commented Oct 8, 2025

@richardgreg richardgreg force-pushed the feat/state-field-randomization-improvement branch 2 times, most recently from 741a30e to 1f7da1b Compare October 9, 2025 07:48
@leolara
Copy link
Member

leolara commented Oct 9, 2025

@richardgreg let me know if I should try to run the tests again

* Add Electra churn field randomization
* Add withdrawal field randomization for Capella+ forks
* Add finality checkpoint randomization with safety checks
* Add pending operations randomization
* Randomize fields for all forks transitioning from phase0 to Electra
@richardgreg richardgreg force-pushed the feat/state-field-randomization-improvement branch from 1f7da1b to ca9f91e Compare October 10, 2025 10:06
@richardgreg
Copy link
Author

richardgreg commented Oct 10, 2025

@richardgreg let me know if I should try to run the tests again

@leolara sure. You can go ahead and do it. My branch is up-to-date and it generates the reftests locally. I'm hoping that will fix any conflict arising in the CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing CI, actions, tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fully populate state fields in randomize_state

3 participants