Skip to content

test_self_set_code_cost()

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

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
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
@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