Skip to content

Commit 60fec2b

Browse files
committed
chore(ruff): changes to tests/cancun/.
1 parent e375c01 commit 60fec2b

40 files changed

+451
-624
lines changed

tests/cancun/eip1153_tstore/__init__.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
EIP-1153 Tests
3-
"""
1+
"""EIP-1153 Tests."""
42

53
from enum import Enum, unique
64
from pprint import pprint
@@ -49,50 +47,41 @@ def test_function(test_value):
4947
"""
5048

5149
def __init__(self, value):
50+
"""Initialize the enum value."""
5251
assert isinstance(value, dict)
5352
assert "description" in value
5453
self._value_ = value
5554

5655
def param(self, names: List[str]):
57-
"""
58-
Return the `pytest.param` value for this test case.
59-
"""
56+
"""Return the `pytest.param` value for this test case."""
6057
value = self._value_
6158
if "pytest_marks" in value:
6259
marks = {"marks": value["pytest_marks"]}
6360
else:
6461
marks = {}
6562
if "pytest_id" in value:
66-
id = value["pytest_id"]
63+
pytest_id = value["pytest_id"]
6764
else:
68-
id = self.name.lower()
69-
return pytest.param(*[value[name] for name in names], id=id, **marks)
65+
pytest_id = self.name.lower()
66+
return pytest.param(*[value[name] for name in names], id=pytest_id, **marks)
7067

7168
@classmethod
7269
def special_keywords(cls) -> List[str]:
73-
"""
74-
Return the special dictionary keywords that are not test parameters.
75-
"""
70+
"""Return the special dictionary keywords that are not test parameters."""
7671
return ["description", "pytest_marks", "pytest_id"]
7772

7873
def names(self) -> List[str]:
79-
"""
80-
Return the names of all the parameters included in the enum value dict.
81-
"""
74+
"""Return the names of all the parameters included in the enum value dict."""
8275
return sorted([k for k in self._value_.keys() if k not in self.special_keywords()])
8376

8477
@property
8578
def description(self):
86-
"""
87-
Returns the description of this test case.
88-
"""
79+
"""Returns the description of this test case."""
8980
return self._value_["description"]
9081

9182
@classmethod
9283
def parametrize(cls):
93-
"""
94-
Returns the decorator to parametrize a test with this enum.
95-
"""
84+
"""Return decorator to parametrize a test with this enum."""
9685
names = None
9786
for test_case_names in [test_case.names() for test_case in cls]:
9887
if names is None:

tests/cancun/eip1153_tstore/spec.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
"""
2-
Defines EIP-1153 specification constants and functions.
3-
"""
1+
"""Defines EIP-1153 specification constants and functions."""
42
from dataclasses import dataclass
53

64

75
@dataclass(frozen=True)
86
class ReferenceSpec:
9-
"""
10-
Defines the reference spec version and git path.
11-
"""
7+
"""Defines the reference spec version and git path."""
128

139
git_path: str
1410
version: str
@@ -21,7 +17,7 @@ class ReferenceSpec:
2117
class Spec:
2218
"""
2319
Parameters from the EIP-1153 specifications as defined at
24-
https://eips.ethereum.org/EIPS/eip-1153
20+
https://eips.ethereum.org/EIPS/eip-1153.
2521
"""
2622

2723
TLOAD_OPCODE_BYTE = 0x5C

tests/cancun/eip1153_tstore/test_basic_tload.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Ethereum Transient Storage EIP Tests
3-
https://eips.ethereum.org/EIPS/eip-1153
3+
https://eips.ethereum.org/EIPS/eip-1153.
44
"""
55

66
from typing import Dict, Union
@@ -22,7 +22,7 @@ def test_basic_tload_transaction_begin(
2222
pre: Alloc,
2323
):
2424
"""
25-
Ported .json vectors:
25+
Ported .json vectors.
2626
2727
(01_tloadBeginningTxnFiller.yml)
2828
load arbitrary value is 0 at beginning of transaction
@@ -67,7 +67,7 @@ def test_basic_tload_works(
6767
pre: Alloc,
6868
):
6969
"""
70-
Ported .json vectors:
70+
Ported .json vectors.
7171
7272
(02_tloadAfterTstoreFiller.yml)
7373
tload from same slot after tstore returns correct value
@@ -119,7 +119,7 @@ def test_basic_tload_other_after_tstore(
119119
pre: Alloc,
120120
):
121121
"""
122-
Ported .json vectors:
122+
Ported .json vectors.
123123
124124
(03_tloadAfterStoreIs0Filler.yml)
125125
Loading any other slot after storing to a slot returns 0.
@@ -167,7 +167,7 @@ def test_basic_tload_gasprice(
167167
pre: Alloc,
168168
):
169169
"""
170-
Ported .json vectors:
170+
Ported .json vectors.
171171
172172
(16_tloadGasFiller.yml)
173173
tload costs 100 gas same as a warm sload
@@ -245,7 +245,7 @@ def test_basic_tload_after_store(
245245
pre: Alloc,
246246
):
247247
"""
248-
Ported .json vectors:
248+
Ported .json vectors.
249249
250250
(18_tloadAfterStoreFiller.yml)
251251
tload from same slot after store returns 0

tests/cancun/eip1153_tstore/test_tload_calls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Ethereum Transient Storage EIP Tests
3-
https://eips.ethereum.org/EIPS/eip-1153
3+
https://eips.ethereum.org/EIPS/eip-1153.
44
"""
55

66
import pytest
@@ -17,7 +17,7 @@
1717
@pytest.mark.parametrize("call_type", [Op.CALL, Op.CALLCODE, Op.DELEGATECALL])
1818
def test_tload_calls(state_test: StateTestFiller, pre: Alloc, call_type: Op):
1919
"""
20-
Ported .json vectors:
20+
Ported .json vectors.
2121
2222
(04_tloadAfterCallFiller.yml)
2323
Loading a slot after a call to another contract is 0.

tests/cancun/eip1153_tstore/test_tload_reentrancy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Ethereum Transient Storage EIP Tests
3-
https://eips.ethereum.org/EIPS/eip-1153
3+
https://eips.ethereum.org/EIPS/eip-1153.
44
"""
55

66
from enum import Enum
@@ -27,7 +27,7 @@
2727

2828

2929
class CallDestType(Enum):
30-
"""Call dest type"""
30+
"""Call dest type."""
3131

3232
REENTRANCY = 1
3333
EXTERNAL_CALL = 2
@@ -45,7 +45,7 @@ def test_tload_reentrancy(
4545
call_dest_type: CallDestType,
4646
):
4747
"""
48-
Ported .json vectors:
48+
Ported .json vectors.
4949
5050
(05_tloadReentrancyFiller.yml)
5151
Reentrant calls access the same transient storage

tests/cancun/eip1153_tstore/test_tstorage.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22
abstract: Tests [EIP-1153: Transient Storage Opcodes](https://eips.ethereum.org/EIPS/eip-1153)
33
Test [EIP-1153: Transient Storage Opcodes](https://eips.ethereum.org/EIPS/eip-1153). Ports
44
and extends some tests from
5-
[ethereum/tests/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage)
5+
[ethereum/tests/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage).
66
""" # noqa: E501
77

88
from enum import unique
99

1010
import pytest
1111

12-
from ethereum_test_tools import Account, Alloc, Bytecode, CodeGasMeasure, Environment
12+
from ethereum_test_tools import (
13+
Account,
14+
Alloc,
15+
Bytecode,
16+
CodeGasMeasure,
17+
Environment,
18+
StateTestFiller,
19+
Transaction,
20+
)
1321
from ethereum_test_tools import Opcodes as Op
14-
from ethereum_test_tools import StateTestFiller, Transaction
1522

1623
from . import PytestParameterEnum
1724
from .spec import Spec, ref_spec_1153
@@ -29,8 +36,8 @@ def test_transient_storage_unset_values(state_test: StateTestFiller, pre: Alloc)
2936
Test that tload returns zero for unset values. Loading an arbitrary value is
3037
0 at beginning of transaction: TLOAD(x) is 0.
3138
32-
Based on [ethereum/tests/.../01_tloadBeginningTxnFiller.yml](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/01_tloadBeginningTxnFiller.yml)", # noqa: E501
33-
"""
39+
Based on [ethereum/tests/.../01_tloadBeginningTxnFiller.yml](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/01_tloadBeginningTxnFiller.yml)",
40+
""" # noqa: E501
3441
env = Environment()
3542

3643
slots_under_test = [0, 1, 2, 2**128, 2**256 - 1]
@@ -62,8 +69,8 @@ def test_tload_after_tstore(state_test: StateTestFiller, pre: Alloc):
6269
Loading after storing returns the stored value: TSTORE(x, y), TLOAD(x)
6370
returns y.
6471
65-
Based on [ethereum/tests/.../02_tloadAfterTstoreFiller.yml](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/02_tloadAfterTstoreFiller.yml)", # noqa: E501
66-
"""
72+
Based on [ethereum/tests/.../02_tloadAfterTstoreFiller.yml](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/02_tloadAfterTstoreFiller.yml)",
73+
""" # noqa: E501
6774
env = Environment()
6875

6976
slots_under_test = [0, 1, 2, 2**128, 2**256 - 1]
@@ -96,8 +103,8 @@ def test_tload_after_sstore(state_test: StateTestFiller, pre: Alloc):
96103
Loading after storing returns the stored value: TSTORE(x, y), TLOAD(x)
97104
returns y.
98105
99-
Based on [ethereum/tests/.../18_tloadAfterStoreFiller.yml](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/18_tloadAfterStoreFiller.yml)", # noqa: E501
100-
"""
106+
Based on [ethereum/tests/.../18_tloadAfterStoreFiller.yml](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/18_tloadAfterStoreFiller.yml)",
107+
""" # noqa: E501
101108
env = Environment()
102109

103110
slots_under_test = [1, 3, 2**128, 2**256 - 1]
@@ -136,8 +143,8 @@ def test_tload_after_tstore_is_zero(state_test: StateTestFiller, pre: Alloc):
136143
"""
137144
Test that tload returns zero after tstore is called with zero.
138145
139-
Based on [ethereum/tests/.../03_tloadAfterStoreIs0Filler.yml](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/03_tloadAfterStoreIs0Filler.yml)", # noqa: E501
140-
"""
146+
Based on [ethereum/tests/.../03_tloadAfterStoreIs0Filler.yml](https://github.com/ethereum/tests/blob/9b00b68593f5869eb51a6659e1cc983e875e616b/src/EIPTestsFiller/StateTests/stEIP1153-transientStorage/03_tloadAfterStoreIs0Filler.yml)",
147+
""" # noqa: E501
141148
env = Environment()
142149

143150
slots_to_write = [1, 4, 2**128, 2**256 - 2]
@@ -175,9 +182,7 @@ def test_tload_after_tstore_is_zero(state_test: StateTestFiller, pre: Alloc):
175182

176183
@unique
177184
class GasMeasureTestCases(PytestParameterEnum):
178-
"""
179-
Test cases for gas measurement.
180-
"""
185+
"""Test cases for gas measurement."""
181186

182187
TLOAD = {
183188
"description": "Test that tload() of an empty slot consumes the expected gas.",
@@ -218,9 +223,7 @@ def test_gas_usage(
218223
overhead_cost: int,
219224
extra_stack_items: int,
220225
):
221-
"""
222-
Test that tstore and tload consume the expected gas.
223-
"""
226+
"""Test that tstore and tload consume the expected gas."""
224227
gas_measure_bytecode = CodeGasMeasure(
225228
code=bytecode, overhead_cost=overhead_cost, extra_stack_items=extra_stack_items
226229
)
@@ -240,9 +243,7 @@ def test_gas_usage(
240243

241244
@unique
242245
class LoopRunUntilOutOfGasCases(PytestParameterEnum):
243-
"""
244-
Test cases to run until out of gas.
245-
"""
246+
"""Test cases to run until out of gas."""
246247

247248
TSTORE = {
248249
"description": "Run tstore in loop until out of gas",
@@ -268,9 +269,7 @@ def test_run_until_out_of_gas(
268269
repeat_bytecode: Bytecode,
269270
bytecode_repeat_times: int,
270271
):
271-
"""
272-
Use TSTORE over and over to different keys until we run out of gas.
273-
"""
272+
"""Use TSTORE over and over to different keys until we run out of gas."""
274273
bytecode = Op.JUMPDEST + repeat_bytecode * bytecode_repeat_times + Op.JUMP(Op.PUSH0)
275274
code_address = pre.deploy_contract(code=bytecode)
276275
tx = Transaction(

tests/cancun/eip1153_tstore/test_tstorage_clear_after_tx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Ethereum Transient Storage EIP Tests
3-
https://eips.ethereum.org/EIPS/eip-1153
3+
https://eips.ethereum.org/EIPS/eip-1153.
44
"""
55

66
from typing import Optional
@@ -34,7 +34,7 @@ def test_tstore_clear_after_deployment_tx(
3434
evm_code_type: EVMCodeType,
3535
):
3636
"""
37-
This test first creates a contract, which TSTOREs a value 1 in slot 1.
37+
First creates a contract, which TSTOREs a value 1 in slot 1.
3838
After creating the contract, a new tx will call this contract, storing TLOAD(1) into slot 1.
3939
The transient storage should be cleared after creating the contract (at tx-level), so
4040
the storage should stay empty.
@@ -81,7 +81,7 @@ def test_tstore_clear_after_tx(
8181
pre: Alloc,
8282
):
8383
"""
84-
This test first SSTOREs the TLOAD value of key 1 in slot 1. Then, it TSTOREs 1 in slot 1.
84+
First SSTOREs the TLOAD value of key 1 in slot 1. Then, it TSTOREs 1 in slot 1.
8585
The second tx will re-call the contract. The storage should stay empty,
8686
because the transient storage is cleared after the transaction.
8787
"""

tests/cancun/eip1153_tstore/test_tstorage_create_contexts.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@
77

88
import pytest
99

10-
from ethereum_test_tools import Account, Address, Alloc, Bytecode, Environment, Initcode
10+
from ethereum_test_tools import (
11+
Account,
12+
Address,
13+
Alloc,
14+
Bytecode,
15+
Environment,
16+
Initcode,
17+
StateTestFiller,
18+
Transaction,
19+
compute_create_address,
20+
)
1121
from ethereum_test_tools import Opcodes as Op
12-
from ethereum_test_tools import StateTestFiller, Transaction, compute_create_address
1322

1423
from . import CreateOpcodeParams, PytestParameterEnum
1524
from .spec import ref_spec_1153
@@ -116,8 +125,7 @@ class InitcodeTestCases(PytestParameterEnum):
116125
@InitcodeTestCases.parametrize()
117126
class TestTransientStorageInContractCreation:
118127
"""
119-
Test transient storage in contract creation contexts:
120-
128+
Test transient storage in contract creation contexts.
121129
- TSTORE/TLOAD in initcode should not be able to access the creator's transient storage.
122130
- TSTORE/TLOAD in initcode should be able to access the created contract's transient
123131
storage.
@@ -157,7 +165,7 @@ def creator_contract_code( # noqa: D102
157165

158166
@pytest.fixture()
159167
def creator_address(self, pre: Alloc, creator_contract_code: Bytecode) -> Address:
160-
"""The address that creates the contract with create/create2"""
168+
"""Address that creates the contract with create/create2."""
161169
return pre.deploy_contract(creator_contract_code)
162170

163171
@pytest.fixture()
@@ -187,9 +195,7 @@ def test_contract_creation(
187195
expected_creator_storage: dict,
188196
expected_storage: dict,
189197
) -> None:
190-
"""
191-
Test transient storage in contract creation contexts.
192-
"""
198+
"""Test transient storage in contract creation contexts."""
193199
sender = pre.fund_eoa()
194200

195201
tx = Transaction(

0 commit comments

Comments
 (0)