Example #1
0
def test_block_lookup_failed(spec, state):
    test_steps = []
    # Initialization
    state = build_state_with_incomplete_transition(spec, state)
    store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state)
    yield 'anchor_state', state
    yield 'anchor_block', anchor_block
    current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time
    on_tick_and_append_step(spec, store, current_time, test_steps)
    assert store.time == current_time

    pow_block = prepare_empty_pow_block(spec)
    pow_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(
        1)
    pow_blocks = [pow_block]
    for pb in pow_blocks:
        yield from add_pow_block(spec, store, pb, test_steps)

    def run_func():
        block = build_empty_block_for_next_slot(spec, state)
        block.body.execution_payload.parent_hash = pow_block.block_hash
        signed_block = state_transition_and_sign_block(spec, state, block)
        yield from tick_and_add_block(spec,
                                      store,
                                      signed_block,
                                      test_steps,
                                      valid=False,
                                      merge_block=True,
                                      block_not_found=True)

    yield from with_pow_block_patch(spec, pow_blocks, run_func)
    yield 'steps', test_steps
def test_success_first_payload(spec, state):
    # pre-state
    state = build_state_with_incomplete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)

    yield from run_execution_payload_processing(spec, state, execution_payload)
Example #3
0
def test_gaslimit_max_first_payload(spec, state):
    # pre-state
    state = build_state_with_incomplete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_limit = uint64(2**64 - 1)

    yield from run_execution_payload_processing(spec, state, execution_payload)
Example #4
0
def test_bad_timestamp_first_payload(spec, state):
    # pre-state
    state = build_state_with_incomplete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.timestamp = execution_payload.timestamp + 1

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
Example #5
0
def test_bad_random_first_payload(spec, state):
    # pre-state
    state = build_state_with_incomplete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.random = b'\x42' * 32

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
Example #6
0
def test_bad_execution_first_payload(spec, state):
    # completely valid payload, but execution itself fails (e.g. block exceeds gas limit)

    # pre-state
    state = build_state_with_incomplete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False)
def test_non_empty_extra_data_first_payload(spec, state):
    # pre-state
    state = build_state_with_incomplete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.extra_data = b'\x45' * 12

    yield from run_execution_payload_processing(spec, state, execution_payload)

    assert state.latest_execution_payload_header.extra_data == execution_payload.extra_data
Example #8
0
def test_is_merge_block_and_is_execution_enabled(spec, state):
    for result in expected_results:
        (with_complete_transition, with_execution_payload, is_merge_block,
         is_execution_enabled) = result
        if with_complete_transition:
            state = build_state_with_complete_transition(spec, state)
        else:
            state = build_state_with_incomplete_transition(spec, state)

        body = spec.BeaconBlockBody()
        if with_execution_payload:
            body.execution_payload = build_empty_execution_payload(spec, state)

        assert spec.is_merge_block(state, body) == is_merge_block
        assert spec.is_execution_enabled(state, body) == is_execution_enabled
Example #9
0
def test_fail_merge_complete(spec, state):
    state = build_state_with_incomplete_transition(spec, state)
    assert not spec.is_merge_transition_complete(state)