Skip to content

Commit

Permalink
format with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Jan 10, 2025
1 parent c0284ac commit 027bcd7
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 143 deletions.
4 changes: 1 addition & 3 deletions tests/frontier/scenarios/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
Scenarios common import
"""
"""Scenarios common import."""
31 changes: 15 additions & 16 deletions tests/frontier/scenarios/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Define Scenario structures and helpers for test_scenarios test
"""
"""Define Scenario structures and helpers for test_scenarios test."""

from dataclasses import dataclass
from enum import Enum
Expand All @@ -16,14 +14,14 @@

@dataclass
class ScenarioDebug:
"""Debug selector for the development"""
"""Debug selector for the development."""

test_param: ParameterSet | None
scenario_name: str


class ScenarioExpectOpcode(Enum):
"""Opcodes that are replaced to real values computed by the scenario"""
"""Opcodes that are replaced to real values computed by the scenario."""

TX_ORIGIN = 1
CODE_ADDRESS = 2
Expand All @@ -44,12 +42,13 @@ class ScenarioExpectOpcode(Enum):
@dataclass
class ProgramResult:
"""
Describe expected result of a program
Describe expected result of a program.
Attributes:
result (int | ScenarioExpectOpcode): The result of the program
from_fork (Fork): The result is only valid from this fork (default: Frontier)
static_support (bool): Can be verified in static context (default: True)
"""

result: int | ScenarioExpectOpcode
Expand All @@ -64,7 +63,7 @@ class ScenarioEnvironment:
"""
Scenario evm environment
Each scenario must define an environment on which program is executed
This is so post state verification could check results of evm opcodes
This is so post state verification could check results of evm opcodes.
"""

code_address: Address # Op.ADDRESS, address scope for program
Expand All @@ -79,9 +78,7 @@ class ScenarioEnvironment:

@dataclass
class ExecutionEnvironment:
"""
Scenario execution environment which is determined by test
"""
"""Scenario execution environment which is determined by test."""

fork: Fork
gasprice: int
Expand All @@ -95,13 +92,14 @@ class ExecutionEnvironment:
@dataclass
class ScenarioGeneratorInput:
"""
Parameters for the scenario generator function
Parameters for the scenario generator function.
Attributes:
fork (Fork): Fork for which we ask to generate scenarios
pre (Alloc): Access to the state to be able to deploy contracts into pre
operation (Bytecode): Evm bytecode program that will be tested
external_address (Address): Static external address for ext opcodes
"""

fork: Fork
Expand All @@ -114,13 +112,14 @@ class ScenarioGeneratorInput:
@dataclass
class Scenario:
"""
Describe test scenario that will be run in test for each program
Describe test scenario that will be run in test for each program.
Attributes:
name (str): Scenario name for the test vector
code (Address): Address that is an entry point for scenario code
env (ScenarioEnvironment): Evm values for ScenarioExpectAddress map
reverting (bool): If scenario reverts program execution, making result 0 (default: False)
"""

name: str
Expand All @@ -134,7 +133,7 @@ def translate_result(
) -> int:
"""
Translate expected program result code into concrete value,
given the scenario evm environment and test execution environment
given the scenario evm environment and test execution environment.
"""
if exec_env.fork < res.from_fork:
return 0
Expand Down Expand Up @@ -177,7 +176,7 @@ def replace_special_calls_in_operation(
"""
Run find replace of some special calls to the contracts that we don't know at compile time
replace 0xfff..fff address to external_address
replace special call to 0xfff..ffe address to gas_hash_address contract
replace special call to 0xfff..ffe address to gas_hash_address contract.
"""
gas_hash_address = make_gas_hash_contract(pre)
invalid_opcode_contract = make_invalid_opcode_contract(pre)
Expand Down Expand Up @@ -235,7 +234,7 @@ def make_gas_hash_contract(pre: Alloc) -> Address:
Contract that spends unique amount of gas based on input
Used for the values we can't predict, can be gas consuming on high values
So that if we can't check exact value in expect section,
we at least could spend unique gas amount
we at least could spend unique gas amount.
"""
gas_hash_address = pre.deploy_contract(
code=Op.MSTORE(0, 0)
Expand All @@ -259,7 +258,7 @@ def make_gas_hash_contract(pre: Alloc) -> Address:
def make_invalid_opcode_contract(pre: Alloc) -> Address:
"""
Deploy a contract that will execute any asked byte as an opcode from calldataload
With 0-ed input stack of 10 elements, valid for opcodes starting at 0x0C
With 0-ed input stack of 10 elements, valid for opcodes starting at 0x0C.
"""
invalid_opcode_caller = pre.deploy_contract(
code=Op.PUSH0 * 10
Expand Down
4 changes: 1 addition & 3 deletions tests/frontier/scenarios/programs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
Scenarios common import
"""
"""Scenarios common import."""
6 changes: 2 additions & 4 deletions tests/frontier/scenarios/programs/all_frontier_opcodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Define a program for scenario test that executes all frontier opcodes and entangles it's result
"""
"""Define a program for scenario test that executes all frontier opcodes and entangles it's result.""" # noqa: E501

import pytest

Expand All @@ -16,7 +14,7 @@


def make_all_opcode_program() -> Bytecode:
"""Make a program that call each Frontier opcode and verifies it's result"""
"""Make a program that call each Frontier opcode and verifies it's result."""
code: Bytecode = (
# Test opcode 01 - ADD
Conditional(
Expand Down
4 changes: 1 addition & 3 deletions tests/frontier/scenarios/programs/context_calls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Define programs that will run all context opcodes for test scenarios
"""
"""Define programs that will run all context opcodes for test scenarios."""

import pytest

Expand Down
6 changes: 2 additions & 4 deletions tests/frontier/scenarios/programs/invalid_opcodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Define programs that can not be run in static context
"""
"""Define programs that can not be run in static context."""

import pytest

Expand All @@ -22,7 +20,7 @@


def make_all_invalid_opcode_calls() -> Bytecode:
"""Call special contract to initiate all invalid opcode instruction"""
"""Call special contract to initiate all invalid opcode instruction."""
invalid_opcode_caller = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD

code = Bytecode(
Expand Down
4 changes: 1 addition & 3 deletions tests/frontier/scenarios/programs/static_violation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Define programs that can not be run in static context
"""
"""Define programs that can not be run in static context."""

import pytest

Expand Down
4 changes: 1 addition & 3 deletions tests/frontier/scenarios/scenarios/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
Scenarios common import
"""
"""Scenarios common import."""
Loading

0 comments on commit 027bcd7

Please sign in to comment.