Ejemplo n.º 1
0
def test_single_crosslink_update_from_previous_epoch(spec, state):
    next_epoch(spec, state)

    attestation = get_valid_attestation(spec, state, signed=True)

    fill_aggregate_attestation(spec, state, attestation)
    add_attestation_to_state(spec, state, attestation,
                             state.slot + spec.SLOTS_PER_EPOCH)

    assert len(state.previous_epoch_attestations) == 1

    shard = attestation.data.crosslink.shard
    pre_crosslink = deepcopy(state.current_crosslinks[shard])

    crosslink_deltas = spec.get_crosslink_deltas(state)

    yield from run_process_crosslinks(spec, state)

    assert state.previous_crosslinks[shard] != state.current_crosslinks[shard]
    assert pre_crosslink != state.current_crosslinks[shard]

    # ensure rewarded
    for index in spec.get_crosslink_committee(
            state, attestation.data.target_epoch,
            attestation.data.crosslink.shard):
        assert crosslink_deltas[0][index] > 0
        assert crosslink_deltas[1][index] == 0
Ejemplo n.º 2
0
def test_double_late_crosslink(spec, state):
    if spec.get_epoch_committee_count(
            state, spec.get_current_epoch(state)) < spec.SHARD_COUNT:
        print(
            "warning: ignoring test, test-assumptions are incompatible with configuration"
        )
        return

    next_epoch(spec, state)
    state.slot += 4

    attestation_1 = get_valid_attestation(spec, state, signed=True)
    fill_aggregate_attestation(spec, state, attestation_1)

    # add attestation_1 to next epoch
    next_epoch(spec, state)
    add_attestation_to_state(spec, state, attestation_1, state.slot + 1)

    for _ in range(spec.SLOTS_PER_EPOCH):
        attestation_2 = get_valid_attestation(spec, state)
        if attestation_2.data.crosslink.shard == attestation_1.data.crosslink.shard:
            sign_attestation(spec, state, attestation_2)
            break
        next_slot(spec, state)
    apply_empty_block(spec, state)

    fill_aggregate_attestation(spec, state, attestation_2)

    # add attestation_2 in the next epoch after attestation_1 has
    # already updated the relevant crosslink
    next_epoch(spec, state)
    add_attestation_to_state(spec, state, attestation_2, state.slot + 1)

    assert len(state.previous_epoch_attestations) == 1
    assert len(state.current_epoch_attestations) == 0

    crosslink_deltas = spec.get_crosslink_deltas(state)

    yield from run_process_crosslinks(spec, state)

    shard = attestation_2.data.crosslink.shard

    # ensure that the current crosslinks were not updated by the second attestation
    assert state.previous_crosslinks[shard] == state.current_crosslinks[shard]
    # ensure no reward, only penalties for the failed crosslink
    for index in spec.get_crosslink_committee(
            state, attestation_2.data.target_epoch,
            attestation_2.data.crosslink.shard):
        assert crosslink_deltas[0][index] == 0
        assert crosslink_deltas[1][index] > 0
Ejemplo n.º 3
0
def test_single_crosslink_update_from_current_epoch(spec, state):
    next_epoch(spec, state)

    attestation = get_valid_attestation(spec, state, signed=True)

    fill_aggregate_attestation(spec, state, attestation)
    add_attestation_to_state(spec, state, attestation,
                             state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)

    assert len(state.current_epoch_attestations) == 1

    shard = attestation.data.crosslink.shard
    pre_crosslink = deepcopy(state.current_crosslinks[shard])

    yield from run_process_crosslinks(spec, state)

    assert state.previous_crosslinks[shard] != state.current_crosslinks[shard]
    assert pre_crosslink != state.current_crosslinks[shard]