From 2a1358688b68db3210d53f4229fd4243cb5f5830 Mon Sep 17 00:00:00 2001 From: madlabman <10616301+madlabman@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:22:32 +0100 Subject: [PATCH] refactor: rename is_electra_attestation --- src/modules/csm/checkpoint.py | 9 +++++---- tests/modules/csm/test_processing_attestation.py | 9 ++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/modules/csm/checkpoint.py b/src/modules/csm/checkpoint.py index 9dd69eb31..9c7fa7a74 100644 --- a/src/modules/csm/checkpoint.py +++ b/src/modules/csm/checkpoint.py @@ -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: diff --git a/tests/modules/csm/test_processing_attestation.py b/tests/modules/csm/test_processing_attestation.py index 05ad72ecf..542f0ea08 100644 --- a/tests/modules/csm/test_processing_attestation.py +++ b/tests/modules/csm/test_processing_attestation.py @@ -1,5 +1,4 @@ from itertools import chain -from typing import Sequence from unittest.mock import Mock import pytest @@ -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 @@ -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