def test_all_valid(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_parent = prepare_empty_pow_block(spec) pow_block_parent.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256( 1) pow_block = prepare_empty_pow_block(spec) pow_block.parent_hash = pow_block_parent.block_hash pow_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY pow_blocks = [pow_block, pow_block_parent] 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, merge_block=True) # valid assert spec.get_head(store) == signed_block.message.hash_tree_root() yield from with_pow_block_patch(spec, pow_blocks, run_func) yield 'steps', test_steps
def test_valid_terminal_pow_block_fail_just_after_terminal(spec, state): parent_block = prepare_empty_pow_block(spec) parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY block = prepare_empty_pow_block(spec) block.parent_hash = parent_block.block_hash block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY + uint256(1) assert not spec.is_valid_terminal_pow_block(block, parent_block)
def test_valid_terminal_pow_block_success_valid(spec, state): parent_block = prepare_empty_pow_block(spec) parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256( 1) block = prepare_empty_pow_block(spec) block.parent_hash = parent_block.block_hash block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY assert spec.is_valid_terminal_pow_block(block, parent_block)
def test_validate_transition_execution_payload_success(spec, state): parent_block = prepare_empty_pow_block(spec) parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256( 1) block = prepare_empty_pow_block(spec) block.parent_hash = parent_block.block_hash block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY payload = spec.ExecutionPayload() payload.parent_hash = block.block_hash run_validate_transition_execution_payload(spec, block, parent_block, payload)
def test_validate_transition_execution_payload_fail_after_terminal( spec, state): parent_block = prepare_empty_pow_block(spec) parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY block = prepare_empty_pow_block(spec) block.parent_hash = parent_block.block_hash block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY + 1 payload = spec.ExecutionPayload() payload.parent_hash = block.block_hash run_validate_transition_execution_payload(spec, block, parent_block, payload, valid=False)