Skip to content

test_delegatecall_reservoir_passing()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_delegatecall_reservoir_passing@a9abd46e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_delegatecall_reservoir_passing --fork Amsterdam

Test DELEGATECALL passes full reservoir to child.

DELEGATECALL runs child code in the caller's storage context. The child's SSTORE writes to the parent's storage using state gas from the reservoir.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
@pytest.mark.valid_from("EIP8037")
def test_delegatecall_reservoir_passing(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test DELEGATECALL passes full reservoir to child.

    DELEGATECALL runs child code in the caller's storage context.
    The child's SSTORE writes to the parent's storage using state
    gas from the reservoir.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    parent_storage = Storage()
    # Library code runs in parent's context — slot is reserved on
    # parent_storage so the post check uses the same source of truth.
    library = pre.deploy_contract(
        code=Op.SSTORE(parent_storage.store_next(1, "delegated"), 1),
    )

    parent = pre.deploy_contract(
        code=(Op.DELEGATECALL(gas=100_000, address=library)),
    )

    tx = Transaction(
        to=parent,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    post = {parent: Account(storage=parent_storage)}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.