Add Altair networking helper tests

This commit is contained in:
Hsiao-Wei Wang 2021-07-02 14:42:02 +08:00
parent 060ba633eb
commit 7bde1729b1
No known key found for this signature in database
GPG Key ID: 1111A8A81778319E
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,47 @@
from eth2spec.test.context import (
with_altair_and_later,
spec_state_test,
)
from eth2spec.test.helpers.state import (
transition_to,
)
@with_altair_and_later
@spec_state_test
def test_get_sync_subcommittee_pubkeys_current_sync_committee(state, spec):
# Transition to the head of the next period
transition_to(spec, state, spec.SLOTS_PER_EPOCH * spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD)
next_slot_epoch = spec.compute_epoch_at_slot(state.slot + 1)
assert (
spec.compute_sync_committee_period(spec.get_current_epoch(state))
== spec.compute_sync_committee_period(next_slot_epoch)
)
sync_committee = state.current_sync_committee
sync_subcommittee_size = spec.SYNC_COMMITTEE_SIZE // spec.SYNC_COMMITTEE_SUBNET_COUNT
subcommittee_index = 1
i = subcommittee_index * sync_subcommittee_size
expect = sync_committee.pubkeys[i:i + sync_subcommittee_size]
assert spec.get_sync_subcommittee_pubkeys(state, subcommittee_index) == expect
@with_altair_and_later
@spec_state_test
def test_get_sync_subcommittee_pubkeys_next_sync_committee(state, spec):
# Transition to the end of the current period
transition_to(spec, state, spec.SLOTS_PER_EPOCH * spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD - 1)
next_slot_epoch = spec.compute_epoch_at_slot(state.slot + 1)
assert (
spec.compute_sync_committee_period(spec.get_current_epoch(state))
!= spec.compute_sync_committee_period(next_slot_epoch)
)
sync_committee = state.next_sync_committee
sync_subcommittee_size = spec.SYNC_COMMITTEE_SIZE // spec.SYNC_COMMITTEE_SUBNET_COUNT
subcommittee_index = 1
i = subcommittee_index * sync_subcommittee_size
expect = sync_committee.pubkeys[i:i + sync_subcommittee_size]
assert spec.get_sync_subcommittee_pubkeys(state, subcommittee_index) == expect