Example #1
0
def test_calculate_first_committee_at_slot(genesis_state,
                                           config):
    state = genesis_state
    slots_per_epoch = config.SLOTS_PER_EPOCH
    shard_count = config.SHARD_COUNT
    target_committee_size = config.TARGET_COMMITTEE_SIZE

    current_epoch = state.current_epoch(slots_per_epoch)

    active_validator_indices = get_active_validator_indices(state.validators, current_epoch)

    committees_per_slot = get_committees_per_slot(
        len(active_validator_indices),
        shard_count,
        slots_per_epoch,
        target_committee_size,
    )

    assert state.slot % config.SLOTS_PER_EPOCH == 0
    for slot in range(state.slot, state.slot + config.SLOTS_PER_EPOCH):
        offset = committees_per_slot * (slot % slots_per_epoch)
        shard = (
            get_epoch_start_shard(state, current_epoch, config) + offset
        ) % shard_count
        committee = get_crosslink_committee(
            state,
            current_epoch,
            shard,
            config,
        )

        assert committee == _calculate_first_committee_at_slot(state, slot, CommitteeConfig(config))
def test_get_committees_per_slot(active_validator_count, slots_per_epoch,
                                 target_committee_size, shard_count,
                                 expected_committee_count):
    assert expected_committee_count // slots_per_epoch == get_committees_per_slot(
        active_validator_count=active_validator_count,
        shard_count=shard_count,
        slots_per_epoch=slots_per_epoch,
        target_committee_size=target_committee_size,
    )