Example #1
0
    def __init__(self, base_db: BaseDB) -> None:
        if not self.vm_configuration:
            raise ValueError(
                "The Chain class cannot be instantiated with an empty `vm_configuration`"
            )
        else:
            validate_vm_configuration(self.vm_configuration)

        self.chaindb = self.get_chaindb_class()(base_db)
        self.headerdb = HeaderDB(base_db)
        if self.gas_estimator is None:
            self.gas_estimator = get_gas_estimator()  # type: ignore
Example #2
0
    def __init__(self, base_db: AtomicDatabaseAPI) -> None:
        if not self.vm_configuration:
            raise ValueError(
                "The Chain class cannot be instantiated with an empty `vm_configuration`"
            )
        else:
            validate_vm_configuration(self.vm_configuration)

        self.chaindb = self.get_chaindb_class()(base_db)
        self.consensus_context = self.consensus_context_class(self.chaindb.db)
        self.headerdb = HeaderDB(base_db)
        if self.gas_estimator is None:
            self.gas_estimator = get_gas_estimator()
Example #3
0
def fork_at(vm_class: Type[VirtualMachineAPI], at_block: Union[int,
                                                               BlockNumber],
            chain_class: Type[ChainAPI]) -> Type[ChainAPI]:
    """
    Adds the ``vm_class`` to the chain's ``vm_configuration``.

    .. code-block:: python

        from eth.chains.base import MiningChain
        from eth.tools.builder.chain import build, fork_at

        FrontierOnlyChain = build(MiningChain, fork_at(FrontierVM, 0))

        # these two classes are functionally equivalent.
        class FrontierOnlyChain(MiningChain):
            vm_configuration = (
                (0, FrontierVM),
            )

    .. note:: This function is curriable.

    The following pre-curried versions of this function are available as well,
    one for each mainnet fork.

    * :func:`~eth.tools.builder.chain.frontier_at`
    * :func:`~eth.tools.builder.chain.homestead_at`
    * :func:`~eth.tools.builder.chain.tangerine_whistle_at`
    * :func:`~eth.tools.builder.chain.spurious_dragon_at`
    * :func:`~eth.tools.builder.chain.byzantium_at`
    * :func:`~eth.tools.builder.chain.constantinople_at`
    * :func:`~eth.tools.builder.chain.petersburg_at`
    * :func:`~eth.tools.builder.chain.istanbul_at`
    * :func:`~eth.tools.builder.chain.muir_glacier_at`
    * :func:`~eth.tools.builder.chain.berlin_at`
    * :func:`~eth.tools.builder.chain.london_at`
    * :func:`~eth.tools.builder.chain.arrow_glacier_at`
    * :func:`~eth.tools.builder.chain.gray_glacier_at`
    * :func:`~eth.tools.builder.chain.latest_mainnet_at` - whatever the latest mainnet VM is
    """
    if chain_class.vm_configuration is not None:
        base_configuration = chain_class.vm_configuration
    else:
        base_configuration = ()

    vm_configuration = base_configuration + (
        (BlockNumber(at_block), vm_class), )
    validate_vm_configuration(vm_configuration)
    return chain_class.configure(vm_configuration=vm_configuration)
Example #4
0
def fork_at(vm_class: Type[BaseVM], at_block: int,
            chain_class: Type[BaseChain]) -> Type[BaseChain]:
    """
    Adds the ``vm_class`` to the chain's ``vm_configuration``.

    .. code-block:: python

        from eth.chains.base import MiningChain
        from eth.tools.builder.chain import build, fork_at

        FrontierOnlyChain = build(MiningChain, fork_at(FrontierVM, 0))

        # these two classes are functionally equivalent.
        class FrontierOnlyChain(MiningChain):
            vm_configuration = (
                (0, FrontierVM),
            )

    .. note:: This function is curriable.

    The following pre-curried versions of this function are available as well,
    one for each mainnet fork.

    * :func:`~eth.tools.builder.chain.frontier_at`
    * :func:`~eth.tools.builder.chain.homestead_at`
    * :func:`~eth.tools.builder.chain.tangerine_whistle_at`
    * :func:`~eth.tools.builder.chain.spurious_dragon_at`
    * :func:`~eth.tools.builder.chain.byzantium_at`
    * :func:`~eth.tools.builder.chain.constantinople_at`
    """
    if chain_class.vm_configuration is not None:
        base_configuration = chain_class.vm_configuration
    else:
        base_configuration = tuple()

    vm_configuration = base_configuration + ((at_block, vm_class), )
    validate_vm_configuration(vm_configuration)
    return chain_class.configure(vm_configuration=vm_configuration)
Example #5
0
def test_validate_vm_configuration_bad_configs(value):
    with pytest.raises(ValidationError):
        validate_vm_configuration(value)