Skip to content

test_eof_example_custom_fields()

Documentation for tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_eof_example.py::test_eof_example_custom_fields@83970623.

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_custom_fields --fork Osaka

Example of python EOF container class tuning.

Source code in tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_eof_example.py
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def test_eof_example_custom_fields(eof_test: EOFTestFiller):
    """Example of python EOF container class tuning."""
    # if you need to overwrite certain structure bytes, you can use customization
    # this is useful for unit testing the eof structure format, you can reorganize sections
    # and overwrite the header bytes for testing purposes
    # most of the combinations are covered by the unit tests

    # This features are subject for development and will change in the future

    eof_code = Container(
        name="valid_container_example_2",
        magic=b"\xef\x00",  # magic can be overwritten for test purposes, (default is 0xEF00)
        version=b"\x01",  # version can be overwritten for testing purposes (default is 0x01)
        header_terminator=b"\x00",  # terminator byte can be overwritten (default is 0x00)
        extra=b"",  # extra bytes to be trailed after the container body bytes (default is None)
        sections=[
            # TYPES section is constructed automatically based on CODE
            # CODE section
            Section.Code(
                code=Op.PUSH1(2)
                + Op.STOP,  # this is the actual bytecode to be deployed in the body
                max_stack_height=1,  # define code header (in body) stack size
            ),
            # DATA section
            Section.Data(
                data="0xef",
                # custom_size overrides the size bytes, so you can put only 1 byte into data
                # but still make the header size of 2 to produce invalid section
                # if custom_size != len(data), the section will be invalid
                custom_size=1,
            ),
        ],
        # auto generate types section based on provided code sections
        # AutoSection.ONLY_BODY - means the section will be generated only for the body bytes
        # AutoSection.ONLY_BODY - means the section will be generated only for the header bytes
        auto_type_section=AutoSection.AUTO,
        # auto generate default data section (0x empty), by default is True
        auto_data_section=True,
        # auto sort section by order 01 02 03 04
        # AutoSection.ONLY_BODY - means the sorting will be done only for the body bytes
        # AutoSection.ONLY_BODY - means the section will be done only for the header bytes
        auto_sort_sections=AutoSection.AUTO,
    )

    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