Skip to content

test_account_state_gas_via_delegation_pointer()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_account_state_gas_via_delegation_pointer@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_account_state_gas_via_delegation_pointer --fork Amsterdam

Test account-creating charges are billed the same via a delegation pointer as they are directly.

Delegated code runs in the authority's context, so a CREATE takes the authority's nonce and a SELFDESTRUCT moves the authority's balance. Each still bills its state charge from the reservoir, and the header reports it in the state dimension.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
@pytest.mark.parametrize(
    "state_op",
    [Op.CREATE, Op.CREATE2, Op.SELFDESTRUCT],
)
@pytest.mark.valid_from("EIP8037")
def test_account_state_gas_via_delegation_pointer(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    state_op: Op,
) -> None:
    """
    Test account-creating charges are billed the same via a delegation
    pointer as they are directly.

    Delegated code runs in the authority's context, so a CREATE takes the
    authority's nonce and a SELFDESTRUCT moves the authority's balance.
    Each still bills its state charge from the reservoir, and the header
    reports it in the state dimension.
    """
    if state_op == Op.CREATE:
        code = Op.POP(Op.CREATE(0, 0, 0))
    elif state_op == Op.CREATE2:
        code = Op.POP(Op.CREATE2(0, 0, 0, 0))
    else:
        code = Op.SELFDESTRUCT(pre.nonexistent_account(), account_new=True)
    contract = pre.deploy_contract(code=code)

    delegator = pre.fund_eoa(delegation=contract, amount=1)
    state_gas = code.state_cost(fork)
    assert state_gas > 0, "the op must carry a state charge"

    tx = Transaction(
        to=delegator,
        state_gas_reservoir=state_gas,
        sender=pre.fund_eoa(),
    )

    state_test(
        pre=pre,
        post={},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=state_gas),
    )

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.