Skip to content

Commit c411805

Browse files
committed
chore(ruff): changes to tests/prague/.
1 parent b83116f commit c411805

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+474
-777
lines changed

tests/prague/eip2537_bls_12_381_precompiles/conftest.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
"""
2-
Shared pytest definitions local to EIP-2537 tests.
3-
"""
1+
"""Shared pytest definitions local to EIP-2537 tests."""
42

53
from typing import SupportsBytes
64

75
import pytest
86

9-
from ethereum_test_tools import EOA, Address, Alloc, Bytecode
7+
from ethereum_test_tools import EOA, Address, Alloc, Bytecode, Storage, Transaction, keccak256
108
from ethereum_test_tools import Opcodes as Op
11-
from ethereum_test_tools import Storage, Transaction, keccak256
129

1310
from .spec import GAS_CALCULATION_FUNCTION_MAP
1411

1512

1613
@pytest.fixture
17-
def precompile_gas(precompile_address: int, input: bytes) -> int:
14+
def precompile_gas(precompile_address: int, input_value: bytes) -> int:
1815
"""Gas cost for the precompile."""
19-
return GAS_CALCULATION_FUNCTION_MAP[precompile_address](len(input))
16+
return GAS_CALCULATION_FUNCTION_MAP[precompile_address](len(input_value))
2017

2118

2219
@pytest.fixture
2320
def precompile_gas_modifier() -> int:
2421
"""
25-
Used to modify the gas passed to the precompile, for testing purposes.
22+
Modify the gas passed to the precompile, for testing purposes.
2623
2724
By default the call is made with the exact gas amount required for the given opcode,
2825
but when this fixture is overridden, the gas amount can be modified to, e.g., test
@@ -93,6 +90,7 @@ def call_contract_code(
9390
Op.STATICCALL).
9491
call_contract_post_storage:
9592
Storage of the test contract after the transaction is executed.
93+
9694
"""
9795
expected_output = bytes(expected_output)
9896

@@ -152,23 +150,21 @@ def post(call_contract_address: Address, call_contract_post_storage: Storage):
152150

153151
@pytest.fixture
154152
def tx_gas_limit(precompile_gas: int) -> int:
155-
"""
156-
Transaction gas limit used for the test (Can be overridden in the test).
157-
"""
153+
"""Transaction gas limit used for the test (Can be overridden in the test)."""
158154
return 10_000_000 + precompile_gas
159155

160156

161157
@pytest.fixture
162158
def tx(
163-
input: bytes,
159+
input_data: bytes,
164160
tx_gas_limit: int,
165161
call_contract_address: Address,
166162
sender: EOA,
167163
) -> Transaction:
168164
"""Transaction for the test."""
169165
return Transaction(
170166
gas_limit=tx_gas_limit,
171-
input=input,
167+
data=input_data,
172168
to=call_contract_address,
173169
sender=sender,
174170
)

tests/prague/eip2537_bls_12_381_precompiles/helpers.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Helper functions for the EIP-2537 BLS12-381 precompiles tests.
3-
"""
1+
"""Helper functions for the EIP-2537 BLS12-381 precompiles tests."""
42
import os
53
from typing import Annotated, List
64

@@ -10,16 +8,12 @@
108

119

1210
def current_python_script_directory(*args: str) -> str:
13-
"""
14-
Get the current Python script directory, optionally appending additional path components.
15-
"""
11+
"""Get the current Python script directory, optionally appending additional path components."""
1612
return os.path.join(os.path.dirname(os.path.realpath(__file__)), *args)
1713

1814

1915
class Vector(BaseModel):
20-
"""
21-
Test vector for the BLS12-381 precompiles.
22-
"""
16+
"""Test vector for the BLS12-381 precompiles."""
2317

2418
input: Annotated[bytes, BeforeValidator(bytes.fromhex)]
2519
expected: Annotated[bytes, BeforeValidator(bytes.fromhex)]
@@ -29,16 +23,12 @@ class Vector(BaseModel):
2923
model_config = ConfigDict(alias_generator=to_pascal)
3024

3125
def to_pytest_param(self):
32-
"""
33-
Convert the test vector to a tuple that can be used as a parameter in a pytest test.
34-
"""
26+
"""Convert the test vector to a tuple that can be used as a parameter in a pytest test."""
3527
return pytest.param(self.input, self.expected, id=self.name)
3628

3729

3830
class FailVector(BaseModel):
39-
"""
40-
Test vector for the BLS12-381 precompiles.
41-
"""
31+
"""Test vector for the BLS12-381 precompiles."""
4232

4333
input: Annotated[bytes, BeforeValidator(bytes.fromhex)]
4434
expected_error: str
@@ -47,16 +37,12 @@ class FailVector(BaseModel):
4737
model_config = ConfigDict(alias_generator=to_pascal)
4838

4939
def to_pytest_param(self):
50-
"""
51-
Convert the test vector to a tuple that can be used as a parameter in a pytest test.
52-
"""
40+
"""Convert the test vector to a tuple that can be used as a parameter in a pytest test."""
5341
return pytest.param(self.input, id=self.name)
5442

5543

5644
class VectorList(RootModel):
57-
"""
58-
List of test vectors for the BLS12-381 precompiles.
59-
"""
45+
"""List of test vectors for the BLS12-381 precompiles."""
6046

6147
root: List[Vector | FailVector]
6248

@@ -65,9 +51,7 @@ class VectorList(RootModel):
6551

6652

6753
def vectors_from_file(filename: str) -> List:
68-
"""
69-
Load test vectors from a file.
70-
"""
54+
"""Load test vectors from a file."""
7155
with open(
7256
current_python_script_directory(
7357
"vectors",

tests/prague/eip2537_bls_12_381_precompiles/spec.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
Defines EIP-2537 specification constants and functions.
3-
"""
1+
"""Defines EIP-2537 specification constants and functions."""
2+
43
import json
54
from dataclasses import dataclass
65
from typing import Callable, List, Sized, SupportsBytes, Tuple
@@ -10,9 +9,7 @@
109

1110
@dataclass(frozen=True)
1211
class ReferenceSpec:
13-
"""
14-
Defines the reference spec version and git path.
15-
"""
12+
"""Defines the reference spec version and git path."""
1613

1714
git_path: str
1815
version: str
@@ -22,12 +19,10 @@ class ReferenceSpec:
2219

2320

2421
class BytesConcatenation(SupportsBytes, Sized):
25-
"""
26-
A class that can be concatenated with bytes.
27-
"""
22+
"""A class that can be concatenated with bytes."""
2823

2924
def __len__(self) -> int:
30-
"""Returns the length of the object when converted to bytes."""
25+
"""Return length of the object when converted to bytes."""
3126
return len(bytes(self))
3227

3328
def __add__(self, other: bytes | SupportsBytes) -> bytes:
@@ -46,7 +41,7 @@ class FP(BytesConcatenation):
4641
x: int = 0
4742

4843
def __bytes__(self) -> bytes:
49-
"""Converts the field element to bytes."""
44+
"""Convert field element to bytes."""
5045
return self.x.to_bytes(64, byteorder="big")
5146

5247

@@ -58,7 +53,7 @@ class PointG1(BytesConcatenation):
5853
y: int = 0
5954

6055
def __bytes__(self) -> bytes:
61-
"""Converts the point to bytes."""
56+
"""Convert point to bytes."""
6257
return self.x.to_bytes(64, byteorder="big") + self.y.to_bytes(64, byteorder="big")
6358

6459
def __neg__(self):
@@ -73,7 +68,7 @@ class FP2(BytesConcatenation):
7368
x: Tuple[int, int] = (0, 0)
7469

7570
def __bytes__(self) -> bytes:
76-
"""Converts the field element to bytes."""
71+
"""Convert field element to bytes."""
7772
return self.x[0].to_bytes(64, byteorder="big") + self.x[1].to_bytes(64, byteorder="big")
7873

7974

@@ -85,7 +80,7 @@ class PointG2(BytesConcatenation):
8580
y: Tuple[int, int] = (0, 0)
8681

8782
def __bytes__(self) -> bytes:
88-
"""Converts the point to bytes."""
83+
"""Convert point to bytes."""
8984
return (
9085
self.x[0].to_bytes(64, byteorder="big")
9186
+ self.x[1].to_bytes(64, byteorder="big")
@@ -105,7 +100,7 @@ class Scalar(BytesConcatenation):
105100
x: int = 0
106101

107102
def __bytes__(self) -> bytes:
108-
"""Converts the scalar to bytes."""
103+
"""Convert scalar to bytes."""
109104
return self.x.to_bytes(32, byteorder="big")
110105

111106

@@ -118,7 +113,7 @@ def __bytes__(self) -> bytes:
118113
class Spec:
119114
"""
120115
Parameters from the EIP-2537 specifications as defined at
121-
https://eips.ethereum.org/EIPS/eip-2537
116+
https://eips.ethereum.org/EIPS/eip-2537.
122117
"""
123118

124119
# Addresses
@@ -218,22 +213,18 @@ class Spec:
218213

219214

220215
def msm_discount(k: int) -> int:
221-
"""
222-
Returns the discount for the G1MSM and G2MSM precompiles.
223-
"""
216+
"""Return discount for the G1MSM and G2MSM precompiles."""
224217
return Spec.MSM_DISCOUNT_TABLE[min(k, 128)]
225218

226219

227220
def msm_gas_func_gen(len_per_pair: int, multiplication_cost: int) -> Callable[[int], int]:
228221
"""
229-
Generates a function that calculates the gas cost for the G1MSM and G2MSM
222+
Generate function that calculates the gas cost for the G1MSM and G2MSM
230223
precompiles.
231224
"""
232225

233226
def msm_gas(input_length: int) -> int:
234-
"""
235-
Calculates the gas cost for the G1MSM and G2MSM precompiles.
236-
"""
227+
"""Calculate gas cost for the G1MSM and G2MSM precompiles."""
237228
k = input_length // len_per_pair
238229
if k == 0:
239230
return 0
@@ -246,9 +237,7 @@ def msm_gas(input_length: int) -> int:
246237

247238

248239
def pairing_gas(input_length: int) -> int:
249-
"""
250-
Calculates the gas cost for the PAIRING precompile.
251-
"""
240+
"""Calculate gas cost for the PAIRING precompile."""
252241
k = input_length // Spec.LEN_PER_PAIR
253242
return (Spec.PAIRING_PER_PAIR_GAS * k) + Spec.PAIRING_BASE_GAS
254243

tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1add.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
import pytest
77

8-
from ethereum_test_tools import Alloc, Environment
8+
from ethereum_test_tools import Alloc, Environment, StateTestFiller, Transaction
99
from ethereum_test_tools import Opcodes as Op
10-
from ethereum_test_tools import StateTestFiller, Transaction
1110

1211
from .helpers import vectors_from_file
1312
from .spec import PointG1, Spec, ref_spec_2537
@@ -22,7 +21,7 @@
2221

2322

2423
@pytest.mark.parametrize(
25-
"input,expected_output",
24+
"input_value,expected_output",
2625
vectors_from_file("add_G1_bls.json")
2726
+ [
2827
pytest.param(
@@ -48,9 +47,7 @@ def test_valid(
4847
post: dict,
4948
tx: Transaction,
5049
):
51-
"""
52-
Test the BLS12_G1ADD precompile.
53-
"""
50+
"""Test the BLS12_G1ADD precompile."""
5451
state_test(
5552
env=Environment(),
5653
pre=pre,
@@ -60,7 +57,7 @@ def test_valid(
6057

6158

6259
@pytest.mark.parametrize(
63-
"input",
60+
"input_value",
6461
vectors_from_file("fail-add_G1_bls.json")
6562
+ [
6663
pytest.param(
@@ -156,9 +153,7 @@ def test_invalid(
156153
post: dict,
157154
tx: Transaction,
158155
):
159-
"""
160-
Negative tests for the BLS12_G1ADD precompile.
161-
"""
156+
"""Negative tests for the BLS12_G1ADD precompile."""
162157
state_test(
163158
env=Environment(),
164159
pre=pre,
@@ -168,7 +163,7 @@ def test_invalid(
168163

169164

170165
@pytest.mark.parametrize(
171-
"input,expected_output,precompile_gas_modifier",
166+
"input_value,expected_output,precompile_gas_modifier",
172167
[
173168
pytest.param(
174169
Spec.INF_G1 + Spec.INF_G1,
@@ -190,9 +185,7 @@ def test_gas(
190185
post: dict,
191186
tx: Transaction,
192187
):
193-
"""
194-
Test the BLS12_G1ADD precompile gas requirements.
195-
"""
188+
"""Test the BLS12_G1ADD precompile gas requirements."""
196189
state_test(
197190
env=Environment(),
198191
pre=pre,
@@ -210,7 +203,7 @@ def test_gas(
210203
],
211204
)
212205
@pytest.mark.parametrize(
213-
"input,expected_output",
206+
"input_value,expected_output",
214207
[
215208
pytest.param(
216209
Spec.INF_G1 + Spec.INF_G1,
@@ -225,9 +218,7 @@ def test_call_types(
225218
post: dict,
226219
tx: Transaction,
227220
):
228-
"""
229-
Test the BLS12_G1ADD precompile using different call types.
230-
"""
221+
"""Test the BLS12_G1ADD precompile using different call types."""
231222
state_test(
232223
env=Environment(),
233224
pre=pre,

0 commit comments

Comments
 (0)