Skip to content

Commit 18d007d

Browse files
committed
loading blob from file should be stand-alone function for ease-of-use
1 parent 5905a26 commit 18d007d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tests/osaka/eip7594_peerdas/helper_functions.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,16 @@ def write_to_file(self):
325325
with open(file_name, "w", encoding="utf-8") as f: # overwrite existing
326326
f.write(json_str)
327327

328-
def read_from_file(self) -> "Blob":
329-
"""Read a .json file and reconstruct object it represents."""
330-
# TODO: file_name should match location defined in write_to_file
331-
file_name: str = self.name + ".json"
332-
with open(file_name, "r", encoding="utf-8") as f:
333-
json_str: str = f.read()
334328

335-
# reconstruct object
336-
return Blob.model_validate_json(json_str)
329+
def LoadBlobFromFile(seed: int) -> Blob:
330+
"""Read a .json file and reconstruct object it represents."""
331+
# TODO: file_name should match location defined in write_to_file
332+
file_name: str = "blob_" + str(seed) + ".json"
333+
with open(file_name, "r", encoding="utf-8") as f:
334+
json_str: str = f.read()
335+
336+
# reconstruct object
337+
return Blob.model_validate_json(json_str)
337338

338339

339340
def NewBlob(fork: str, seed: int = 0, timestamp: int = 0) -> Blob:
@@ -437,7 +438,7 @@ def get_cells(data: Bytes) -> List[Bytes] | None:
437438
assert b.timestamp == restored.timestamp
438439

439440
b.write_to_file()
440-
c: Blob = NewBlob("prague", 1337).read_from_file() # annoying: have to put dummy value for fork
441+
c: Blob = LoadBlobFromFile(1337) # annoying: have to put dummy value for fork
441442
assert b.data == c.data
442443
assert b.commitment == c.commitment
443444
assert b.proof == c.proof

0 commit comments

Comments
 (0)