Skip to content

test_bal_7702_top_frame_delegation_oog()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_top_frame_delegation_oog@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_top_frame_delegation_oog --fork Amsterdam

Ensure the delegation target of a delegated tx.to enters the BAL only when gas covers the top-frame delegation charge.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
@pytest.mark.parametrize(
    "outcome",
    [
        pytest.param("oog", id="oog_at_delegation_charge"),
        pytest.param("success", id="success"),
    ],
)
def test_bal_7702_top_frame_delegation_oog(
    fork: Fork,
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    outcome: str,
) -> None:
    """
    Ensure the delegation target of a delegated ``tx.to`` enters the
    BAL only when gas covers the top-frame delegation charge.
    """
    sender = pre.fund_eoa()

    delegated_to = pre.deploy_contract(code=Op.STOP)
    target = pre.fund_eoa(amount=0, delegation=delegated_to)

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        recipient_type=RecipientType.DELEGATION_7702,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_gas = fork.transaction_top_frame_gas_calculator()(
        recipient_type=RecipientType.DELEGATION_7702,
    )

    gas_limit = intrinsic_gas + top_frame_gas
    if outcome == "oog":
        gas_limit -= 1
        # The delegation charge fails, so the target is never accessed.
        delegated_to_expectation = None
    else:
        delegated_to_expectation = BalAccountExpectation.empty()

    tx = Transaction(
        sender=sender,
        to=target,
        gas_limit=gas_limit,
    )

    block = Block(
        txs=[tx],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                target: BalAccountExpectation.empty(),
                delegated_to: delegated_to_expectation,
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={sender: Account(nonce=1)},
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.