Skip to content

test_sstore_direct_call_same_contract()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_sstore_direct_call_same_contract@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_sstore_direct_call_same_contract --fork Amsterdam

Test SSTORE state gas charged when calling the contract directly.

Baseline comparison: calling the contract directly (not via a delegation pointer) charges SSTORE state gas identically.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
@pytest.mark.valid_from("EIP8037")
def test_sstore_direct_call_same_contract(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test SSTORE state gas charged when calling the contract directly.

    Baseline comparison: calling the contract directly (not via a
    delegation pointer) charges SSTORE state gas identically.
    """
    storage = Storage()
    contract_code = Op.SSTORE(storage.store_next(1), 1)
    contract = pre.deploy_contract(code=contract_code)

    intrinsic_execution = fork.transaction_intrinsic_cost_calculator()(
        return_cost_deducted_prior_execution=True,
    )
    top_frame_execution = fork.transaction_top_frame_execution_gas(
        recipient_type=RecipientType.CONTRACT,
    )
    top_frame_state = fork.transaction_top_frame_state_gas(
        recipient_type=RecipientType.CONTRACT,
    )
    assert top_frame_state == 0

    block_execution = (
        intrinsic_execution
        + top_frame_execution
        + contract_code.execution_cost(fork)
    )
    block_state = top_frame_state + contract_code.state_cost(fork)
    assert block_state > block_execution

    sender = pre.fund_eoa()
    tx = Transaction(
        to=contract,
        state_gas_reservoir=block_state,
        sender=sender,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=block_execution + block_state,
        ),
    )

    post = {contract: Account(storage=storage)}
    state_test(
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(
            gas_used=max(block_execution, block_state)
        ),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.