def test_get_block_root( current_block_number, target_slot, success, epoch_length, sample_block): blocks, latest_block_roots = generate_mock_latest_block_roots( sample_block, current_block_number, epoch_length, ) if success: block_root = get_block_root( latest_block_roots, current_block_number, target_slot, ) assert block_root == blocks[target_slot].root else: with pytest.raises(ValueError): get_block_root( latest_block_roots, current_block_number, target_slot, )
def validate_serenity_attestation(state: BeaconState, attestation: Attestation, epoch_length: int, min_attestation_inclusion_delay: int, latest_block_roots_length: int) -> None: """ Validate the given ``attestation``. Raise ``ValidationError`` if it's invalid. """ validate_serenity_attestation_slot( attestation.data, state.slot, epoch_length, min_attestation_inclusion_delay, ) validate_serenity_attestation_justified_slot( attestation.data, state.slot, state.previous_justified_slot, state.justified_slot, epoch_length, ) validate_serenity_attestation_justified_block_root( attestation.data, justified_block_root=get_block_root( state=state, slot=attestation.data.justified_slot, latest_block_roots_length=latest_block_roots_length, ), ) validate_serenity_attestation_latest_crosslink_root( attestation.data, latest_crosslink_root=state.latest_crosslinks[ attestation.data.shard].shard_block_root, ) validate_serenity_attestation_shard_block_root(attestation.data) validate_serenity_attestation_aggregate_signature( state, attestation, epoch_length, )
def create_mock_signed_attestations_at_slot(state, attestation_slot): attestations = [] shard_and_committees_at_slot = get_shard_committees_at_slot( state, slot=attestation_slot, epoch_length=config.EPOCH_LENGTH, ) for shard_committee in shard_and_committees_at_slot: # have 0th committee member sign voting_committee_indices = [0] latest_crosslink_root = state.latest_crosslinks[shard_committee.shard].shard_block_root assert len(shard_committee.committee) > 0 attestation_data = AttestationData(**sample_attestation_data_params).copy( slot=attestation_slot, shard=shard_committee.shard, justified_slot=state.previous_justified_slot, justified_block_root=get_block_root( state, state.previous_justified_slot, config.LATEST_BLOCK_ROOTS_LENGTH, ), latest_crosslink_root=latest_crosslink_root, shard_block_root=ZERO_HASH32, ) attestations.append( create_mock_signed_attestation( state, shard_committee, voting_committee_indices, attestation_data, ) ) return tuple(attestations)