Skip to content

Commit

Permalink
refactor(tests): parametrize CALLF execution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Oct 24, 2024
1 parent 0ed27a0 commit e9d31bb
Showing 1 changed file with 57 additions and 85 deletions.
142 changes: 57 additions & 85 deletions tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)


def test_callf_stack_size_1024(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in called function"""
eof_state_test(
data=Container(
@pytest.mark.parametrize(
"container",
(
Container(
name="no_inputs",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
Expand All @@ -45,16 +44,8 @@ def test_callf_stack_size_1024(
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_with_inputs_stack_size_1024(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in called function with inputs"""
eof_state_test(
data=Container(
Container(
name="with_inputs",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
Expand All @@ -72,16 +63,8 @@ def test_callf_with_inputs_stack_size_1024(
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_stack_size_1024_at_callf(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in called function at CALLF instruction"""
eof_state_test(
data=Container(
Container(
name="at_callf",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
Expand All @@ -107,16 +90,8 @@ def test_callf_stack_size_1024_at_callf(
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_stack_size_1024_at_push(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in nested called function at PUSH0 instruction"""
eof_state_test(
data=Container(
Container(
name="at_push0",
sections=[
Section.Code(
code=Op.PUSH0 * 1022
Expand Down Expand Up @@ -144,90 +119,80 @@ def test_callf_stack_size_1024_at_push(
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_stack_overflow(
eof_state_test: EOFStateTestFiller,
):
"""Test stack overflowing 1024 items in called function"""
eof_state_test(
data=Container(
Container(
name="nested_with_inputs_at_push0",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
code=Op.PUSH0 * 1022
+ Op.CALLF[1]
+ Op.POP * 1023
+ Op.POP * 1022
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1023,
max_stack_height=1022,
),
Section.Code(
Op.PUSH0 +
# Stack has 1024 items
# Stack has 1023 items
Op.CALLF[2] + Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
Section.Code(
Op.PUSH0 +
# Runtime stack overflow
# Stack has 1024 items
Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
],
),
container_post=Account(storage={slot_code_worked: 0}),
),
ids=lambda x: x.name,
)
def test_callf_operand_stack_size_max(eof_state_test: EOFStateTestFiller, container: Container):
"""Test operand stack reaching 1024 items"""
eof_state_test(
data=container,
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_with_inputs_stack_size_1024_at_push(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in nested called function with inputs at PUSH0 instruction"""
eof_state_test(
data=Container(
@pytest.mark.parametrize(
"container",
(
Container(
name="no_inputs",
sections=[
Section.Code(
code=Op.PUSH0 * 1022
code=Op.PUSH0 * 1023
+ Op.CALLF[1]
+ Op.POP * 1022
+ Op.POP * 1023
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1022,
max_stack_height=1023,
),
Section.Code(
Op.PUSH0 +
# Stack has 1023 items
# Stack has 1024 items
Op.CALLF[2] + Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
),
Section.Code(
Op.PUSH0 +
# Stack has 1024 items
# Runtime stack overflow
Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_with_inputs_stack_overflow(
eof_state_test: EOFStateTestFiller,
):
"""Test stack overflowing 1024 items in called function with inputs"""
eof_state_test(
data=Container(
Container(
name="with_inputs",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
Expand Down Expand Up @@ -255,6 +220,13 @@ def test_callf_with_inputs_stack_overflow(
),
],
),
),
ids=lambda x: x.name,
)
def test_callf_operand_stack_overflow(eof_state_test: EOFStateTestFiller, container: Container):
"""Test stack overflowing 1024 items in called function"""
eof_state_test(
data=container,
container_post=Account(storage={slot_code_worked: 0}),
)

Expand Down

0 comments on commit e9d31bb

Please sign in to comment.