Convert assert to return False

This commit is contained in:
Justin Traglia 2024-10-02 16:02:39 -05:00
parent e02cbab59f
commit 3984bd3604
No known key found for this signature in database
GPG Key ID: F099C9CD25DF82A1
2 changed files with 13 additions and 9 deletions

View File

@ -73,11 +73,16 @@ def verify_data_column_sidecar(sidecar: DataColumnSidecar) -> bool:
Verify if the data column sidecar is valid.
"""
# The sidecar index must be within the valid range
assert sidecar.index < NUMBER_OF_COLUMNS
if sidecar.index >= NUMBER_OF_COLUMNS
return False
# A sidecar for zero blobs is invalid
assert len(sidecar.kzg_commitments) > 0
if len(sidecar.kzg_commitments) == 0:
return False
# There should be an equal number of cells/commitments/proofs
assert len(sidecar.column) == len(sidecar.kzg_commitments) == len(sidecar.kzg_proofs)
if len(sidecar.column) != len(sidecar.kzg_commitments) or len(sidecar.column) != len(sidecar.kzg_proofs):
return False
return True
```

View File

@ -1,6 +1,5 @@
import random
from eth2spec.test.context import (
expect_assertion_error,
single_phase,
spec_state_test,
spec_test,
@ -62,7 +61,7 @@ def test_verify_data_column_sidecar__invalid_zero_blobs(spec, state):
sidecar.column = []
sidecar.kzg_commitments = []
sidecar.kzg_proofs = []
expect_assertion_error(lambda: spec.verify_data_column_sidecar(sidecar))
assert not spec.verify_data_column_sidecar(sidecar)
@with_eip7594_and_later
@ -71,7 +70,7 @@ def test_verify_data_column_sidecar__invalid_zero_blobs(spec, state):
def test_verify_data_column_sidecar__invalid_index(spec, state):
sidecar = compute_data_column_sidecar(spec, state)
sidecar.index = 128
expect_assertion_error(lambda: spec.verify_data_column_sidecar(sidecar))
assert not spec.verify_data_column_sidecar(sidecar)
@with_eip7594_and_later
@ -80,7 +79,7 @@ def test_verify_data_column_sidecar__invalid_index(spec, state):
def test_verify_data_column_sidecar__invalid_mismatch_len_column(spec, state):
sidecar = compute_data_column_sidecar(spec, state)
sidecar.column = sidecar.column[1:]
expect_assertion_error(lambda: spec.verify_data_column_sidecar(sidecar))
assert not spec.verify_data_column_sidecar(sidecar)
@with_eip7594_and_later
@ -89,7 +88,7 @@ def test_verify_data_column_sidecar__invalid_mismatch_len_column(spec, state):
def test_verify_data_column_sidecar__invalid_mismatch_len_kzg_commitments(spec, state):
sidecar = compute_data_column_sidecar(spec, state)
sidecar.kzg_commitments = sidecar.kzg_commitments[1:]
expect_assertion_error(lambda: spec.verify_data_column_sidecar_kzg_proofs(sidecar))
assert not spec.verify_data_column_sidecar(sidecar)
@with_eip7594_and_later
@ -98,7 +97,7 @@ def test_verify_data_column_sidecar__invalid_mismatch_len_kzg_commitments(spec,
def test_verify_data_column_sidecars__invalid_mismatch_len_kzg_proofs(spec, state):
sidecar = compute_data_column_sidecar(spec, state)
sidecar.kzg_proofs = sidecar.kzg_proofs[1:]
expect_assertion_error(lambda: spec.verify_data_column_sidecar_kzg_proofs(sidecar))
assert not spec.verify_data_column_sidecar(sidecar)
# Tests for verify_data_column_sidecar_kzg_proofs