Skip to content

test_child_state_gas_tracked_in_parent()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_child_state_gas_tracked_in_parent@5c024cbb.

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_child_state_gas_tracked_in_parent --fork Amsterdam

Test state gas used by child is accumulated in parent.

Both parent and child perform SSTOREs. The total state gas used should reflect both operations. This is verified by the test succeeding with enough total gas but would OOG if state gas wasn't tracked across frames.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
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
@pytest.mark.valid_from("EIP8037")
def test_child_state_gas_tracked_in_parent(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test state gas used by child is accumulated in parent.

    Both parent and child perform SSTOREs. The total state gas used
    should reflect both operations. This is verified by the test
    succeeding with enough total gas but would OOG if state gas
    wasn't tracked across frames.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    child_storage = Storage()
    child = pre.deploy_contract(
        code=Op.SSTORE(child_storage.store_next(1), 1),
    )

    parent_storage = Storage()
    parent = pre.deploy_contract(
        code=(
            # Parent SSTORE
            Op.SSTORE(parent_storage.store_next(1), 1)
            # Child SSTORE
            + Op.SSTORE(
                parent_storage.store_next(1),
                Op.CALL(gas=100_000, address=child),
            )
        ),
    )

    # Provide enough reservoir for both SSTOREs
    tx = Transaction(
        to=parent,
        state_gas_reservoir=sstore_state_gas * 2,
        sender=pre.fund_eoa(),
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.