def apply_fixture_block_to_chain(
        block_fixture: Dict[str, Any],
        chain: BaseChain,
        perform_validation: bool = True
) -> Tuple[BaseBlock, BaseBlock, BaseBlock]:
    """
    :return: (premined_block, mined_block, rlp_encoded_mined_block)
    """
    # The block to import may be in a different block-class-range than the
    # chain's current one, so we use the block number specified in the
    # fixture to look up the correct block class.
    if 'blockHeader' in block_fixture:
        block_number = block_fixture['blockHeader']['number']
        block_class = chain.get_vm_class_for_block_number(
            block_number).get_block_class()
    else:
        block_class = chain.get_vm().get_block_class()

    block = rlp.decode(block_fixture['rlp'], sedes=block_class)

    mined_block, _, _ = chain.import_block(
        block, perform_validation=perform_validation)

    rlp_encoded_mined_block = rlp.encode(mined_block, sedes=block_class)

    return (block, mined_block, rlp_encoded_mined_block)
Ejemplo n.º 2
0
 def _import_blocks(chain: BaseChain) -> BaseChain:
     for block in blocks:
         chain.import_block(block)
     return chain
Ejemplo n.º 3
0
def import_block(block: BaseBlock, chain: BaseChain) -> BaseChain:
    """
    Import the provided ``block`` into the chain.
    """
    chain.import_block(block)
    return chain