Skip to content

test_single_authorization_charges()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py::test_single_authorization_charges@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py::test_single_authorization_charges --fork Amsterdam

A single authorization on a third-party authority, spanning the action space that drives its top-frame charge.

Every valid action below is the transaction's first write to its (third-party) authority, so each pays ACCOUNT_WRITE on top of the charges listed:

  • CREATES_ACCOUNT: the authority does not exist, so the authorization also pays NEW_ACCOUNT (creation) and AUTH_BASE (net-new delegation indicator).
  • SETS_NEW_DELEGATION: an existing empty-code EOA gains a delegation, paying AUTH_BASE.
  • SETS_DIFFERENT_DELEGATION / SETS_SAME_DELEGATION: an already-delegated EOA is re-pointed (or re-pointed to the same target); it was delegated before the transaction, so no AUTH_BASE accrues. The nonce still advances.
  • CLEARS_DELEGATION: an already-delegated EOA is cleared (the authorization target is the null address); no AUTH_BASE accrues and the delegation code is removed.
  • INVALID: the authorization nonce does not match the authority's account nonce, so validate_authorization skips it. The intrinsic base cost is still paid; no top-frame charge (not even ACCOUNT_WRITE) accrues and the authority is untouched.
Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@pytest.mark.parametrize(
    "action", list(AuthorizationAction), ids=lambda a: a.name.lower()
)
def test_single_authorization_charges(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    action: AuthorizationAction,
) -> None:
    """
    A single authorization on a third-party authority, spanning the
    action space that drives its top-frame charge.

    Every valid action below is the transaction's first write to its
    (third-party) authority, so each pays ``ACCOUNT_WRITE`` on top of
    the charges listed:

    - ``CREATES_ACCOUNT``: the authority does not exist, so the
      authorization also pays ``NEW_ACCOUNT`` (creation) and
      ``AUTH_BASE`` (net-new delegation indicator).
    - ``SETS_NEW_DELEGATION``: an existing empty-code EOA gains a
      delegation, paying ``AUTH_BASE``.
    - ``SETS_DIFFERENT_DELEGATION`` / ``SETS_SAME_DELEGATION``: an
      already-delegated EOA is re-pointed (or re-pointed to the same
      target); it was delegated before the transaction, so no
      ``AUTH_BASE`` accrues. The nonce still advances.
    - ``CLEARS_DELEGATION``: an already-delegated EOA is cleared (the
      authorization target is the null address); no ``AUTH_BASE``
      accrues and the delegation code is removed.
    - ``INVALID``: the authorization nonce does not match the
      authority's account nonce, so ``validate_authorization`` skips it.
      The intrinsic base cost is still paid; no top-frame charge (not
      even ``ACCOUNT_WRITE``) accrues and the authority is untouched.
    """
    sender = pre.fund_eoa()
    recipient = pre.deploy_contract(code=Op.STOP)

    scenario = build_authorization(pre, action)
    authorization_list = [scenario.authorization]
    total_gas_cost = authorization_transaction_cost(fork, authorization_list)

    tx = Transaction(
        sender=sender,
        to=recipient,
        value=0,
        authorization_list=authorization_list,
        gas_limit=total_gas_cost,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=total_gas_cost,
        ),
    )

    post = {
        scenario.authority: scenario.applied_account,
    }

    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 6 parametrized test cases across 1 fork.