-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 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 |
---|---|---|
|
@@ -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
|
||
- 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 | ||
|
||
|