コード例 #1
0
def test_process_justification_and_finalization(
    genesis_state,
    current_epoch,
    current_epoch_justifiable,
    previous_epoch_justifiable,
    previous_justified_epoch,
    current_justified_epoch,
    justification_bits,
    finalized_epoch,
    justified_epoch_after,
    justification_bits_after,
    finalized_epoch_after,
    config,
):
    justification_bits = _convert_to_bitfield(justification_bits)
    justification_bits_after = _convert_to_bitfield(justification_bits_after)
    previous_epoch = max(current_epoch - 1, 0)
    slot = (current_epoch + 1) * config.SLOTS_PER_EPOCH - 1

    state = genesis_state.mset(
        "slot",
        slot,
        "previous_justified_checkpoint",
        Checkpoint.create(epoch=previous_justified_epoch),
        "current_justified_checkpoint",
        Checkpoint.create(epoch=current_justified_epoch),
        "justification_bits",
        justification_bits,
        "finalized_checkpoint",
        Checkpoint.create(epoch=finalized_epoch),
        "block_roots",
        tuple(
            i.to_bytes(32, "little")
            for i in range(config.SLOTS_PER_HISTORICAL_ROOT)),
    )

    if previous_epoch_justifiable:
        attestations = mk_all_pending_attestations_with_full_participation_in_epoch(
            state, previous_epoch, config)
        state = state.set("previous_epoch_attestations", attestations)

    if current_epoch_justifiable:
        attestations = mk_all_pending_attestations_with_full_participation_in_epoch(
            state, current_epoch, config)
        state = state.set("current_epoch_attestations", attestations)

    post_state = process_justification_and_finalization(state, config)

    assert (post_state.previous_justified_checkpoint.epoch ==
            state.current_justified_checkpoint.epoch)
    assert post_state.current_justified_checkpoint.epoch == justified_epoch_after
    assert post_state.justification_bits == justification_bits_after
    assert post_state.finalized_checkpoint.epoch == finalized_epoch_after
コード例 #2
0
def test_process_justification_and_finalization(
        genesis_state, current_epoch, current_epoch_justifiable,
        previous_epoch_justifiable, previous_justified_epoch,
        current_justified_epoch, justification_bitfield, finalized_epoch,
        justified_epoch_after, justification_bitfield_after,
        finalized_epoch_after, config):
    previous_epoch = max(current_epoch - 1, 0)
    slot = (current_epoch + 1) * config.SLOTS_PER_EPOCH - 1

    state = genesis_state.copy(
        slot=slot,
        previous_justified_epoch=previous_justified_epoch,
        current_justified_epoch=current_justified_epoch,
        justification_bitfield=justification_bitfield,
        finalized_epoch=finalized_epoch,
        block_roots=tuple(
            i.to_bytes(32, "little")
            for i in range(config.SLOTS_PER_HISTORICAL_ROOT)),
    )

    if previous_epoch_justifiable:
        attestations = mk_all_pending_attestations_with_full_participation_in_epoch(
            state,
            previous_epoch,
            config,
        )
        state = state.copy(previous_epoch_attestations=attestations, )

    if current_epoch_justifiable:
        attestations = mk_all_pending_attestations_with_full_participation_in_epoch(
            state,
            current_epoch,
            config,
        )
        state = state.copy(current_epoch_attestations=attestations, )

    post_state = process_justification_and_finalization(state, config)

    assert post_state.previous_justified_epoch == state.current_justified_epoch
    assert post_state.current_justified_epoch == justified_epoch_after
    assert post_state.justification_bitfield == justification_bitfield_after
    assert post_state.finalized_epoch == finalized_epoch_after
コード例 #3
0
def test_justification_without_mock(genesis_state, slots_per_historical_root,
                                    config):

    state = genesis_state
    state = process_justification_and_finalization(state, config)
    assert state.justification_bits == (False, ) * JUSTIFICATION_BITS_LENGTH
コード例 #4
0
def test_justification_without_mock(genesis_state, slots_per_historical_root,
                                    config):

    state = genesis_state
    state = process_justification_and_finalization(state, config)
    assert state.justification_bitfield == 0b0