mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-12 11:44:41 +00:00
Update unit tests: add test_compute_subnets_for_sync_committee_slot_period_boundary
This commit is contained in:
parent
3c609e02ea
commit
dad698f97a
@ -143,20 +143,61 @@ def _subnet_for_sync_committee_index(spec, i):
|
||||
return i // (spec.SYNC_COMMITTEE_SIZE // spec.SYNC_COMMITTEE_SUBNET_COUNT)
|
||||
|
||||
|
||||
def _get_expected_subnets_by_pubkey(sync_committee_members):
|
||||
expected_subnets_by_pubkey = defaultdict(list)
|
||||
for (subnet, pubkey) in sync_committee_members:
|
||||
expected_subnets_by_pubkey[pubkey].append(subnet)
|
||||
return expected_subnets_by_pubkey
|
||||
|
||||
|
||||
@with_altair_and_later
|
||||
@with_state
|
||||
def test_compute_subnets_for_sync_committee(state, spec, phases):
|
||||
# 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)
|
||||
)
|
||||
some_sync_committee_members = list(
|
||||
(
|
||||
_subnet_for_sync_committee_index(spec, i),
|
||||
pubkey,
|
||||
)
|
||||
# use current_sync_committee
|
||||
for i, pubkey in enumerate(state.current_sync_committee.pubkeys)
|
||||
)
|
||||
|
||||
expected_subnets_by_pubkey = defaultdict(list)
|
||||
for (subnet, pubkey) in some_sync_committee_members:
|
||||
expected_subnets_by_pubkey[pubkey].append(subnet)
|
||||
expected_subnets_by_pubkey = _get_expected_subnets_by_pubkey(some_sync_committee_members)
|
||||
|
||||
for _, pubkey in some_sync_committee_members:
|
||||
validator_index = _validator_index_for_pubkey(state, pubkey)
|
||||
subnets = spec.compute_subnets_for_sync_committee(state, validator_index)
|
||||
expected_subnets = expected_subnets_by_pubkey[pubkey]
|
||||
assert subnets == expected_subnets
|
||||
|
||||
|
||||
@with_altair_and_later
|
||||
@with_state
|
||||
def test_compute_subnets_for_sync_committee_slot_period_boundary(state, spec, phases):
|
||||
# Transition to the end of the 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)
|
||||
)
|
||||
some_sync_committee_members = list(
|
||||
(
|
||||
_subnet_for_sync_committee_index(spec, i),
|
||||
pubkey,
|
||||
)
|
||||
# use next_sync_committee
|
||||
for i, pubkey in enumerate(state.next_sync_committee.pubkeys)
|
||||
)
|
||||
expected_subnets_by_pubkey = _get_expected_subnets_by_pubkey(some_sync_committee_members)
|
||||
|
||||
for _, pubkey in some_sync_committee_members:
|
||||
validator_index = _validator_index_for_pubkey(state, pubkey)
|
||||
|
Loading…
x
Reference in New Issue
Block a user