Skip to content

Test Execution Function

Documentation for tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_execution_function.py.

Generate fixtures for these test cases for Prague with:

Prague only:

fill -v tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_execution_function.py --fork=Prague --evm-bin=/path/to/evm-tool-dev-version
For all forks up to and including Prague:
fill -v tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_execution_function.py --until=Prague --evm-bin=/path/to/evm-tool-dev-version

Execution of CALLF, RETF opcodes within EOF V1 containers tests

test_eof_functions_contract_call_succeed(state_test, pre, container)

Test simple contracts that are simply expected to succeed on call.

Source code in tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_execution_function.py
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
@pytest.mark.parametrize("container", CALL_SUCCEED_CONTRACTS, ids=lambda x: x.name)
def test_eof_functions_contract_call_succeed(
    state_test: StateTestFiller,
    pre: Alloc,
    container: Container,
):
    """
    Test simple contracts that are simply expected to succeed on call.
    """
    env = Environment()

    sender = pre.fund_eoa()
    container_address = pre.deploy_contract(container)
    caller_contract = Op.SSTORE(0, Op.CALL(Op.GAS, container_address, 0, 0, 0, 0, 0)) + Op.STOP()
    caller_address = pre.deploy_contract(caller_contract)

    tx = Transaction(
        to=caller_address,
        gas_limit=50000000,
        gas_price=10,
        protected=False,
        data="",
        sender=sender,
    )

    post = {caller_address: Account(storage={0: 1})}

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

test_eof_functions_contract_call_fail(state_test, pre, container)

Test simple contracts that are simply expected to fail on call.

Source code in tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_execution_function.py
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
@pytest.mark.parametrize("container", CALL_FAIL_CONTRACTS, ids=lambda x: x.name)
def test_eof_functions_contract_call_fail(
    state_test: StateTestFiller,
    pre: Alloc,
    container: Container,
):
    """
    Test simple contracts that are simply expected to fail on call.
    """
    env = Environment()

    sender = pre.fund_eoa()
    container_address = pre.deploy_contract(container)
    caller_contract = Op.SSTORE(Op.CALL(Op.GAS, container_address, 0, 0, 0, 0, 0), 1) + Op.STOP()
    caller_address = pre.deploy_contract(caller_contract)

    tx = Transaction(
        to=caller_address,
        gas_limit=50000000,
        gas_price=10,
        protected=False,
        data="",
        sender=sender,
    )

    post = {caller_address: Account(storage={0: 1})}

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

test_eof_functions_contract_call_within_deep_nested(state_test, pre)

Test performing a call within a nested callf and verify correct behavior of return stack in calling contract.

TODO: This test belongs in EIP-7069 test folder, not code validation.

Source code in tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_execution_function.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
def test_eof_functions_contract_call_within_deep_nested(
    state_test: StateTestFiller,
    pre: Alloc,
):
    """
    Test performing a call within a nested callf and verify correct behavior of
    return stack in calling contract.

    TODO: This test belongs in EIP-7069 test folder, not code validation.
    """
    env = Environment()

    nested_callee_address = pre.deploy_contract(code=Op.SSTORE(0, 1) + Op.STOP())
    contract_call_within_deep_nested_callf = Container(
        name="contract_call_within_deep_nested_callf",
        sections=[
            Section.Code(
                code=Op.CALLF[1] + Op.SSTORE(0, 1) + Op.STOP,
            )
        ]
        + [
            # All sections call next section and on return, store a 1
            # to their call stack height key
            Section.Code(
                code=(Op.CALLF[i] + Op.SSTORE(i - 1, 1) + Op.RETF),
                code_outputs=0,
            )
            for i in range(2, MAX_CODE_SECTIONS)
        ]
        + [
            # Last section makes external contract call
            Section.Code(
                code=(
                    Op.EXTCALL(nested_callee_address, 0, 0, 0)
                    + Op.ISZERO
                    + Op.PUSH2(MAX_CODE_SECTIONS - 1)
                    + Op.SSTORE
                    + Op.RETF
                ),
                code_outputs=0,
            )
        ],
    )
    callee_address = pre.deploy_contract(contract_call_within_deep_nested_callf)
    sender = pre.fund_eoa()

    tx = Transaction(
        to=callee_address,
        gas_limit=50000000,
        gas_price=10,
        protected=False,
        data="",
        sender=sender,
    )
    post = {
        callee_address: Account(storage={i: 1 for i in range(MAX_CODE_SECTIONS)}),
        nested_callee_address: Account(
            storage={
                0: 1,
            }
        ),
    }

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