Skip to content

Commit dc50745

Browse files
authored
Add test for get_builders_sweep_withdrawals (#5369)
This PR adds coverage for the `get_builders_sweep_withdrawals` function. It adds a test for the limit of how many sweep withdrawals should be processed in a single run, the standard `get_builder_withdrawals` had this covered but this was missing for the sweep withdrawals.
1 parent be49e0e commit dc50745

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

tests/core/pyspec/eth_consensus_specs/test/gloas/block_processing/test_process_withdrawals.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,3 +1558,53 @@ def test_empty_parent_preserves_populated_expected_withdrawals(spec, state):
15581558

15591559
assert_process_withdrawals(spec, state, pre_state, all_state_unchanged=True)
15601560
assert list(spec.get_expected_withdrawals(state).withdrawals) != populated_withdrawals
1561+
1562+
1563+
@with_gloas_and_later
1564+
@spec_state_test
1565+
def test_builder_sweep_withdrawals_limit(spec, state):
1566+
"""
1567+
Test that the builder sweep checks the withdrawals limit
1568+
"""
1569+
# The sweep reserves one slot for the validator sweep
1570+
sweep_limit = spec.MAX_WITHDRAWALS_PER_PAYLOAD - 1
1571+
1572+
# More eligible builders than the limit, so the limit stops the sweep
1573+
eligible_builders = list(range(sweep_limit + 1))
1574+
for builder_index in eligible_builders:
1575+
if builder_index >= len(state.builders):
1576+
add_builder_to_registry(spec, state, builder_index)
1577+
assert len(state.builders) >= len(eligible_builders)
1578+
1579+
balances = {i: spec.Gwei((i + 1) * 1_000_000_000) for i in eligible_builders}
1580+
1581+
# Setup sweep withdrawals
1582+
prepare_process_withdrawals(
1583+
spec,
1584+
state,
1585+
builder_sweep_indices=eligible_builders,
1586+
builder_balances=balances,
1587+
next_withdrawal_builder_index=0,
1588+
)
1589+
1590+
pre_state = state.copy()
1591+
yield from run_gloas_withdrawals_processing(spec, state)
1592+
1593+
withdrawn = eligible_builders[:sweep_limit]
1594+
reserved = eligible_builders[sweep_limit]
1595+
1596+
assert_process_withdrawals(
1597+
spec,
1598+
state,
1599+
pre_state,
1600+
withdrawal_count=sweep_limit,
1601+
builder_balances={
1602+
**dict.fromkeys(withdrawn, 0),
1603+
reserved: balances[reserved],
1604+
},
1605+
withdrawal_amounts_builders={i: balances[i] for i in withdrawn},
1606+
withdrawal_index_delta=sweep_limit,
1607+
)
1608+
1609+
# assert_process_withdrawals does not check the sweep cursor
1610+
assert state.next_withdrawal_builder_index == sweep_limit

0 commit comments

Comments
 (0)