Skip to content

test_mixed_valid_and_invalid_auths()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_mixed_valid_and_invalid_auths@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_mixed_valid_and_invalid_auths --fork Amsterdam

Test mixed valid and invalid authorizations under the top-frame model.

Every tuple (valid or invalid) pays the intrinsic REGULAR_PER_AUTH_BASE_COST. Only the valid authorizations reach set_delegation and each writes a net-new delegation on an existing authority, paying the first-write ACCOUNT_WRITE and the top-frame AUTH_BASE; the invalid (wrong nonce) tuples are skipped and pay no top-frame charge. The receipt gas is intrinsic_regular + num_valid * (ACCOUNT_WRITE + AUTH_BASE).

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
@pytest.mark.parametrize(
    "num_valid,num_invalid",
    [
        pytest.param(1, 1, id="one_valid_one_invalid"),
        pytest.param(2, 1, id="two_valid_one_invalid"),
        pytest.param(1, 2, id="one_valid_two_invalid"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_mixed_valid_and_invalid_auths(
    state_test: StateTestFiller,
    pre: Alloc,
    num_valid: int,
    num_invalid: int,
    fork: Fork,
) -> None:
    """
    Test mixed valid and invalid authorizations under the top-frame model.

    Every tuple (valid or invalid) pays the intrinsic
    ``REGULAR_PER_AUTH_BASE_COST``. Only the valid authorizations reach
    ``set_delegation`` and each writes a net-new delegation on an existing
    authority, paying the first-write ``ACCOUNT_WRITE`` and the top-frame
    ``AUTH_BASE``; the invalid (wrong nonce) tuples are skipped and pay
    no top-frame charge. The receipt gas is ``intrinsic_regular +
    num_valid * (ACCOUNT_WRITE + AUTH_BASE)``.
    """
    contract = pre.deploy_contract(code=Op.STOP)

    valid_signers = [pre.fund_eoa() for _ in range(num_valid)]
    invalid_signers = [pre.fund_eoa() for _ in range(num_invalid)]

    authorization_list = [
        AuthorizationTuple(
            address=contract,
            nonce=0,
            signer=signer,
            creates_account=False,
            writes_delegation=True,
        )
        for signer in valid_signers
    ] + [
        AuthorizationTuple(
            address=contract,
            nonce=99,  # Wrong nonce -- skipped
            signer=signer,
            creates_account=False,
            writes_delegation=False,
            first_write=False,
        )
        for signer in invalid_signers
    ]

    intrinsic_regular, top_frame_regular, top_frame_state = _auth_gas(
        fork, authorization_list
    )
    cumulative_gas_used, header_gas_used = _receipt_and_header(
        intrinsic_regular, top_frame_regular, top_frame_state
    )

    tx = Transaction(
        to=contract,
        authorization_list=authorization_list,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=cumulative_gas_used,
        ),
    )

    post = {
        signer: Account(code=Spec7702.delegation_designation(contract))
        for signer in valid_signers
    }
    for signer in invalid_signers:
        post[signer] = Account(nonce=0, code=b"")

    state_test(
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=header_gas_used),
    )

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.