Skip to content

Test Section Size

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

Generate fixtures for these test cases for Prague with:

Prague only:

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

EOF Container, test custom_size field for sections

test_section_size(eof_test, section_size, section_kind, exception)

Test custom_size is auto, more or less then the actual size of the section

Source code in tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_section_size.py
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
66
67
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
@pytest.mark.parametrize(
    "section_kind, section_size, exception",
    [
        (SectionKind.DATA, SectionSize.NORMAL, None),
        (SectionKind.DATA, SectionSize.UNDERSIZE, EOFException.INVALID_SECTION_BODIES_SIZE),
        (SectionKind.DATA, SectionSize.OVERSIZE, EOFException.TOPLEVEL_CONTAINER_TRUNCATED),
        (SectionKind.CODE, SectionSize.UNDERSIZE, EOFException.INVALID_SECTION_BODIES_SIZE),
        (SectionKind.CODE, SectionSize.OVERSIZE, EOFException.INVALID_SECTION_BODIES_SIZE),
        (SectionKind.CODE, SectionSize.NORMAL, None),
        (SectionKind.TYPE, SectionSize.UNDERSIZE, EOFException.INVALID_TYPE_SECTION_SIZE),
        (SectionKind.TYPE, SectionSize.OVERSIZE, EOFException.INVALID_SECTION_BODIES_SIZE),
        (SectionKind.TYPE, SectionSize.NORMAL, None),
    ],
)
def test_section_size(
    eof_test: EOFTestFiller,
    section_size: SectionSize,
    section_kind: SectionKind,
    exception: EOFException,
):
    """
    Test custom_size is auto, more or less then the actual size of the section
    """
    eof_code = Container()

    if section_size != SectionSize.NORMAL and section_kind == SectionKind.TYPE:
        eof_code.sections.append(
            Section(
                kind=SectionKind.TYPE,
                data="0x00800001",
                custom_size=section_size,
            ),
        )

    if section_size != SectionSize.NORMAL and section_kind == SectionKind.CODE:
        eof_code.sections.append(
            Section.Code(
                code=Op.ADDRESS + Op.POP + Op.STOP,
                max_stack_height=1,
                custom_size=section_size,
            )
        )
    else:
        eof_code.sections.append(
            Section.Code(
                code=Op.ADDRESS + Op.POP + Op.STOP,
                max_stack_height=1,
            )
        )

    if section_size != SectionSize.NORMAL and section_kind == SectionKind.DATA:
        eof_code.sections.append(Section.Data("0x00daaa", custom_size=section_size))
    else:
        eof_code.sections.append(Section.Data("0x00aaaa"))

    eof_test(
        data=eof_code,
        expect_exception=exception,
    )