Skip to content

Commit

Permalink
refactor: rename is_electra_attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
madlabman committed Dec 20, 2024
1 parent 3d00d10 commit 2a13586
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/modules/csm/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,13 @@ def process_attestations(attestations: Iterable[BlockAttestation], committees: C


def get_committee_indices(attestation: BlockAttestation) -> list[CommitteeIndex]:
if not is_electra_attestation(attestation):
return [attestation.data.index]
return [str(i) for i in get_set_indices(hex_bitvector_to_list(attestation.committee_bits))]
if is_eip7549_attestation(attestation):
return [str(i) for i in get_set_indices(hex_bitvector_to_list(attestation.committee_bits))]
return [attestation.data.index]


def is_electra_attestation(attestation: BlockAttestation) -> TypeGuard[BlockAttestationElectra]:
def is_eip7549_attestation(attestation: BlockAttestation) -> TypeGuard[BlockAttestationElectra]:
# @see https://eips.ethereum.org/EIPS/eip-7549
has_committee_bits = getattr(attestation, "committee_bits") is not None
has_zero_index = attestation.data.index == "0"
if has_committee_bits and not has_zero_index:
Expand Down
9 changes: 4 additions & 5 deletions tests/modules/csm/test_processing_attestation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from itertools import chain
from typing import Sequence
from unittest.mock import Mock

import pytest
Expand All @@ -8,7 +7,7 @@
get_committee_indices,
hex_bitlist_to_list,
hex_bitvector_to_list,
is_electra_attestation,
is_eip7549_attestation,
process_attestations,
)
from src.providers.consensus.types import BlockAttestation
Expand Down Expand Up @@ -128,14 +127,14 @@ def test_attested_indices_post_electra():
@pytest.mark.unit
def test_derive_attestation_version():
att: BlockAttestation = Mock(data=Mock(index="0"), aggregation_bits="", committee_bits=None)
assert not is_electra_attestation(att)
assert not is_eip7549_attestation(att)

att: BlockAttestation = Mock(data=Mock(index="0"), aggregation_bits="", committee_bits="")
assert is_electra_attestation(att)
assert is_eip7549_attestation(att)

att: BlockAttestation = Mock(data=Mock(index="1"), aggregation_bits="", committee_bits="")
with pytest.raises(ValueError, match="invalid attestation"):
assert is_electra_attestation(att)
assert is_eip7549_attestation(att)


@pytest.mark.unit
Expand Down

0 comments on commit 2a13586

Please sign in to comment.