Пример #1
0
def test_generate_aggregate_pubkeys(activated_genesis_validators,
                                    sample_slashable_vote_data_params,
                                    data):
    max_value_for_list = len(activated_genesis_validators) - 1
    (indices, some_index) = _list_and_index(
        data,
        elements=st.integers(
            min_value=0,
            max_value=max_value_for_list,
        )
    )
    custody_bit_0_indices = indices[:some_index]
    custody_bit_1_indices = indices[some_index:]

    key = "custody_bit_0_indices"
    sample_slashable_vote_data_params[key] = custody_bit_0_indices
    key = "custody_bit_1_indices"
    sample_slashable_vote_data_params[key] = custody_bit_1_indices

    votes = SlashableVoteData(**sample_slashable_vote_data_params)

    keys = generate_aggregate_pubkeys(activated_genesis_validators, votes)
    assert len(keys) == 2

    (poc_0_key, poc_1_key) = keys

    poc_0_keys = get_pubkey_for_indices(activated_genesis_validators, custody_bit_0_indices)
    poc_1_keys = get_pubkey_for_indices(activated_genesis_validators, custody_bit_1_indices)

    assert bls.aggregate_pubkeys(poc_0_keys) == poc_0_key
    assert bls.aggregate_pubkeys(poc_1_keys) == poc_1_key
Пример #2
0
def test_get_pubkey_for_indices(activated_genesis_validators, data):
    max_value_for_list = len(activated_genesis_validators) - 1
    indices = _generate_some_indices(data, max_value_for_list)
    pubkeys = get_pubkey_for_indices(activated_genesis_validators, indices)

    assert len(indices) == len(pubkeys)

    for index, pubkey in enumerate(pubkeys):
        validator_index = indices[index]
        assert activated_genesis_validators[validator_index].pubkey == pubkey
Пример #3
0
def test_generate_aggregate_pubkeys(activated_genesis_validators,
                                    sample_slashable_attestation_params, data):
    max_value_for_list = len(activated_genesis_validators) - 1
    (validator_indices,
     some_index) = _list_and_index(data,
                                   elements=st.integers(
                                       min_value=0,
                                       max_value=max_value_for_list,
                                   ))

    key = "validator_indices"
    sample_slashable_attestation_params[key] = validator_indices

    custody_bitfield = get_empty_bitfield(len(validator_indices))
    for index in range(some_index):
        custody_bitfield = set_voted(custody_bitfield, index)

    key = "custody_bitfield"
    sample_slashable_attestation_params[key] = custody_bitfield

    slashable_attestation = SlashableAttestation(
        **sample_slashable_attestation_params)
    custody_bit_0_indices, custody_bit_1_indices = slashable_attestation.custody_bit_indices
    assert len(
        set(custody_bit_0_indices).intersection(
            set(custody_bit_1_indices))) == 0

    keys = generate_aggregate_pubkeys(activated_genesis_validators,
                                      slashable_attestation)
    assert len(keys) == 2

    (poc_0_key, poc_1_key) = keys

    poc_0_keys = get_pubkey_for_indices(activated_genesis_validators,
                                        custody_bit_0_indices)
    poc_1_keys = get_pubkey_for_indices(activated_genesis_validators,
                                        custody_bit_1_indices)

    assert bls.aggregate_pubkeys(poc_0_keys) == poc_0_key
    assert bls.aggregate_pubkeys(poc_1_keys) == poc_1_key