示例#1
0
def test_validate_attestation_attester_bitfield(attestation_validation_fixture,
                                                config):
    (crystallized_state, active_state, original_attestation, block,
     parent_block) = attestation_validation_fixture

    attestation = copy.deepcopy(original_attestation)
    attestation.attester_bitfield = get_empty_bitfield(10)
    with pytest.raises(ValidationError):
        validate_attestation(
            crystallized_state,
            active_state,
            attestation,
            block,
            parent_block,
            config,
        )

    attestation = copy.deepcopy(original_attestation)
    attestation_indices = get_attestation_indices(crystallized_state,
                                                  attestation, config)
    last_bit = len(attestation_indices)
    attestation.attester_bitfield = set_voted(attestation.attester_bitfield,
                                              last_bit)

    with pytest.raises(ValidationError):
        validate_attestation(
            crystallized_state,
            active_state,
            attestation,
            block,
            parent_block,
            config,
        )
示例#2
0
def test_validate_attestation_slot(attestation_validation_fixture,
                                   attestation_slot, config):
    (crystallized_state, active_state, attestation, block,
     parent_block) = attestation_validation_fixture

    attestation.slot = attestation_slot
    with pytest.raises(ValidationError):
        validate_attestation(
            crystallized_state,
            active_state,
            attestation,
            block,
            parent_block,
            config,
        )
示例#3
0
def test_validate_attestation_aggregate_sig(attestation_validation_fixture,
                                            config):
    (crystallized_state, active_state, attestation, block,
     parent_block) = attestation_validation_fixture

    attestation.aggregate_sig = [0, 0]

    with pytest.raises(ValidationError):
        validate_attestation(
            crystallized_state,
            active_state,
            attestation,
            block,
            parent_block,
            config,
        )
示例#4
0
def test_validate_attestation_valid(attestation_validation_fixture, config):
    (crystallized_state, active_state, attestation, block,
     parent_block) = attestation_validation_fixture

    assert validate_attestation(
        crystallized_state,
        active_state,
        attestation,
        block,
        parent_block,
        config,
    )
示例#5
0
def test_validate_attestation_justified(attestation_validation_fixture,
                                        config):
    (crystallized_state, active_state, original_attestation, block,
     parent_block) = attestation_validation_fixture

    # Case 1: attestation.justified_slot > crystallized_state.last_justified_slot
    attestation = copy.deepcopy(original_attestation)
    attestation.justified_slot = crystallized_state.last_justified_slot + 1
    with pytest.raises(ValidationError):
        validate_attestation(
            crystallized_state,
            active_state,
            attestation,
            block,
            parent_block,
            config,
        )

    # Case 2: justified_block_hash is not in canonical chain
    attestation = copy.deepcopy(original_attestation)
    attestation.justified_block_hash = b'\x11' * 32
    with pytest.raises(ValidationError):
        validate_attestation(
            crystallized_state,
            active_state,
            attestation,
            block,
            parent_block,
            config,
        )

    # Case 3: justified_slot doesn't match justified_block_hash
    attestation = copy.deepcopy(original_attestation)
    attestation.justified_slot = attestation.justified_slot - 1
    with pytest.raises(ValidationError):
        validate_attestation(
            crystallized_state,
            active_state,
            attestation,
            block,
            parent_block,
            config,
        )