Skip to content

Commit

Permalink
new(tests) deep and wide subcontainers
Browse files Browse the repository at this point in the history
EOF tests for a very deeply nested container and one level of all
possible containers.

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon committed Jul 26, 2024
1 parent 247c8d3 commit a660949
Showing 1 changed file with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ethereum_test_tools.eof.v1 import Container, ContainerKind, Section
from ethereum_test_tools.eof.v1.constants import MAX_BYTECODE_SIZE
from ethereum_test_tools.vm.opcode import Opcodes as Op
from ethereum_test_types.eof.v1.constants import MAX_INITCODE_SIZE

from .. import EOF_FORK_NAME
from .helpers import slot_code_worked, value_code_worked
Expand Down Expand Up @@ -468,3 +469,79 @@ def test_container_both_kinds_different_sub(eof_test: EOFTestFiller):
kind=ContainerKind.INITCODE,
),
)


def test_deep_container(eof_test: EOFTestFiller):
"""Test a very deeply nested container"""

container = Container(
sections=[
Section.Code(
code=Op.PUSH0 + Op.PUSH0 + Op.PUSH0 + Op.PUSH0 + Op.EOFCREATE[0] + Op.STOP,
),
Section.Container(
container=Container(
sections=[
Section.Code(
code=Op.PUSH0 + Op.PUSH0 + Op.RETURNCONTRACT[0],
),
stop_sub_container,
]
)
),
]
)
last_container = container
while len(container) < MAX_INITCODE_SIZE:
last_container = container
container = Container(
sections=[
Section.Code(
code=Op.PUSH0 + Op.PUSH0 + Op.PUSH0 + Op.PUSH0 + Op.EOFCREATE[0] + Op.STOP,
),
Section.Container(
container=Container(
sections=[
Section.Code(
code=Op.PUSH0 + Op.PUSH0 + Op.RETURNCONTRACT[0],
),
Section.Container(container=last_container),
]
)
),
]
)

eof_test(data=last_container)


def test_wide_container(eof_test: EOFTestFiller):
"""Test a container with the maximum number of sub-containers"""
create_code = Op.STOP
for x in range(0, 256):
create_code = Op.EOFCREATE[x](0, 0, 0, 0) + create_code

eof_test(
data=Container(
sections=[
Section.Code(
code=create_code,
),
*(
[
Section.Container(
container=Container(
sections=[
Section.Code(
code=Op.PUSH0 + Op.PUSH0 + Op.RETURNCONTRACT[0],
),
stop_sub_container,
]
)
)
]
* 256
),
]
)
)

0 comments on commit a660949

Please sign in to comment.