Skip to content

Commit 9b6904a

Browse files
committed
review feedback adjustments
1 parent 3dffdca commit 9b6904a

File tree

6 files changed

+60
-2108
lines changed

6 files changed

+60
-2108
lines changed

src/ethereum_test_forks/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Ethereum test fork definitions."""
22

3-
from typing import Literal
4-
53
from .base_fork import Fork, ForkAttribute
64
from .forks.forks import (
75
ArrowGlacier,

src/ethereum_test_types/blob_types.py

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@
2020
Prague,
2121
)
2222

23-
24-
def fork_string_to_object(fork_name: str) -> type[Cancun] | type[Prague] | type[Osaka]:
25-
"""Take a fork string and return the respective fork as object."""
26-
fork_name = fork_name.lower()
27-
28-
if fork_name == "cancun":
29-
return Cancun
30-
if fork_name == "prague":
31-
return Prague
32-
if fork_name == "osaka":
33-
return Osaka
34-
raise ValueError(f"Fork {fork_name} has not yet been implemented in this function.")
35-
36-
3723
CACHED_BLOBS_DIRECTORY: Path = (
3824
Path(platformdirs.user_cache_dir("ethereum-execution-spec-tests")) / "cached_blobs"
3925
)
@@ -49,7 +35,7 @@ class Blob(CamelModel):
4935

5036
versioned_hash: Hash
5137
name: str # blob_<fork>_<seed>
52-
fork: str
38+
fork: Fork
5339
seed: int
5440
timestamp: int
5541

@@ -59,7 +45,7 @@ class Blob(CamelModel):
5945
def trusted_setup(cls):
6046
"""Set trusted setup if it is not already set."""
6147
if cls._trusted_setup is None:
62-
trusted_setup_path = Path(realpath(__file__)).parent / "blob_trusted_setup.txt"
48+
trusted_setup_path = Path(realpath(__file__)).parent / "kzg_trusted_setup.txt"
6349
trusted_setup = ckzg.load_trusted_setup(str(trusted_setup_path), 0)
6450
print(f"{trusted_setup_path} has been loaded")
6551
cls._trusted_setup = trusted_setup
@@ -159,7 +145,7 @@ def get_proof(fork: Fork, data: Bytes) -> List[Bytes] | Bytes:
159145
return proofs
160146

161147
raise AssertionError(
162-
f"get_proof() has not been implemented yet for fork: {fork_str}. "
148+
f"get_proof() has not been implemented yet for fork: {fork.name()}."
163149
f"Got amount of cell proofs {amount_cell_proofs} but expected 128."
164150
)
165151

@@ -179,14 +165,12 @@ def get_cells(fork: Fork, data: Bytes) -> List[Bytes] | None:
179165
return cells # List[bytes]
180166

181167
raise AssertionError(
182-
f"get_cells() has not been implemented yet for fork: {fork_str}. Got amount of "
168+
f"get_cells() has not been implemented yet for fork: {fork.name()}. Got amount of "
183169
f"cell proofs {amount_cell_proofs} but expected 128."
184170
)
185171

186172
assert fork.supports_blobs(), f"Provided fork {fork.name()} does not support blobs!"
187173

188-
fork_str: str = fork.name().lower()
189-
190174
# if this blob already exists then load from file
191175
blob_location: Path = Blob.get_filepath(fork, seed)
192176
if blob_location.exists():
@@ -211,7 +195,7 @@ def get_cells(fork: Fork, data: Bytes) -> List[Bytes] | None:
211195
cells=cells,
212196
versioned_hash=versioned_hash,
213197
name=name,
214-
fork=fork_str,
198+
fork=fork,
215199
seed=seed,
216200
timestamp=timestamp,
217201
)
@@ -253,7 +237,7 @@ def from_file(file_name: str) -> "Blob":
253237
def write_to_file(self):
254238
"""Take a blob object, serialize it and write it to disk as json."""
255239
json_str = self.model_dump_json()
256-
output_location = Blob.get_filepath(fork_string_to_object(self.fork), self.seed)
240+
output_location = Blob.get_filepath(self.fork, self.seed)
257241

258242
# warn if existing static_blob gets overwritten
259243
if output_location.exists():
@@ -264,11 +248,10 @@ def write_to_file(self):
264248

265249
def verify_cell_kzg_proof_batch(self, cell_indices: list) -> bool:
266250
"""Check whether all cell proofs are valid and returns True only if that is the case."""
267-
fork_obj = fork_string_to_object(self.fork)
268-
amount_cell_proofs: int = cast(int, fork_obj.get_blob_constant("AMOUNT_CELL_PROOFS"))
251+
amount_cell_proofs: int = cast(int, self.fork.get_blob_constant("AMOUNT_CELL_PROOFS"))
269252

270253
assert amount_cell_proofs > 0, (
271-
f"verify_cell_kzg_proof_batch() is not available for your fork: {self.fork}."
254+
f"verify_cell_kzg_proof_batch() is not available for your fork: {self.fork.name()}."
272255
)
273256

274257
assert self.cells is not None, "self.cells is None, critical error."
@@ -298,11 +281,10 @@ def delete_cells_then_recover_them(self, deletion_indices: list[int]):
298281
the ckzg recovery mechanism is used to repair the missing cells.
299282
If no assertion is triggered the reconstruction was successful.
300283
"""
301-
fork_obj = fork_string_to_object(self.fork)
302-
amount_cell_proofs: int = cast(int, fork_obj.get_blob_constant("AMOUNT_CELL_PROOFS"))
284+
amount_cell_proofs: int = cast(int, self.fork.get_blob_constant("AMOUNT_CELL_PROOFS"))
303285

304286
assert amount_cell_proofs > 0, (
305-
f"delete_cells_then_recover_them() is not available for fork: {self.fork}"
287+
f"delete_cells_then_recover_them() is not available for fork: {self.fork.name()}"
306288
)
307289

308290
assert self.cells is not None, "self.cells is None, critical problem."
@@ -377,8 +359,7 @@ def corrupt_byte(b: bytes) -> Bytes:
377359
return Bytes(bytes([b[0] ^ 0xFF]))
378360

379361
# osaka and later
380-
fork_obj = fork_string_to_object(self.fork)
381-
amount_cell_proofs: int = cast(int, fork_obj.get_blob_constant("AMOUNT_CELL_PROOFS"))
362+
amount_cell_proofs: int = cast(int, self.fork.get_blob_constant("AMOUNT_CELL_PROOFS"))
382363
if amount_cell_proofs > 0:
383364
assert isinstance(self.proof, list), (
384365
"proof was expected to be a list but it isn't"
@@ -406,7 +387,7 @@ def corrupt_byte(b: bytes) -> Bytes:
406387

407388
# pre-osaka (cancun and prague)
408389
assert amount_cell_proofs == 0, (
409-
f"You need to adjust corrupt_proof to handle fork {self.fork}"
390+
f"You need to adjust corrupt_proof to handle fork {self.fork.name()}"
410391
)
411392
assert isinstance(self.proof, Bytes), "proof was expected to be Bytes but it isn't"
412393

@@ -426,8 +407,6 @@ def corrupt_byte(b: bytes) -> Bytes:
426407
# mytestfork.fork_at(timestamp=15000) # returns prague
427408
# TODO: call this once only at blob creation (not when reading blob from file) + remove timestamp from json
428409

429-
# TODO: in test_blob_txs_full.py cancun test: how to convert Hash to bytes?
430-
431410
# TODO: test all functions again
432411

433412
# --------- generate static blobs ------------
@@ -456,7 +435,9 @@ def corrupt_byte(b: bytes) -> Bytes:
456435
# duration_ms = (end - start) * 1000
457436
# print(f"Generated and wrote {amount_of_blobs} blobs to disk in: {duration_ms:.3f} ms")
458437

438+
459439
myosaka: Fork = Osaka
440+
print(f"Fork test print: {myosaka.name()}")
460441
myprague: Fork = Prague
461442
mycancun: Fork = Cancun
462443
myseed: int = 1337 # fork+seed is the unique ID of a blob

0 commit comments

Comments
 (0)