From ba60080b78ad254bddc8263882c531597f560880 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Wed, 10 Jul 2024 21:29:30 +0200 Subject: [PATCH] new(tests): Add test for stack reaching max size in called function --- .../eip4750_functions/__init__.py | 3 ++ .../eip4750_functions/helpers.py | 14 ++++++ .../eip4750_functions/test_callf_execution.py | 44 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/prague/eip7692_eof_v1/eip4750_functions/__init__.py create mode 100644 tests/prague/eip7692_eof_v1/eip4750_functions/helpers.py create mode 100644 tests/prague/eip7692_eof_v1/eip4750_functions/test_callf_execution.py diff --git a/tests/prague/eip7692_eof_v1/eip4750_functions/__init__.py b/tests/prague/eip7692_eof_v1/eip4750_functions/__init__.py new file mode 100644 index 0000000000..ba2edc4b15 --- /dev/null +++ b/tests/prague/eip7692_eof_v1/eip4750_functions/__init__.py @@ -0,0 +1,3 @@ +""" +EOF tests for EIP-4750 functions +""" diff --git a/tests/prague/eip7692_eof_v1/eip4750_functions/helpers.py b/tests/prague/eip7692_eof_v1/eip4750_functions/helpers.py new file mode 100644 index 0000000000..82e0bed985 --- /dev/null +++ b/tests/prague/eip7692_eof_v1/eip4750_functions/helpers.py @@ -0,0 +1,14 @@ +""" +EOF Functions tests helpers +""" + +import itertools + +"""Storage addresses for common testing fields""" +_slot = itertools.count() +next(_slot) # don't use slot 0 +slot_code_worked = next(_slot) +slot_last_slot = next(_slot) + +"""Storage values for common testing fields""" +value_code_worked = 0x2015 diff --git a/tests/prague/eip7692_eof_v1/eip4750_functions/test_callf_execution.py b/tests/prague/eip7692_eof_v1/eip4750_functions/test_callf_execution.py new file mode 100644 index 0000000000..56dbd017cb --- /dev/null +++ b/tests/prague/eip7692_eof_v1/eip4750_functions/test_callf_execution.py @@ -0,0 +1,44 @@ +""" +EOF CALLF execution tests +""" + +import pytest + +from ethereum_test_tools import Account, EOFException, EOFStateTestFiller +from ethereum_test_tools.eof.v1 import Container, Section +from ethereum_test_tools.vm.opcode import Opcodes as Op + +from .. import EOF_FORK_NAME +from .helpers import slot_code_worked, value_code_worked + +REFERENCE_SPEC_GIT_PATH = "EIPS/eip-4750.md" +REFERENCE_SPEC_VERSION = "14400434e1199c57d912082127b1d22643788d11" + +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( + sections=[ + Section.Code( + code=Op.PUSH0 * 1023 + + Op.CALLF[1] + + Op.POP * 1023 + + Op.SSTORE(slot_code_worked, value_code_worked) + + Op.RETURN(0, 0), + max_stack_height=1023, + ), + Section.Code( + Op.PUSH0 + Op.POP + Op.RETF, + code_inputs=0, + code_outputs=0, + max_stack_height=1, + ), + ], + ), + container_post=Account(storage={slot_code_worked: value_code_worked}), + )