Skip to content

Add tests for process_withdrawals block processing#4468

Closed
terencechain wants to merge 9 commits intoethereum:masterfrom
terencechain:process-wd-tests
Closed

Add tests for process_withdrawals block processing#4468
terencechain wants to merge 9 commits intoethereum:masterfrom
terencechain:process-wd-tests

Conversation

@terencechain
Copy link
Copy Markdown
Contributor

No description provided.

@terencechain terencechain force-pushed the process-wd-tests branch 3 times, most recently from 5f30233 to 6836408 Compare July 28, 2025 21:54
@ethereum-code-reviewer

This comment was marked as spam.

@ethereum-code-reviewer

This comment was marked as duplicate.

@jtraglia jtraglia added the eip7732 ePBS label Jul 29, 2025
Comment on lines +158 to +161
if is_post_eip7732(spec):
assert len(expected_withdrawals_result[0]) == 0
else:
assert len(expected_withdrawals_result) == 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is the else condition necessary if we use @with_eip7732_and_later?

Comment on lines +296 to +297
else:
expected_withdrawals = spec.get_expected_withdrawals(state)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same thing with this else block. We don't need to check is_post_eip7732.

Comment on lines +300 to +304
# Verify priority ordering: builder -> pending -> sweep
assert len(expected_withdrawals) == 3
assert expected_withdrawals[0].validator_index == builder_index # Builder first
assert expected_withdrawals[1].validator_index == pending_index # Pending second
assert expected_withdrawals[2].validator_index == sweep_index # Sweep third
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The naming here is a bit confusing. Maybe these would be better:

  • Builder payments
  • Pending partial withdrawals
  • Exit/excess withdrawals


@with_eip7732_and_later
@spec_state_test
def test_maximum_withdrawals_per_payload_limit(spec, state):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should also test for:

  • There are more than MAX_WITHDRAWALS_PER_PAYLOAD builder payments and the pending partial withdrawals queue is not empty. Assert that the builder_pending_withdrawals queue is still not empty. Assert that none of the other withdrawals were processed.
  • No builder payments, MAX_WITHDRAWALS_PER_PAYLOAD pending partial withdrawals, some sweep withdrawals. There would be sweep withdrawals because of MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP.
  • No builder payments, no pending partial withdrawals, MAX_WITHDRAWALS_PER_PAYLOAD sweep withdrawals.

Comment on lines +354 to +360
# Add multiple pending withdrawals
for i in range(3):
prepare_pending_withdrawal(spec, state, i)

# EIP-7732 limits pending withdrawals to min(MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP, MAX_WITHDRAWALS_PER_PAYLOAD - 1)
# In minimal config: min(2, 4-1) = 2
expected_withdrawals = min(3, spec.MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe add enough pending partial withdrawals for this to test the mainnet value (8) too. So maybe queue MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP withdrawals and set num_expected to that too?

Test withdrawal processing with validator not yet active.
"""
set_parent_block_full(spec, state)
validator_index = min(len(state.validators) // 2, spec.MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP - 1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this so complicated?

Comment on lines +443 to +445
validator_index = min(
len(state.validators) // 2 + 1, spec.MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP - 1
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here? Why not just index 0?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can do this in a follow up PR, but there are some missing tests that I would like to see here. We need to ensure that builders can perform the full range of "regular" withdrawals too. Eg a builder can do partial withdrawals.

set_parent_block_full(spec, state)
current_epoch = spec.get_current_epoch(state)
set_validator_fully_withdrawable(spec, state, 3, current_epoch)
state.validators[3].effective_balance = 10000000000
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer we use MIN_ACTIVATION_BALANCE here.

current_epoch = spec.get_current_epoch(state)
set_validator_fully_withdrawable(spec, state, 4, current_epoch)
state.validators[4].effective_balance = 0
state.balances[4] = 100000000
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer we use MIN_ACTIVATION_BALANCE here too.

@terencechain
Copy link
Copy Markdown
Contributor Author

thanks @jtraglia , I think I addressed everything in 63ebc37

@jtraglia
Copy link
Copy Markdown
Member

jtraglia commented Aug 4, 2025

thanks @jtraglia , I think I addressed everything in 63ebc37

Thank you. Will review these changes in a bit. We'll need @potuz to review too.

PS: The CI runners are currently broken. I've asked EF devops to look into it.

@jtraglia
Copy link
Copy Markdown
Member

jtraglia commented Aug 4, 2025

@terencechain currently failing lint checks.

@terencechain terencechain force-pushed the process-wd-tests branch 3 times, most recently from 1870941 to f07705d Compare August 4, 2025 18:37
@terencechain terencechain marked this pull request as draft August 20, 2025 22:59
@jtraglia jtraglia changed the title eip7732: add tests for process_withdrawals block processing eip7732: add tests for process_withdrawals block processing Sep 25, 2025
@leolara
Copy link
Copy Markdown
Member

leolara commented Dec 7, 2025

Most of the tests here don't assert what should be the final result. This is bad, if the specs are wrong that is passed inadvertently to the tests.

Some tests that we should add:

  • More combinations for withdrawal priorites
  • Tests with different amounts of validator withdrawing
  • Tests with different address prefixes (including builders with non-builder prefixes)
  • Slashed builders in different circustances
  • More tests with differnt convinations in the boundary of MAX_WITHDRAWALS_PER_PAYLOAD

I can work on these

@jtraglia jtraglia changed the title eip7732: add tests for process_withdrawals block processing Add tests for process_withdrawals block processing Dec 8, 2025
@leolara
Copy link
Copy Markdown
Member

leolara commented Jan 5, 2026

Most of this code has been refactored here: #4810

@leolara leolara closed this Jan 5, 2026
leolara added a commit to leolara/consensus-specs that referenced this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants