Skip to content

test_self_set_code_cost()

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

Generate fixtures for these test cases for Osaka with:

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

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

Source code in tests/prague/eip7702_set_code_tx/test_gas.py
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
@pytest.mark.parametrize("pre_authorized", [True, False])
def test_self_set_code_cost(
    state_test: StateTestFiller,
    pre: Alloc,
    pre_authorized: bool,
) -> None:
    """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)

    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(
        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