Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Jul 30, 2024
1 parent f12d155 commit 0aa8389
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions docs/writing_tests/test_markers.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,53 @@ This marker is used to automatically parameterize a test with all EVM code types

```python
import pytest
from ethereum_test_forks import EVMCodeType

@pytest.mark.with_all_evm_code_types
@pytest.mark.valid_from("Frontier")
def test_something_with_all_evm_code_types(evm_code_type: EVMCodeType):
def test_something_with_all_evm_code_types(pre: Alloc):
pass
```

In this example, the test will be parameterized for parameter `precompile` only with value `[EVMCodeType.LEGACY]` for fork Frontier, but eventually it will be parametrized with with values `[EVMCodeType.LEGACY, EVMCodeType.EOF_V1]` on the EOF activation fork.
In this example, the test will be parameterized for parameter `evm_code_type` only with value `[EVMCodeType.LEGACY]` starting on fork Frontier, and eventually it will be parametrized with with values `[EVMCodeType.LEGACY, EVMCodeType.EOF_V1]` on the EOF activation fork.

There will not be any automatic test conversion for the `EVMCodeType` parameter, so the test writer must handle the different code types manually.
In all calls to `pre.deploy_contract`, if the code parameter is `Bytecode` type, and `evm_code_type==EVMCodeType.EOF_V1`, the bytecode will be automatically wrapped in an EOF V1 container.

Code wrapping might fail in the following circumstances:
- The code contains invalid EOF V1 opcodes.

Check failure on line 101 in docs/writing_tests/test_markers.md

View workflow job for this annotation

GitHub Actions / build (macos-latest, 3.11, stable, tox run-parallel --parallel-no-spinner)

Lists should be surrounded by blank lines

docs/writing_tests/test_markers.md:101 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- The code contains invalid EO..."] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md032.md

Check failure on line 101 in docs/writing_tests/test_markers.md

View workflow job for this annotation

GitHub Actions / build (macos-latest, 3.11, stable, tox run-parallel --parallel-no-spinner)

Lists should be surrounded by blank lines

docs/writing_tests/test_markers.md:101 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- The code contains invalid EO..."] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md032.md
- The code does not end with a valid EOF V1 terminating opcode (such as `Op.STOP` or `Op.REVERT` or `Op.RETURN`).

In the case where the code wrapping fails, `evm_code_type` can be added as a parameter to the test and the bytecode can be dynamically modified to be compatible with the EOF V1 container.

```python
import pytest

@pytest.mark.with_all_evm_code_types
@pytest.mark.valid_from("Frontier")
def test_something_with_all_evm_code_types(pre: Alloc, evm_code_type: EVMCodeType):
code = Op.SSTORE(1, 1)
if evm_code_type == EVMCodeType.EOF_V1:
# Modify the bytecode to be compatible with EOF V1 container
code += Op.STOP
pre.deploy_contract(code)
...
```

### pytest.mark.with_all_call_opcodes

This marker is used to automatically parameterize a test with all EVM call opcodes that are valid for the fork being tested.

```python
import pytest

@pytest.mark.with_all_call_opcodes
@pytest.mark.valid_from("Frontier")
def test_something_with_all_call_opcodes(pre: Alloc, call_opcode: Op):
...
```

In this example, the test will be parametrized for parameter `call_opcode` with values `[Op.CALL, Op.CALLCODE]` starting on fork Frontier, `[Op.CALL, Op.CALLCODE, Op.DELEGATECALL]` on fork Homestead, `[Op.CALL, Op.CALLCODE, Op.DELEGATECALL, Op.STATICCALL]` on fork Byzantium, and eventually it will be parametrized with with values `[Op.CALL, Op.CALLCODE, Op.DELEGATECALL, Op.STATICCALL, Op.EXTCALL, Op.EXTSTATICCALL, Op.EXTDELEGATECALL]` on the EOF activation fork.

Parameter `evm_code_type` will also be parametrized with the correct EVM code type for the opcode under test.

## Other Markers

Expand Down

0 comments on commit 0aa8389

Please sign in to comment.