Skip to content

test_self_set_code_cost()

Documentation for tests/prague/eip7702_set_code_tx/test_gas.py::test_self_set_code_cost@21fb11c8.

Generate fixtures for these test cases for Prague with:

fill -v tests/prague/eip7702_set_code_tx/test_gas.py::test_self_set_code_cost --fork Prague

Test set to code account access cost when it delegates to itself.

Source code in tests/prague/eip7702_set_code_tx/test_gas.py
 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
@pytest.mark.parametrize("pre_authorized", [True, False])
def test_self_set_code_cost(
    state_test: StateTestFiller,
    pre: Alloc,
    pre_authorized: bool,
):
    """Test set to code account access cost when it delegates to itself."""
    if pre_authorized:
        auth_signer = pre.fund_eoa(0, delegation="Self")
    else:
        auth_signer = pre.fund_eoa(0)

    slot_call_cost = 1

    overhead_cost = 3 * len(Op.CALL.kwargs)  # type: ignore

    callee_code = CodeGasMeasure(
        code=Op.CALL(gas=0, address=auth_signer),
        overhead_cost=overhead_cost,
        extra_stack_items=1,
        sstore_key=slot_call_cost,
    )

    callee_address = pre.deploy_contract(callee_code)
    callee_storage = Storage()
    callee_storage[slot_call_cost] = 200 if not pre_authorized else 2700

    tx = Transaction(
        gas_limit=1_000_000,
        to=callee_address,
        authorization_list=[
            AuthorizationTuple(
                address=auth_signer,
                nonce=0,
                signer=auth_signer,
            ),
        ]
        if not pre_authorized
        else None,
        sender=pre.fund_eoa(),
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            callee_address: Account(storage=callee_storage),
            auth_signer: Account(
                nonce=1,
                code=Spec.delegation_designation(auth_signer),
            ),
        },
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) pre_authorized
...fork_Prague-state_test-pre_authorized_True True
...fork_Prague-state_test-pre_authorized_False False
...fork_Prague-blockchain_test_from_state_test-pre_authorized_True True
...fork_Prague-blockchain_test_from_state_test-pre_authorized_False False
...fork_Osaka-state_test-pre_authorized_True True
...fork_Osaka-state_test-pre_authorized_False False
...fork_Osaka-blockchain_test_from_state_test-pre_authorized_True True
...fork_Osaka-blockchain_test_from_state_test-pre_authorized_False False