From e9d31bb9bc5e87f1f7a5927fed1bfd4a6ad8fcaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 24 Oct 2024 12:17:10 +0200 Subject: [PATCH] refactor(tests): parametrize CALLF execution tests --- .../eip4750_functions/test_callf_execution.py | 142 +++++++----------- 1 file changed, 57 insertions(+), 85 deletions(-) diff --git a/tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py b/tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py index e53f444c41..62e8c3caeb 100644 --- a/tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py +++ b/tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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}), )