Skip to content

Commit

Permalink
Add test variants
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Sep 6, 2024
1 parent 91c641c commit aa8c34f
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 18 deletions.
48 changes: 40 additions & 8 deletions tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,37 @@ def test_rjumpi_backwards_min_stack_wrong(
"""
container = Container.Code(
code=(
Op.PUSH0
+ Op.PUSH1(0)
+ Op.RJUMPI[1]
+ Op.PUSH0
+ Op.PUSH1(4)
+ Op.RJUMPI[-9]
+ Op.STOP
Op.PUSH0 # (0, 0)
+ Op.PUSH1(0) # (1, 1)
+ Op.RJUMPI[1] # (2, 2) To PUSH1
+ Op.PUSH0 # (1, 1)
+ Op.PUSH1(4) # (1, 2)
+ Op.RJUMPI[-9] # (2, 3) To first RJUMPI with (1, 2)
+ Op.STOP # (1, 2)
),
max_stack_height=3,
)
eof_test(
data=container,
expect_exception=EOFException.STACK_HEIGHT_MISMATCH,
)


def test_rjumpi_rjumpv_backwards_min_stack_wrong(
eof_test: EOFTestFiller,
):
"""
Backwards rjumpv where min_stack does not match
"""
container = Container.Code(
code=(
Op.PUSH0 # (0, 0)
+ Op.PUSH1(0) # (1, 1)
+ Op.RJUMPI[1] # (2, 2) To PUSH1
+ Op.PUSH0 # (1, 1)
+ Op.PUSH1(4) # (1, 2)
+ Op.RJUMPV[-10] # (2, 3) To first RJUMPI with (1, 2)
+ Op.STOP # (1, 2)
),
max_stack_height=3,
)
Expand All @@ -935,7 +959,15 @@ def test_double_rjumpi(
Two RJUNMPIs, causing the min stack to underflow
"""
container = Container.Code(
code=(Op.PUSH0 + Op.PUSH0 + Op.RJUMPI[5] + Op.PUSH0 + Op.PUSH0 + Op.RJUMPI[0] + Op.RETURN),
code=(
Op.PUSH0 # (0, 0)
+ Op.PUSH0 # (1, 1)
+ Op.RJUMPI[5] # (2, 2) To RETURN
+ Op.PUSH0 # (1, 1)
+ Op.PUSH0 # (2, 2)
+ Op.RJUMPI[0] # (3, 3)
+ Op.RETURN # (1, 2) Underflow
),
max_stack_height=3,
)
eof_test(
Expand Down
38 changes: 31 additions & 7 deletions tests/prague/eip7692_eof_v1/eip4200_relative_jumps/test_rjumpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,13 +1188,37 @@ def test_rjumpv_backwards_min_stack_wrong(
"""
container = Container.Code(
code=(
Op.PUSH0
+ Op.PUSH1(0)
+ Op.RJUMPV[1]
+ Op.PUSH0
+ Op.PUSH1(4)
+ Op.RJUMPV[-11]
+ Op.STOP
Op.PUSH0 # (0, 0)
+ Op.PUSH1(0) # (1, 1)
+ Op.RJUMPV[1] # (2, 2) To PUSH1
+ Op.PUSH0 # (1, 1)
+ Op.PUSH1(4) # (1, 2)
+ Op.RJUMPV[-11] # (2, 3) To first RJUMPV with (1, 2)
+ Op.STOP # (1, 2)
),
max_stack_height=3,
)
eof_test(
data=container,
expect_exception=EOFException.STACK_HEIGHT_MISMATCH,
)


def test_rjumpv_rjumpi_backwards_min_stack_wrong(
eof_test: EOFTestFiller,
):
"""
Backwards rjumpv where min_stack does not match
"""
container = Container.Code(
code=(
Op.PUSH0 # (0, 0)
+ Op.PUSH1(0) # (1, 1)
+ Op.RJUMPV[1] # (2, 2) To PUSH1
+ Op.PUSH0 # (1, 1)
+ Op.PUSH1(4) # (1, 2)
+ Op.RJUMPI[-10] # (2, 3) To first RJUMPV with (1, 2)
+ Op.STOP # (1, 2)
),
max_stack_height=3,
)
Expand Down
62 changes: 59 additions & 3 deletions tests/prague/eip7692_eof_v1/eip6206_jumpf/test_jumpf_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_jumpf_stack_returning_rules(


@pytest.mark.parametrize(
["target_inputs", "target_outputs", "pre_stack", "expected_exception"],
["target_inputs", "target_outputs", "stack_height", "expected_exception"],
[
pytest.param(1, 0, 1, EOFException.STACK_UNDERFLOW, id="less_stack"),
pytest.param(2, 1, 2, None, id="same_stack"),
Expand All @@ -155,17 +155,73 @@ def test_jumpf_incompatible_outputs(
eof_test: EOFTestFiller,
target_inputs: int,
target_outputs: int,
pre_stack: int,
stack_height: int,
expected_exception: EOFException,
):
"""
Tests jumpf into fuction with incorrect output sizes
"""
current_section_outputs = 1
if (current_section_outputs + target_inputs - target_outputs) != stack_height:
assert expected_exception is not None
eof_test(
data=Container(
sections=[
Section.Code(Op.CALLF(1) + Op.STOP, max_stack_height=1),
Section.Code(Op.PUSH0 * pre_stack + Op.JUMPF(2), code_outputs=1),
Section.Code(
Op.PUSH0 * stack_height + Op.JUMPF(2),
code_outputs=current_section_outputs,
),
Section.Code(
Op.POP * (target_inputs - target_outputs) + Op.RETF,
code_inputs=target_inputs,
code_outputs=target_outputs,
max_stack_height=target_inputs,
),
]
),
expect_exception=expected_exception,
)


@pytest.mark.parametrize(
["target_inputs", "target_outputs", "min_stack_height", "expected_exception"],
[
pytest.param(1, 0, 1, EOFException.STACK_UNDERFLOW, id="less_stack"),
pytest.param(2, 1, 2, EOFException.STACK_HIGHER_THAN_OUTPUTS, id="same_stack"),
pytest.param(
3, 2, 3, EOFException.JUMPF_DESTINATION_INCOMPATIBLE_OUTPUTS, id="more_stack"
),
pytest.param(
2, 2, 1, EOFException.JUMPF_DESTINATION_INCOMPATIBLE_OUTPUTS, id="less_output"
),
pytest.param(1, 1, 1, EOFException.STACK_HIGHER_THAN_OUTPUTS, id="same_output"),
pytest.param(0, 0, 1, EOFException.STACK_HIGHER_THAN_OUTPUTS, id="more_output"),
],
)
def test_jumpf_diff_max_stack_height(
eof_test: EOFTestFiller,
target_inputs: int,
target_outputs: int,
min_stack_height: int,
expected_exception: EOFException,
):
"""
Tests jumpf with a different min and max stack height
"""
current_section_outputs = 1
eof_test(
data=Container(
sections=[
Section.Code(Op.CALLF(1) + Op.STOP, max_stack_height=1),
Section.Code(
(Op.PUSH0 * min_stack_height) # (0, 0)
+ Op.PUSH0 # (min_stack_height, min_stack_height)
+ Op.RJUMPI[1] # (min_stack_height + 1, min_stack_height + 1)
+ Op.PUSH0 # (min_stack_height, min_stack_height)
+ Op.JUMPF(2), # (min_stack_height, min_stack_height + 1)
code_outputs=current_section_outputs,
),
Section.Code(
Op.POP * (target_inputs - target_outputs) + Op.RETF,
code_inputs=target_inputs,
Expand Down

0 comments on commit aa8c34f

Please sign in to comment.