|
| 1 | +import random |
| 2 | +from eth2spec.test.helpers.state import next_epoch |
| 3 | + |
1 | 4 | from eth2spec.test.context import ( |
2 | 5 | always_bls, |
3 | 6 | spec_state_test, |
@@ -349,6 +352,48 @@ def test_process_execution_payload_bid_slashed_builder(spec, state): |
349 | 352 | yield from run_execution_payload_bid_processing(spec, state, block, valid=False) |
350 | 353 |
|
351 | 354 |
|
| 355 | +@with_gloas_and_later |
| 356 | +@spec_state_test |
| 357 | +def test_process_block_then_slash_non_timely_builder(spec, state): |
| 358 | + """ |
| 359 | + Test proposer is rewarded if builder is slashed after a successful bid. |
| 360 | + This test case tests the third fork choice - "Empty", The beacon block has been included on-chain, but the committed execution payload has not. |
| 361 | + The beacon block proposer received payment from the corresponding builder. |
| 362 | + """ |
| 363 | + |
| 364 | + # Advance to a state past genesis so the builder is active |
| 365 | + next_epoch(spec, state) |
| 366 | + next_epoch(spec, state) |
| 367 | + state.slot += random.randrange(spec.SLOTS_PER_EPOCH) |
| 368 | + |
| 369 | + # Prepare block and assign a builder who is not the proposer |
| 370 | + block, builder_index = prepare_block_with_non_proposer_builder(spec, state) |
| 371 | + proposer_index = block.proposer_index |
| 372 | + |
| 373 | + # Give builder enough balance for the bid to succeed |
| 374 | + value = spec.Gwei(1_000_000) |
| 375 | + state.balances[builder_index] = value + spec.MIN_ACTIVATION_BALANCE |
| 376 | + |
| 377 | + # Prepare and insert a valid signed bid from the builder |
| 378 | + signed_bid = prepare_signed_execution_payload_bid( |
| 379 | + spec, |
| 380 | + state, |
| 381 | + builder_index=builder_index, |
| 382 | + value=value, |
| 383 | + slot=block.slot, |
| 384 | + parent_block_root=block.parent_root, |
| 385 | + ) |
| 386 | + # block.body.signed_execution_payload_bid = signed_bid |
| 387 | + |
| 388 | + # Capture proposer balance before processing |
| 389 | + pre_balance = state.balances[proposer_index] |
| 390 | + |
| 391 | + spec.process_block(state, block) |
| 392 | + |
| 393 | + post_balance = state.balances[proposer_index] |
| 394 | + assert post_balance >= pre_balance + value, "Proposer did not receive builder's slashed bid value" |
| 395 | + |
| 396 | + |
352 | 397 | @with_gloas_and_later |
353 | 398 | @spec_state_test |
354 | 399 | def test_process_execution_payload_bid_self_build_non_zero_value(spec, state): |
|
0 commit comments