def test_eth1_data_votes_no_consensus(spec, state):
    if spec.EPOCHS_PER_ETH1_VOTING_PERIOD > 2:
        return dump_skipping_message(
            "Skip test if config with longer `EPOCHS_PER_ETH1_VOTING_PERIOD` for saving time."
            " Minimal config suffice to cover the target-of-test.")

    voting_period_slots = spec.EPOCHS_PER_ETH1_VOTING_PERIOD * spec.SLOTS_PER_EPOCH

    pre_eth1_hash = state.eth1_data.block_hash

    offset_block = build_empty_block(spec, state, slot=voting_period_slots - 1)
    state_transition_and_sign_block(spec, state, offset_block)
    yield 'pre', state

    a = b'\xaa' * 32
    b = b'\xbb' * 32

    blocks = []

    for i in range(0, voting_period_slots):
        block = build_empty_block_for_next_slot(spec, state)
        # wait for precisely 50% for A, then start voting B for other 50%
        block.body.eth1_data.block_hash = b if i * 2 >= voting_period_slots else a
        signed_block = state_transition_and_sign_block(spec, state, block)
        blocks.append(signed_block)

    assert len(state.eth1_data_votes) == voting_period_slots
    assert state.eth1_data.block_hash == pre_eth1_hash

    yield 'blocks', blocks
    yield 'post', state
示例#2
0
def test_duplicate_attester_slashing(spec, state):
    if spec.MAX_ATTESTER_SLASHINGS < 2:
        return dump_skipping_message(
            "Skip test if config cannot handle multiple AttesterSlashings per block"
        )

    attester_slashing = get_valid_attester_slashing(spec,
                                                    state,
                                                    signed_1=True,
                                                    signed_2=True)
    attester_slashings = [attester_slashing, attester_slashing.copy()]
    slashed_indices = get_indexed_attestation_participants(
        spec, attester_slashing.attestation_1)

    assert not any(state.validators[i].slashed for i in slashed_indices)

    yield 'pre', state

    #
    # Add to state via block transition
    #
    block = build_empty_block_for_next_slot(spec, state)
    block.body.attester_slashings = attester_slashings

    signed_block = state_transition_and_sign_block(spec,
                                                   state,
                                                   block,
                                                   expect_fail=True)

    yield 'blocks', [signed_block]
    yield 'post', None
示例#3
0
def test_multiple_attester_slashings_partial_overlap(spec, state):
    if spec.MAX_ATTESTER_SLASHINGS < 2:
        return dump_skipping_message(
            "Skip test if config cannot handle multiple AttesterSlashings per block"
        )

    # copy for later balance lookups.
    pre_state = state.copy()

    full_indices = spec.get_active_validator_indices(
        state, spec.get_current_epoch(state))[:8]
    one_third_length = len(full_indices) // 3

    attester_slashing_1 = get_valid_attester_slashing_by_indices(
        spec,
        state,
        full_indices[:one_third_length * 2],
        signed_1=True,
        signed_2=True,
    )
    attester_slashing_2 = get_valid_attester_slashing_by_indices(
        spec,
        state,
        full_indices[one_third_length:],
        signed_1=True,
        signed_2=True,
    )
    attester_slashings = [attester_slashing_1, attester_slashing_2]

    assert not any(state.validators[i].slashed for i in full_indices)

    yield 'pre', state

    #
    # Add to state via block transition
    #
    block = build_empty_block_for_next_slot(spec, state)
    block.body.attester_slashings = attester_slashings

    signed_block = state_transition_and_sign_block(spec, state, block)

    yield 'blocks', [signed_block]
    yield 'post', state

    check_attester_slashing_effect(spec, pre_state, state, full_indices)
示例#4
0
def test_empty_epoch_transition_not_finalizing(spec, state):
    if spec.SLOTS_PER_EPOCH > 8:
        return dump_skipping_message("Skip mainnet config for saving time."
                                     " Minimal config suffice to cover the target-of-test.")

    # copy for later balance lookups.
    pre_balances = list(state.balances)
    yield 'pre', state

    spec.process_slots(state, state.slot + (spec.SLOTS_PER_EPOCH * 5))
    block = build_empty_block_for_next_slot(spec, state)
    signed_block = state_transition_and_sign_block(spec, state, block)

    yield 'blocks', [signed_block]
    yield 'post', state

    assert state.slot == block.slot
    assert state.finalized_checkpoint.epoch < spec.get_current_epoch(state) - 4
    for index in range(len(state.validators)):
        assert state.balances[index] < pre_balances[index]