Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/core/pyspec/eth2spec/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def pytest_addoption(parser):
"fastest: use milagro for signatures and arkworks for everything else (e.g. KZG)"
),
)
parser.addoption(
"--disable-spec-cache",
action="store_true",
default=False,
help="disable-spec-cache: disable the spec cache",
)


def _validate_fork_name(forks):
Expand All @@ -78,6 +84,15 @@ def preset(request):
context.DEFAULT_TEST_PRESET = request.config.getoption("--preset")


@fixture(autouse=True)
def spec_cache(request):
disable_spec_cache = request.config.getoption("--disable-spec-cache")
if disable_spec_cache:
spec_cache.DISABLED_CACHE = True
else:
spec_cache.DISABLED_CACHE = False


@fixture(autouse=True)
def run_phases(request):
forks = request.config.getoption("--fork", default=None)
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
###############################################################################
# Test cases for blob_to_kzg_commitment
###############################################################################

from eth_utils import encode_hex

from eth2spec.test.context import single_phase, spec_test, with_phases
from eth2spec.test.utils.kzg_tests import (
INVALID_BLOBS,
VALID_BLOBS,
)
from tests.core.pyspec.eth2spec.test.helpers.constants import DENEB
from tests.infra.spec_cache import spec_cache
from tests.infra.template_test import template_test


@template_test
def _blob_to_kzg_commitment_case_valid_blob(index):
blob = VALID_BLOBS[index]

@with_phases([DENEB])
@spec_test
@single_phase
@spec_cache(["blob_to_kzg_commitment"])
def the_test(spec):
commitment = spec.blob_to_kzg_commitment(blob)
# assert exception is not thrown with valid blob

yield (
"data",
"data",
{
"input": {"blob": encode_hex(blob)},
"output": encode_hex(commitment),
},
)

return (the_test, f"test_blob_to_kzg_commitment_case_valid_blob_{index}")


for index in range(0, len(VALID_BLOBS)):
_blob_to_kzg_commitment_case_valid_blob(index)


@template_test
def _blob_to_kzg_commitment_case_invalid_blob(index):
blob = INVALID_BLOBS[index]

@with_phases([DENEB])
@spec_test
@single_phase
@spec_cache(["blob_to_kzg_commitment"])
def the_test(spec):
commitment = None
try:
commitment = spec.blob_to_kzg_commitment(blob)
except Exception:
pass

# exception is thrown
assert commitment is None

yield (
"data",
"data",
{
"input": {"blob": encode_hex(blob)},
"output": None,
},
)

return (the_test, f"test_blob_to_kzg_commitment_case_invalid_blob_{index}")


for index in range(0, len(INVALID_BLOBS)):
_blob_to_kzg_commitment_case_invalid_blob(index)
18 changes: 18 additions & 0 deletions tests/core/pyspec/eth2spec/test/fulu/fork_choice/test_on_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
on_tick_and_append_step,
tick_and_add_block_with_data,
)
from tests.infra.spec_cache import spec_cache_peerdas


def flip_one_bit_in_bytes(data: bytes, index: int = 0) -> bytes:
Expand Down Expand Up @@ -46,6 +47,7 @@ def get_alt_sidecars(spec, state):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__ok(spec, state):
"""
Similar to test_simple_blob_data, but in PeerDAS version that is from Fulu onwards.
Expand Down Expand Up @@ -118,6 +120,7 @@ def run_on_block_peerdas_invalid_test(spec, state, fn):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__not_available(spec, state):
"""
Test is_data_available throws an exception when not enough columns are sampled.
Expand All @@ -132,6 +135,7 @@ def test_on_block_peerdas__not_available(spec, state):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_zero_blobs(spec, state):
"""
Test is_data_available returns false when there are no blobs in the sidecars.
Expand All @@ -148,6 +152,7 @@ def invalid_zero_blobs(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_index_1(spec, state):
"""
Test invalid index in sidecars for negative PeerDAS on_block test.
Expand All @@ -162,6 +167,7 @@ def invalid_index(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_index_2(spec, state):
"""
Test invalid index in sidecars for negative PeerDAS on_block test.
Expand All @@ -176,6 +182,7 @@ def invalid_index(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_mismatch_len_column_1(spec, state):
"""
Test mismatch length in column for negative PeerDAS on_block test.
Expand All @@ -190,6 +197,7 @@ def invalid_mismatch_len_column(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_mismatch_len_column_2(spec, state):
"""
Test mismatch length in column for negative PeerDAS on_block test.
Expand All @@ -204,6 +212,7 @@ def invalid_mismatch_len_column(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_mismatch_len_kzg_commitments_1(spec, state):
"""
Test mismatch length in kzg_commitments for negative PeerDAS on_block test.
Expand All @@ -218,6 +227,7 @@ def invalid_mismatch_len_kzg_commitments(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_mismatch_len_kzg_commitments_2(spec, state):
"""
Test mismatch length in kzg_commitments for negative PeerDAS on_block test.
Expand All @@ -232,6 +242,7 @@ def invalid_mismatch_len_kzg_commitments(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_mismatch_len_kzg_proofs_1(spec, state):
"""
Test mismatch length in kzg_proofs for negative PeerDAS on_block test.
Expand All @@ -246,6 +257,7 @@ def invalid_mismatch_len_kzg_proofs(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_mismatch_len_kzg_proofs_2(spec, state):
"""
Test mismatch length in kzg_proofs for negative PeerDAS on_block test.
Expand All @@ -260,6 +272,7 @@ def invalid_mismatch_len_kzg_proofs(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_wrong_column_1(spec, state):
"""
Test wrong column for negative PeerDAS on_block test.
Expand All @@ -274,6 +287,7 @@ def invalid_wrong_column(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_wrong_column_2(spec, state):
"""
Test wrong column for negative PeerDAS on_block test.
Expand All @@ -288,6 +302,7 @@ def invalid_wrong_column(sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_wrong_commitment_1(spec, state):
"""
Test wrong commitment for negative PeerDAS on_block test.
Expand All @@ -303,6 +318,7 @@ def invalid_wrong_commitment(sidecars, alt_sidecars=alt_sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_wrong_commitment_2(spec, state):
"""
Test wrong commitment for negative PeerDAS on_block test.
Expand All @@ -318,6 +334,7 @@ def invalid_wrong_commitment(sidecars, alt_sidecars=alt_sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_wrong_proof_1(spec, state):
"""
Test wrong proof for negative PeerDAS on_block test.
Expand All @@ -333,6 +350,7 @@ def invalid_wrong_proof(sidecars, alt_sidecars=alt_sidecars):

@with_all_phases_from_to(FULU, GLOAS)
@spec_state_test
@spec_cache_peerdas
def test_on_block_peerdas__invalid_wrong_proof_2(spec, state):
"""
Test wrong proof for negative PeerDAS on_block test.
Expand Down
8 changes: 1 addition & 7 deletions tests/core/pyspec/eth2spec/test/helpers/blob.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import random
from functools import cache
from random import Random

from rlp import encode, Serializable
Expand Down Expand Up @@ -170,7 +169,7 @@ def get_block_with_blob_and_sidecars(spec, state, rng=None, blob_count=1):
block, blobs, blob_kzg_commitments, blob_kzg_proofs = get_block_with_blob(
spec, state, rng=rng, blob_count=blob_count
)
cells_and_kzg_proofs = [_cached_compute_cells_and_kzg_proofs(spec, blob) for blob in blobs]
cells_and_kzg_proofs = [spec.compute_cells_and_kzg_proofs(blob) for blob in blobs]

# We need a signed block to call `get_data_column_sidecars_from_block`
signed_block = state_transition_and_sign_block(spec, state, block)
Expand All @@ -182,8 +181,3 @@ def get_block_with_blob_and_sidecars(spec, state, rng=None, blob_count=1):
else:
sidecars = spec.get_data_column_sidecars_from_block(signed_block, cells_and_kzg_proofs)
return block, blobs, blob_kzg_proofs, signed_block, sidecars


@cache
def _cached_compute_cells_and_kzg_proofs(spec, blob):
return spec.compute_cells_and_kzg_proofs(blob)
2 changes: 1 addition & 1 deletion tests/core/pyspec/eth2spec/test/utils/kzg_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
int_to_big_endian,
)

from eth2spec.fulu import spec
from eth2spec.fulu import mainnet as spec
from eth2spec.utils import bls

###############################################################################
Expand Down
Loading