Skip to content

test_max_code_size_self_opcodes()

Documentation for tests/amsterdam/eip7954_increase_max_contract_size/test_max_code_size.py::test_max_code_size_self_opcodes@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7954_increase_max_contract_size/test_max_code_size.py::test_max_code_size_self_opcodes --fork Amsterdam

Ensure self code opcodes work with the new max contract size.

Tested via DELEGATECALL so opcodes operate on the large contract's own code while writing results to the caller's storage.

Source code in tests/amsterdam/eip7954_increase_max_contract_size/test_max_code_size.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
def test_max_code_size_self_opcodes(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Ensure self code opcodes work with the new max contract size.

    Tested via DELEGATECALL so opcodes operate on the large
    contract's own code while writing results to the caller's
    storage.
    """
    logic = (
        Op.SSTORE(0, Op.CODESIZE)
        + Op.CODECOPY(0, 0, Op.CODESIZE)
        + Op.SSTORE(1, Op.SHA3(0, Op.CODESIZE))
        + Op.STOP
    )
    target_code = logic + Op.JUMPDEST * (fork.max_code_size() - len(logic))
    target = pre.deterministic_deploy_contract(deploy_code=target_code)

    alice = pre.fund_eoa()
    oracle = pre.deploy_contract(
        code=Op.DELEGATECALL(gas=Op.GAS, address=target)
    )

    tx = Transaction(
        sender=alice,
        to=oracle,
        gas_limit=fork.transaction_gas_limit_cap(),
    )

    post = {
        oracle: Account(
            storage={
                0: len(target_code),
                1: keccak256(bytes(target_code)),
            }
        )
    }

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.