Skip to content

test_eof_example()

Documentation for tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_eof_example.py::test_eof_example@49a16fac.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_eof_example.py::test_eof_example --fork Osaka

Example of python EOF classes.

Source code in tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_eof_example.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def test_eof_example(eof_test: EOFTestFiller):
    """Example of python EOF classes."""
    # Lets construct an EOF container code
    eof_code = Container(
        name="valid_container_example",
        sections=[
            # TYPES section is constructed automatically based on CODE
            # CODE section
            Section.Code(
                code=Op.CALLF[1](Op.PUSH0) + Op.STOP,  # bytecode to be deployed in the body
                # Code: call section 1 with a single zero as input, then stop.
                max_stack_height=1,  # define code header (in body) stack size
            ),
            # There can be multiple code sections
            Section.Code(
                # Remove input and call section 2 with no inputs, then remove output and return
                code=Op.POP + Op.CALLF[2]() + Op.POP + Op.RETF,
                code_inputs=1,
                code_outputs=0,
                max_stack_height=1,
            ),
            Section.Code(
                # Call section 3 with two inputs (address twice), return
                code=Op.CALLF[3](Op.DUP1, Op.ADDRESS) + Op.POP + Op.POP + Op.RETF,
                code_outputs=1,
                max_stack_height=3,
            ),
            Section.Code(
                # Duplicate one input and return
                code=Op.DUP1 + Op.RETF,
                code_inputs=2,
                code_outputs=3,
                max_stack_height=3,
            ),
            # DATA section
            Section.Data("0xef"),
        ],
    )

    # This will construct a valid EOF container with these bytes
    assert bytes(eof_code) == bytes.fromhex(
        "ef0001010010020004000500060008000204000100008000010100000100010003020300035fe300010050"
        "e3000250e43080e300035050e480e4ef"
    )

    eof_test(
        container=eof_code,
        expect_exception=eof_code.validity_error,
    )

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated)
...fork_Osaka-eof_test