forked from ethereum/execution-spec-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(tests): eip-7620: RETURNCONTRACT validation tests
- Loading branch information
Showing
5 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
EOFTests/efValidation/EOF1_returncontract_invalid_.json | ||
EOFTests/efValidation/EOF1_returncontract_valid_.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
tests/prague/eip7692_eof_v1/eip7620_eof_create/test_returncontract.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
""" | ||
Tests for RETURNCONTRACT instruction validation | ||
""" | ||
|
||
from ethereum_test_tools import EOFTestFiller | ||
from ethereum_test_tools.eof.v1 import Container, Section | ||
from ethereum_test_tools.exceptions import EOFException | ||
from ethereum_test_tools.vm.opcode import Opcodes as Op | ||
|
||
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-7620.md" | ||
REFERENCE_SPEC_VERSION = "f20b164b00ae5553f7536a6d7a83a0f254455e09" | ||
|
||
|
||
def test_returncontract_valid_index_0( | ||
eof_test: EOFTestFiller, | ||
): | ||
"""Deploy container index 0""" | ||
eof_test( | ||
data=Container( | ||
sections=[ | ||
Section.Code( | ||
code=Op.RETURNCONTRACT[0](0, 0), | ||
), | ||
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])), | ||
], | ||
) | ||
) | ||
|
||
|
||
def test_returncontract_valid_index_1( | ||
eof_test: EOFTestFiller, | ||
): | ||
"""Deploy container index 1""" | ||
eof_test( | ||
data=Container( | ||
sections=[ | ||
Section.Code( | ||
code=Op.RJUMPI[6](0) + Op.RETURNCONTRACT[0](0, 0) + Op.RETURNCONTRACT[1](0, 0), | ||
max_stack_height=2, | ||
), | ||
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])), | ||
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])), | ||
], | ||
) | ||
) | ||
|
||
|
||
def test_returncontract_valid_index_255( | ||
eof_test: EOFTestFiller, | ||
): | ||
"""Deploy container index 255""" | ||
eof_test( | ||
data=Container( | ||
sections=[ | ||
Section.Code( | ||
sum((Op.RJUMPI[6](0) + Op.RETURNCONTRACT[i](0, 0)) for i in range(256)) | ||
+ Op.REVERT(0, 0), | ||
max_stack_height=2, | ||
) | ||
] | ||
+ [Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)]))] | ||
* 256 | ||
) | ||
) | ||
|
||
|
||
def test_returncontract_invalid_truncated_immediate( | ||
eof_test: EOFTestFiller, | ||
): | ||
"""Truncated immediate""" | ||
eof_test( | ||
data=Container( | ||
sections=[ | ||
Section.Code( | ||
code=Op.PUSH0 + Op.PUSH0 + Op.RETURNCONTRACT, | ||
), | ||
], | ||
), | ||
expect_exception=EOFException.TRUNCATED_INSTRUCTION, | ||
) | ||
|
||
|
||
def test_returncontract_invalid_index_0( | ||
eof_test: EOFTestFiller, | ||
): | ||
"""Referring to non-existent container section index 0""" | ||
eof_test( | ||
data=Container( | ||
sections=[ | ||
Section.Code( | ||
code=Op.RETURNCONTRACT[0](0, 0), | ||
), | ||
], | ||
), | ||
expect_exception=EOFException.INVALID_CONTAINER_SECTION_INDEX, | ||
) | ||
|
||
|
||
def test_returncontract_invalid_index_1( | ||
eof_test: EOFTestFiller, | ||
): | ||
"""Referring to non-existent container section index 1""" | ||
eof_test( | ||
data=Container( | ||
sections=[ | ||
Section.Code( | ||
code=Op.RETURNCONTRACT[1](0, 0), | ||
), | ||
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])), | ||
], | ||
), | ||
expect_exception=EOFException.INVALID_CONTAINER_SECTION_INDEX, | ||
) | ||
|
||
|
||
def test_returncontract_invalid_index_255( | ||
eof_test: EOFTestFiller, | ||
): | ||
"""Referring to non-existent container section index 255""" | ||
eof_test( | ||
data=Container( | ||
sections=[ | ||
Section.Code( | ||
code=Op.RETURNCONTRACT[255](0, 0), | ||
), | ||
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])), | ||
], | ||
), | ||
expect_exception=EOFException.INVALID_CONTAINER_SECTION_INDEX, | ||
) | ||
|
||
|
||
def test_returncontract_terminating( | ||
eof_test: EOFTestFiller, | ||
): | ||
"""Unreachable code after RETURNCONTRACT""" | ||
eof_test( | ||
data=Container( | ||
sections=[ | ||
Section.Code( | ||
code=Op.RETURNCONTRACT[0](0, 0) + Op.REVERT(0, 0), | ||
), | ||
Section.Container(container=Container(sections=[Section.Code(code=Op.INVALID)])), | ||
], | ||
), | ||
expect_exception=EOFException.UNREACHABLE_INSTRUCTIONS, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters