Skip to content

test_section_order()

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

Generate fixtures for these test cases for Osaka with:

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

Test sections order and it appearance in body and header.

Source code in tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_section_order.py
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
211
212
213
214
215
216
217
218
219
220
@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),
    )

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

    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_bytecode=expected_code,
    )

    eof_test(
        container=eof_code,
        expect_exception=expected_exception,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) test_position section_test section_kind
...fork_Osaka-eof_test-test_position_CasePosition.BODY-section_test_SectionTest.MISSING-section_kind_TYPE CasePosition.BODY SectionTest.MISSING TYPE
...fork_Osaka-eof_test-test_position_CasePosition.BODY-section_test_SectionTest.MISSING-section_kind_CODE CasePosition.BODY SectionTest.MISSING CODE
...fork_Osaka-eof_test-test_position_CasePosition.BODY-section_test_SectionTest.MISSING-section_kind_DATA CasePosition.BODY SectionTest.MISSING DATA
...fork_Osaka-eof_test-test_position_CasePosition.BODY-section_test_SectionTest.WRONG_ORDER-section_kind_TYPE CasePosition.BODY SectionTest.WRONG_ORDER TYPE
...fork_Osaka-eof_test-test_position_CasePosition.BODY-section_test_SectionTest.WRONG_ORDER-section_kind_CODE CasePosition.BODY SectionTest.WRONG_ORDER CODE
...fork_Osaka-eof_test-test_position_CasePosition.BODY-section_test_SectionTest.WRONG_ORDER-section_kind_DATA CasePosition.BODY SectionTest.WRONG_ORDER DATA
...fork_Osaka-eof_test-test_position_CasePosition.HEADER-section_test_SectionTest.MISSING-section_kind_TYPE CasePosition.HEADER SectionTest.MISSING TYPE
...fork_Osaka-eof_test-test_position_CasePosition.HEADER-section_test_SectionTest.MISSING-section_kind_CODE CasePosition.HEADER SectionTest.MISSING CODE
...fork_Osaka-eof_test-test_position_CasePosition.HEADER-section_test_SectionTest.MISSING-section_kind_DATA CasePosition.HEADER SectionTest.MISSING DATA
...fork_Osaka-eof_test-test_position_CasePosition.HEADER-section_test_SectionTest.WRONG_ORDER-section_kind_TYPE CasePosition.HEADER SectionTest.WRONG_ORDER TYPE
...fork_Osaka-eof_test-test_position_CasePosition.HEADER-section_test_SectionTest.WRONG_ORDER-section_kind_CODE CasePosition.HEADER SectionTest.WRONG_ORDER CODE
...fork_Osaka-eof_test-test_position_CasePosition.HEADER-section_test_SectionTest.WRONG_ORDER-section_kind_DATA CasePosition.HEADER SectionTest.WRONG_ORDER DATA
...fork_Osaka-eof_test-test_position_CasePosition.BODY_AND_HEADER-section_test_SectionTest.MISSING-section_kind_TYPE CasePosition.BODY_AND_HEADER SectionTest.MISSING TYPE
...fork_Osaka-eof_test-test_position_CasePosition.BODY_AND_HEADER-section_test_SectionTest.MISSING-section_kind_CODE CasePosition.BODY_AND_HEADER SectionTest.MISSING CODE
...fork_Osaka-eof_test-test_position_CasePosition.BODY_AND_HEADER-section_test_SectionTest.MISSING-section_kind_DATA CasePosition.BODY_AND_HEADER SectionTest.MISSING DATA
...fork_Osaka-eof_test-test_position_CasePosition.BODY_AND_HEADER-section_test_SectionTest.WRONG_ORDER-section_kind_TYPE CasePosition.BODY_AND_HEADER SectionTest.WRONG_ORDER TYPE
...fork_Osaka-eof_test-test_position_CasePosition.BODY_AND_HEADER-section_test_SectionTest.WRONG_ORDER-section_kind_CODE CasePosition.BODY_AND_HEADER SectionTest.WRONG_ORDER CODE
...fork_Osaka-eof_test-test_position_CasePosition.BODY_AND_HEADER-section_test_SectionTest.WRONG_ORDER-section_kind_DATA CasePosition.BODY_AND_HEADER SectionTest.WRONG_ORDER DATA