Skip to content

Commit 3e39639

Browse files
committed
cancun test now uses new Blob class
1 parent ccfedf8 commit 3e39639

File tree

4 files changed

+87
-106
lines changed

4 files changed

+87
-106
lines changed

src/ethereum_test_types/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Common definitions and types."""
22

3+
from .blob import Blob
34
from .eest_types import (
45
EOA,
56
Account,
67
Alloc,
78
AuthorizationTuple,
8-
# Blob,
99
CamelModel,
1010
ConsolidationRequest,
1111
DepositRequest,

src/ethereum_test_types/blob.py

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -400,47 +400,47 @@ def corrupt_byte(b: bytes) -> Bytes:
400400
# static_blob.write_to_file()
401401
# --------------------------------------------
402402

403-
myosaka: Fork = Osaka
404-
myprague: Fork = Prague
405-
mycancun: Fork = Cancun
406-
myseed: int = 1337 # fork+seed is the unique ID of a blob
407-
mytimestamp: int = 168123123
408-
b: Blob = Blob.NewBlob(myosaka, myseed, mytimestamp)
409-
json_str: str = b.model_dump_json()
410-
restored: Blob = Blob.model_validate_json(json_str)
411-
assert b.data == restored.data
412-
assert b.commitment == restored.commitment
413-
assert b.proof == restored.proof
414-
assert b.cells == restored.cells
415-
assert b.versioned_hash == restored.versioned_hash
416-
assert b.name == restored.name
417-
assert b.fork == restored.fork
418-
assert b.timestamp == restored.timestamp
419-
print(type(b.proof), len(b.proof))
420-
print(BYTES_PER_FIELD_ELEMENT)
421-
print(len(b.data))
422-
# b.write_to_file()
423-
# c: Blob = Blob.LoadBlobFromFile("blob_" + "osaka" + "_" + str(myseed) + "_" + str(mytimestamp))
424-
# assert b.data == c.data
425-
# assert b.commitment == c.commitment
426-
# assert b.proof == c.proof
427-
# assert b.cells == c.cells
428-
# assert b.versioned_hash == c.versioned_hash
429-
# assert b.name == c.name
430-
# assert b.fork == c.fork
431-
# assert b.timestamp == c.timestamp
432-
d: Blob = Blob.NewBlob(myprague, myseed, 123)
433-
# d.write_to_file()
434-
e: Blob = Blob.NewBlob(myprague, myseed, 123)
435-
print("Line above should say blob already existed and was loaded from file")
436-
ee: Blob = Blob.NewBlob(myprague, myseed, 1234)
437-
newtimestamp = 999999
438-
f: Blob = Blob.NewBlob(mycancun, 1337, newtimestamp)
439-
# f.write_to_file()
440-
h: Blob = Blob.NewBlob(myosaka, myseed)
441-
# h.write_to_file()
442-
zz: Blob = Blob.NewBlob(myosaka, myseed)
443-
print("Line above should say blob already existed and was loaded from file")
403+
# myosaka: Fork = Osaka
404+
# myprague: Fork = Prague
405+
# mycancun: Fork = Cancun
406+
# myseed: int = 1337 # fork+seed is the unique ID of a blob
407+
# mytimestamp: int = 168123123
408+
# b: Blob = Blob.NewBlob(myosaka, myseed, mytimestamp)
409+
# json_str: str = b.model_dump_json()
410+
# restored: Blob = Blob.model_validate_json(json_str)
411+
# assert b.data == restored.data
412+
# assert b.commitment == restored.commitment
413+
# assert b.proof == restored.proof
414+
# assert b.cells == restored.cells
415+
# assert b.versioned_hash == restored.versioned_hash
416+
# assert b.name == restored.name
417+
# assert b.fork == restored.fork
418+
# assert b.timestamp == restored.timestamp
419+
# print(type(b.proof), len(b.proof))
420+
# print(BYTES_PER_FIELD_ELEMENT)
421+
# print(len(b.data))
422+
# # b.write_to_file()
423+
# # c: Blob = Blob.LoadBlobFromFile("blob_" + "osaka" + "_" + str(myseed) + "_" + str(mytimestamp))
424+
# # assert b.data == c.data
425+
# # assert b.commitment == c.commitment
426+
# # assert b.proof == c.proof
427+
# # assert b.cells == c.cells
428+
# # assert b.versioned_hash == c.versioned_hash
429+
# # assert b.name == c.name
430+
# # assert b.fork == c.fork
431+
# # assert b.timestamp == c.timestamp
432+
# d: Blob = Blob.NewBlob(myprague, myseed, 123)
433+
# # d.write_to_file()
434+
# e: Blob = Blob.NewBlob(myprague, myseed, 123)
435+
# print("Line above should say blob already existed and was loaded from file")
436+
# ee: Blob = Blob.NewBlob(myprague, myseed, 1234)
437+
# newtimestamp = 999999
438+
# f: Blob = Blob.NewBlob(mycancun, 1337, newtimestamp)
439+
# # f.write_to_file()
440+
# h: Blob = Blob.NewBlob(myosaka, myseed)
441+
# # h.write_to_file()
442+
# zz: Blob = Blob.NewBlob(myosaka, myseed)
443+
# print("Line above should say blob already existed and was loaded from file")
444444
# you can load a blob either via just filename or via absolute path or via relative path (cwd is ./src/ethereum_test_types) # noqa: E501
445445
# yyy: Blob = Blob.LoadBlobFromFile("blob_cancun_1337_999999.json")
446446
# # yyyy: Blob = Blob.LoadBlobFromFile(
@@ -456,16 +456,16 @@ def corrupt_byte(b: bytes) -> Bytes:
456456

457457
# test proof corruption
458458
# osaka
459-
testseed = 55
460-
ddd: Blob = Blob.NewBlob(Osaka, testseed + 10)
461-
oldValue = ddd.proof[0][5]
462-
for m in Blob.ProofCorruptionMode:
463-
ddd.corrupt_proof(m)
464-
print("proof corruption works (osaka):", oldValue != ddd.proof[0][5])
465-
# prague
466-
eeeeeeeeee: Blob = Blob.NewBlob(Prague, testseed + 11)
467-
oldValue = eeeeeeeeee.proof[5]
468-
for m in Blob.ProofCorruptionMode:
469-
eeeeeeeeee.corrupt_proof(m)
470-
print("proof corruption works (prague):", oldValue != eeeeeeeeee.proof[5])
471-
print("pydantic model works")
459+
# testseed = 55
460+
# ddd: Blob = Blob.NewBlob(Osaka, testseed + 10)
461+
# oldValue = ddd.proof[0][5]
462+
# for m in Blob.ProofCorruptionMode:
463+
# ddd.corrupt_proof(m)
464+
# print("proof corruption works (osaka):", oldValue != ddd.proof[0][5])
465+
# # prague
466+
# eeeeeeeeee: Blob = Blob.NewBlob(Prague, testseed + 11)
467+
# oldValue = eeeeeeeeee.proof[5]
468+
# for m in Blob.ProofCorruptionMode:
469+
# eeeeeeeeee.corrupt_proof(m)
470+
# print("proof corruption works (prague):", oldValue != eeeeeeeeee.proof[5])
471+
# print("pydantic model works")
Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,30 @@
11
"""Common constants, classes & functions local to EIP-4844 tests."""
22

3-
from dataclasses import dataclass
43
from typing import List, Literal, Tuple
54

6-
from .spec import Spec
5+
from ethereum_test_types.blob import Blob
6+
7+
from .spec import Spec, ref_spec_4844
78

89
INF_POINT = (0xC0 << 376).to_bytes(48, byteorder="big")
910
Z = 0x623CE31CF9759A5C8DAF3A357992F9F3DD7F9339D8998BC8E68373E54F00B75E
1011
Z_Y_INVALID_ENDIANNESS: Literal["little", "big"] = "little"
1112
Z_Y_VALID_ENDIANNESS: Literal["little", "big"] = "big"
1213

1314

14-
@dataclass(kw_only=True)
15-
class Blob:
16-
"""Class representing a full blob."""
17-
18-
blob: bytes
19-
kzg_commitment: bytes
20-
kzg_proof: bytes
21-
22-
def versioned_hash(self) -> bytes:
23-
"""Calculate versioned hash for a given blob."""
24-
return Spec.kzg_to_versioned_hash(self.kzg_commitment)
25-
26-
@staticmethod
27-
def blobs_to_transaction_input(
28-
input_blobs: List["Blob"],
29-
) -> Tuple[List[bytes], List[bytes], List[bytes]]:
30-
"""
31-
Return tuple of lists of blobs, kzg commitments formatted to be added to a network blob
32-
type transaction.
33-
"""
34-
blobs: List[bytes] = []
35-
kzg_commitments: List[bytes] = []
36-
kzg_proofs: List[bytes] = []
37-
38-
for blob in input_blobs:
39-
blobs.append(blob.blob)
40-
kzg_commitments.append(blob.kzg_commitment)
41-
kzg_proofs.append(blob.kzg_proof)
42-
return (blobs, kzg_commitments, kzg_proofs)
15+
def blobs_to_transaction_input(
16+
input_blobs: List[Blob],
17+
) -> Tuple[List[bytes], List[bytes], List[bytes]]:
18+
"""
19+
Return tuple of lists of blobs, kzg commitments formatted to be added to a network blob
20+
type transaction.
21+
"""
22+
blobs: List[bytes] = []
23+
kzg_commitments: List[bytes] = []
24+
kzg_proofs: List[bytes] = []
25+
26+
for blob in input_blobs:
27+
blobs.append(blob.data)
28+
kzg_commitments.append(blob.commitment)
29+
kzg_proofs.append(blob.proof)
30+
return (blobs, kzg_commitments, kzg_proofs)

tests/cancun/eip4844_blobs/test_blob_txs_full.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pytest
1010

11+
from ethereum_test_base_types.base_types import Hash
1112
from ethereum_test_forks import Fork
1213
from ethereum_test_tools import (
1314
Address,
@@ -21,9 +22,10 @@
2122
Transaction,
2223
TransactionException,
2324
)
25+
from ethereum_test_types import Blob
26+
from tests.cancun.eip4844_blobs.common import blobs_to_transaction_input
2427

25-
from .common import INF_POINT, Blob
26-
from .spec import Spec, SpecHelpers, ref_spec_4844
28+
from .spec import Spec, ref_spec_4844
2729

2830
REFERENCE_SPEC_GIT_PATH = ref_spec_4844.git_path
2931
REFERENCE_SPEC_VERSION = ref_spec_4844.version
@@ -92,7 +94,11 @@ def tx_max_priority_fee_per_gas() -> int:
9294
@pytest.fixture
9395
def txs_versioned_hashes(txs_blobs: List[List[Blob]]) -> List[List[bytes]]:
9496
"""List of blob versioned hashes derived from the blobs."""
95-
return [[blob.versioned_hash() for blob in blob_tx] for blob_tx in txs_blobs]
97+
version_hashes: List[List[Hash]] = [
98+
[blob.versioned_hash for blob in blob_tx] for blob_tx in txs_blobs
99+
]
100+
# TODO: how to convert Hash to bytes?
101+
return version_hashes
96102

97103

98104
@pytest.fixture(autouse=True)
@@ -178,7 +184,7 @@ def txs( # noqa: D103
178184
wrapped_blob_transaction=tx_wrapped_blobs,
179185
)
180186
if tx_wrapped_blobs:
181-
blobs_info = Blob.blobs_to_transaction_input(tx_blobs)
187+
blobs_info = blobs_to_transaction_input(tx_blobs)
182188
network_wrapped_tx = NetworkWrappedTransaction(
183189
tx=tx,
184190
blobs=blobs_info[0],
@@ -242,17 +248,12 @@ def generate_full_blob_tests(
242248
Return a list of tests for invalid blob transactions due to insufficient max fee per blob gas
243249
parametrized for each different fork.
244250
"""
245-
blob_size = Spec.FIELD_ELEMENTS_PER_BLOB * SpecHelpers.BYTES_PER_FIELD_ELEMENT
246251
max_blobs = fork.max_blobs_per_block()
247252
return [
248253
pytest.param(
249254
[ # Txs
250255
[ # Blobs per transaction
251-
Blob(
252-
blob=bytes(blob_size),
253-
kzg_commitment=INF_POINT,
254-
kzg_proof=INF_POINT,
255-
),
256+
Blob.NewBlob(fork),
256257
]
257258
],
258259
[True],
@@ -261,11 +262,7 @@ def generate_full_blob_tests(
261262
pytest.param(
262263
[ # Txs
263264
[ # Blobs per transaction
264-
Blob(
265-
blob=bytes(blob_size),
266-
kzg_commitment=INF_POINT,
267-
kzg_proof=INF_POINT,
268-
)
265+
Blob.NewBlob(fork),
269266
]
270267
for _ in range(max_blobs)
271268
],
@@ -275,11 +272,7 @@ def generate_full_blob_tests(
275272
pytest.param(
276273
[ # Txs
277274
[ # Blobs per transaction
278-
Blob(
279-
blob=bytes(blob_size),
280-
kzg_commitment=INF_POINT,
281-
kzg_proof=INF_POINT,
282-
)
275+
Blob.NewBlob(fork),
283276
]
284277
for _ in range(max_blobs)
285278
],

0 commit comments

Comments
 (0)