Skip to content

Test Section Order

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

Generate fixtures for these test cases for Prague with:

Prague only:

fill -v tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_section_order.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_section_order.py --until=Prague --evm-bin=/path/to/evm-tool-dev-version

Different variations of EOF sections displacement

test_section_order(eof_test, section_kind, section_test, test_position)

Test sections order and it appearance in body and header

Source code in tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_section_order.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
@pytest.mark.parametrize("section_kind", [SectionKind.TYPE, SectionKind.CODE, SectionKind.DATA])
@pytest.mark.parametrize("section_test", [SectionTest.MISSING, SectionTest.WRONG_ORDER])
@pytest.mark.parametrize(
    "test_position", [CasePosition.BODY, CasePosition.HEADER, CasePosition.BODY_AND_HEADER]
)
def test_section_order(
    eof_test: EOFTestFiller,
    section_kind: SectionKind,
    section_test: SectionTest,
    test_position: CasePosition,
):
    """
    Test sections order and it appearance in body and header
    """

    def calculate_skip_flag(kind, position) -> bool:
        return (
            False
            if (section_kind != kind)
            else (
                True
                if section_test == SectionTest.MISSING
                and (test_position == position or test_position == CasePosition.BODY_AND_HEADER)
                else False
            )
        )

    def make_section_order(kind) -> List[Section]:
        if section_test != SectionTest.WRONG_ORDER:
            return [section_type, section_code, section_data]
        if kind == SectionKind.TYPE:
            return [section_code, section_type, section_data]
        if kind == SectionKind.CODE:
            return [section_type, section_data, section_code]
        if kind == SectionKind.DATA:
            return [section_data, section_type, section_code]
        return [section_type, section_code, section_data]

    section_code = Section.Code(
        code=Op.ADDRESS + Op.POP + Op.STOP,
        skip_header_listing=calculate_skip_flag(SectionKind.CODE, CasePosition.HEADER),
        skip_body_listing=calculate_skip_flag(SectionKind.CODE, CasePosition.BODY),
    )
    section_type = Section(
        kind=SectionKind.TYPE,
        data=bytes.fromhex("00800001"),
        custom_size=4,
        skip_header_listing=calculate_skip_flag(SectionKind.TYPE, CasePosition.HEADER),
        skip_body_listing=calculate_skip_flag(SectionKind.TYPE, CasePosition.BODY),
    )
    section_data = Section.Data(
        "ef",
        skip_header_listing=calculate_skip_flag(SectionKind.DATA, CasePosition.HEADER),
        skip_body_listing=calculate_skip_flag(SectionKind.DATA, CasePosition.BODY),
    )

    eof_code = Container(
        sections=make_section_order(section_kind),
        auto_type_section=AutoSection.NONE,
        auto_sort_sections=(
            AutoSection.AUTO
            if section_test != SectionTest.WRONG_ORDER
            else (
                AutoSection.ONLY_BODY
                if test_position == CasePosition.HEADER
                else (
                    AutoSection.ONLY_HEADER
                    if test_position == CasePosition.BODY
                    else AutoSection.NONE
                )
            )
        ),
    )

    expected_code, expected_exception = get_expected_code_exception(
        section_kind, section_test, test_position
    )

    # TODO remove this after Container class implementation is reliable
    assert bytes(eof_code).hex() == bytes.fromhex(expected_code).hex()

    eof_test(
        data=eof_code,
        expect_exception=expected_exception,
    )