Skip to content

test_max_initcode_size_gas_metering()

Documentation for tests/amsterdam/eip7954_increase_max_contract_size/test_max_initcode_size.py::test_max_initcode_size_gas_metering@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7954_increase_max_contract_size/test_max_initcode_size.py::test_max_initcode_size_gas_metering --fork Amsterdam

Verify initcode gas metering at the new max initcode size.

Source code in tests/amsterdam/eip7954_increase_max_contract_size/test_max_initcode_size.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@pytest.mark.parametrize(
    "gas_shortfall",
    [
        pytest.param(0, id="exact_gas"),
        pytest.param(
            1,
            id="short_one_gas",
            marks=pytest.mark.exception_test,
        ),
    ],
)
def test_max_initcode_size_gas_metering(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_shortfall: int,
) -> None:
    """Verify initcode gas metering at the new max initcode size."""
    initcode = Initcode(
        deploy_code=Op.STOP, initcode_length=fork.max_initcode_size()
    )
    alice = pre.fund_eoa()

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        calldata=initcode, contract_creation=True
    )

    tx = Transaction(
        sender=alice,
        to=None,
        data=initcode,
        gas_limit=intrinsic_gas - gas_shortfall,
        error=TransactionException.INTRINSIC_GAS_TOO_LOW
        if gas_shortfall
        else None,
    )

    post = {
        compute_create_address(address=alice, nonce=0): Account.NONEXISTENT
        if gas_shortfall
        else Account(code=Op.STOP),
    }

    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.