Esempio n. 1
0
def blockchain_backend(
        request,
        deploy_key,
        web3,
        private_keys,
        blockchain_private_keys,
        blockchain_p2p_ports,
        blockchain_rpc_ports,
        tmpdir,
        random_marker,
):

    """ Helper to do proper cleanup. """
    geth_processes = geth_create_blockchain(
        deploy_key,
        web3,
        private_keys,
        blockchain_private_keys,
        blockchain_rpc_ports,
        blockchain_p2p_ports,
        str(tmpdir),
        request.config.option.verbose,
        random_marker,
        None,
    )
    yield geth_processes

    [x.terminate() for x in geth_processes]
    cleanup_tasks()
Esempio n. 2
0
    def _cleanup():
        for app in raiden_apps:
            app.stop()

        # Two tests in sequence could run a UDP server on the same port, a hanging
        # greenlet from the previous tests could send packet to the new server and
        # mess things up. Kill all greenlets to make sure that no left-over state
        # from a previous test interferes with a new one.
        cleanup_tasks()
Esempio n. 3
0
    def _cleanup():
        for app in raiden_apps:
            app.stop()

        # Two tests in sequence could run a UDP server on the same port, a hanging
        # greenlet from the previous tests could send packet to the new server and
        # mess things up. Kill all greenlets to make sure that no left-over state
        # from a previous test interferes with a new one.
        cleanup_tasks()
Esempio n. 4
0
def web3(
    deploy_key,
    eth_nodes_configuration,
    private_keys,
    account_genesis_eth_balance,
    random_marker,
    tmpdir,
    chain_id,
    logs_storage,
    blockchain_type,
):
    """ Starts a private chain with accounts funded. """
    # include the deploy key in the list of funded accounts
    keys_to_fund = sorted(set(private_keys + [deploy_key]))

    host = "127.0.0.1"
    rpc_port = eth_nodes_configuration[0].rpc_port
    endpoint = f"http://{host}:{rpc_port}"
    web3 = Web3(HTTPProvider(URI(endpoint)))

    accounts_to_fund = [
        AccountDescription(privatekey_to_address(key), account_genesis_eth_balance)
        for key in keys_to_fund
    ]

    # The private chain data is always discarded on the CI
    base_datadir = str(tmpdir)

    # Save the Ethereum node's log for debugging
    base_logdir = os.path.join(logs_storage, blockchain_type)

    genesis_description = GenesisDescription(
        prefunded_accounts=accounts_to_fund, chain_id=chain_id, random_marker=random_marker
    )
    eth_node_runner = run_private_blockchain(
        web3=web3,
        eth_nodes=eth_nodes_configuration,
        base_datadir=base_datadir,
        log_dir=base_logdir,
        verbosity="info",
        genesis_description=genesis_description,
    )
    with eth_node_runner:
        yield web3

    cleanup_tasks()
Esempio n. 5
0
def web3(
        blockchain_p2p_ports,
        blockchain_private_keys,
        blockchain_rpc_ports,
        blockchain_type,
        deploy_key,
        private_keys,
        random_marker,
        request,
        tmpdir,
        chain_id,
):
    """ Starts a private chain with accounts funded. """
    # include the deploy key in the list of funded accounts
    keys_to_fund = set(private_keys)
    keys_to_fund.add(deploy_key)
    keys_to_fund = sorted(keys_to_fund)

    if blockchain_type == 'geth':
        host = '0.0.0.0'
        rpc_port = blockchain_rpc_ports[0]
        endpoint = f'http://{host}:{rpc_port}'
        web3 = Web3(HTTPProvider(endpoint))

        assert len(blockchain_private_keys) == len(blockchain_rpc_ports)
        assert len(blockchain_private_keys) == len(blockchain_p2p_ports)

        geth_nodes = [
            GethNodeDescription(
                key,
                rpc,
                p2p,
                miner=(pos == 0),
            )
            for pos, (key, rpc, p2p) in enumerate(zip(
                blockchain_private_keys,
                blockchain_rpc_ports,
                blockchain_p2p_ports,
            ))
        ]

        accounts_to_fund = [
            privatekey_to_address(key)
            for key in keys_to_fund
        ]

        if _GETH_DATADIR:
            base_datadir = _GETH_DATADIR
            os.makedirs(base_datadir, exist_ok=True)
        else:
            base_datadir = str(tmpdir)

        geth_processes = geth_run_private_blockchain(
            web3=web3,
            accounts_to_fund=accounts_to_fund,
            geth_nodes=geth_nodes,
            base_datadir=base_datadir,
            chain_id=chain_id,
            verbosity=request.config.option.verbose,
            random_marker=random_marker,
        )

        yield web3

        for process in geth_processes:
            process.terminate()

        cleanup_tasks()

    else:
        raise ValueError(f'unknown blockchain_type {blockchain_type}')
Esempio n. 6
0
def web3(
    blockchain_p2p_ports,
    blockchain_private_keys,
    blockchain_rpc_ports,
    blockchain_type,
    blockchain_extra_config,
    deploy_key,
    private_keys,
    account_genesis_eth_balance,
    random_marker,
    request,
    tmpdir,
    chain_id,
    logs_storage,
):
    """ Starts a private chain with accounts funded. """
    # include the deploy key in the list of funded accounts
    keys_to_fund = set(private_keys)
    keys_to_fund.add(deploy_key)
    keys_to_fund = sorted(keys_to_fund)

    if blockchain_type not in {client.value for client in EthClient}:
        raise ValueError(f"unknown blockchain_type {blockchain_type}")

    host = "127.0.0.1"
    rpc_port = blockchain_rpc_ports[0]
    endpoint = f"http://{host}:{rpc_port}"
    web3 = Web3(HTTPProvider(endpoint))

    assert len(blockchain_private_keys) == len(blockchain_rpc_ports)
    assert len(blockchain_private_keys) == len(blockchain_p2p_ports)

    eth_nodes = [
        EthNodeDescription(
            private_key=key,
            rpc_port=rpc,
            p2p_port=p2p,
            miner=(pos == 0),
            extra_config=blockchain_extra_config,
            blockchain_type=blockchain_type,
        )
        for pos, (key, rpc, p2p) in enumerate(
            zip(blockchain_private_keys, blockchain_rpc_ports, blockchain_p2p_ports)
        )
    ]

    accounts_to_fund = [
        AccountDescription(privatekey_to_address(key), account_genesis_eth_balance)
        for key in keys_to_fund
    ]

    # The private chain data is always discarded on the CI
    base_datadir = str(tmpdir)

    # Save the Ethereum node's log for debugging
    base_logdir = os.path.join(logs_storage, blockchain_type)

    genesis_description = GenesisDescription(
        prefunded_accounts=accounts_to_fund, chain_id=chain_id, random_marker=random_marker
    )
    eth_node_runner = run_private_blockchain(
        web3=web3,
        eth_nodes=eth_nodes,
        base_datadir=base_datadir,
        log_dir=base_logdir,
        verbosity="info",
        genesis_description=genesis_description,
    )
    with eth_node_runner:
        yield web3

    cleanup_tasks()
Esempio n. 7
0
def web3(
    blockchain_p2p_ports,
    blockchain_private_keys,
    blockchain_rpc_ports,
    blockchain_type,
    deploy_key,
    private_keys,
    random_marker,
    request,
    tmpdir,
    ethereum_tester,
    chain_id,
):
    """ Starts a private chain with accounts funded. """
    # include the deploy key in the list of funded accounts
    keys_to_fund = set(private_keys)
    keys_to_fund.add(deploy_key)
    keys_to_fund = sorted(keys_to_fund)

    if blockchain_type == 'geth':
        host = '0.0.0.0'
        rpc_port = blockchain_rpc_ports[0]
        endpoint = f'http://{host}:{rpc_port}'
        web3 = Web3(HTTPProvider(endpoint))

        assert len(blockchain_private_keys) == len(blockchain_rpc_ports)
        assert len(blockchain_private_keys) == len(blockchain_p2p_ports)

        geth_nodes = [
            GethNodeDescription(
                key,
                rpc,
                p2p,
                miner=(pos == 0),
            ) for pos, (key, rpc, p2p) in enumerate(
                zip(
                    blockchain_private_keys,
                    blockchain_rpc_ports,
                    blockchain_p2p_ports,
                ))
        ]

        accounts_to_fund = [privatekey_to_address(key) for key in keys_to_fund]

        geth_processes = geth_run_private_blockchain(
            web3,
            accounts_to_fund,
            geth_nodes,
            str(tmpdir),
            chain_id,
            request.config.option.verbose,
            random_marker,
        )

        yield web3

        for process in geth_processes:
            process.terminate()

        cleanup_tasks()

    elif blockchain_type == 'tester':
        web3 = Web3(EthereumTesterProvider(ethereum_tester))
        snapshot = ethereum_tester.take_snapshot()

        fund_accounts(web3, keys_to_fund, ethereum_tester)

        miner = Miner(web3)
        miner.start()

        yield web3

        miner.stop.set()
        miner.join()
        ethereum_tester.revert_to_snapshot(snapshot)

    else:
        raise ValueError(f'unknown blockchain_type {blockchain_type}')
Esempio n. 8
0
    def _cleanup():
        for app in raiden_apps:
            app.stop()

        # kill all leftover tasklets
        cleanup_tasks()
Esempio n. 9
0
    def _cleanup():
        for process in geth_processes:
            process.terminate()

        # Then kill any remaining tasklet
        cleanup_tasks()
Esempio n. 10
0
def teardown_module(module):  # pylint: disable=unused-argument
    from raiden.tests.utils.tests import cleanup_tasks
    cleanup_tasks()
Esempio n. 11
0
    def _cleanup():
        for process in geth_processes:
            process.terminate()

        # Then kill any remaining tasklet
        cleanup_tasks()
Esempio n. 12
0
    def _cleanup():
        for app in hydrachain_apps:
            app.stop()

        cleanup_tasks()
Esempio n. 13
0
def teardown_module(module):  # pylint: disable=unused-argument
    from raiden.tests.utils.tests import cleanup_tasks
    cleanup_tasks()
Esempio n. 14
0
    def _cleanup():
        for process in geth_processes:
            process.terminate()

        cleanup_tasks()
Esempio n. 15
0
def web3(
        blockchain_p2p_ports,
        blockchain_private_keys,
        blockchain_rpc_ports,
        blockchain_type,
        deploy_key,
        private_keys,
        random_marker,
        request,
        tmpdir,
        ethereum_tester,
        chain_id,
):
    """ Starts a private chain with accounts funded. """
    # include the deploy key in the list of funded accounts
    keys_to_fund = set(private_keys)
    keys_to_fund.add(deploy_key)
    keys_to_fund = sorted(keys_to_fund)

    if blockchain_type == 'geth':
        host = '0.0.0.0'
        rpc_port = blockchain_rpc_ports[0]
        endpoint = f'http://{host}:{rpc_port}'
        web3 = Web3(HTTPProvider(endpoint))

        assert len(blockchain_private_keys) == len(blockchain_rpc_ports)
        assert len(blockchain_private_keys) == len(blockchain_p2p_ports)

        geth_nodes = [
            GethNodeDescription(
                key,
                rpc,
                p2p,
                miner=(pos == 0),
            )
            for pos, (key, rpc, p2p) in enumerate(zip(
                blockchain_private_keys,
                blockchain_rpc_ports,
                blockchain_p2p_ports,
            ))
        ]

        accounts_to_fund = [
            privatekey_to_address(key)
            for key in keys_to_fund
        ]

        geth_processes = geth_run_private_blockchain(
            web3,
            accounts_to_fund,
            geth_nodes,
            str(tmpdir),
            chain_id,
            request.config.option.verbose,
            random_marker,
        )

        yield web3

        for process in geth_processes:
            process.terminate()

        cleanup_tasks()

    elif blockchain_type == 'tester':
        web3 = Web3(EthereumTesterProvider(ethereum_tester))
        snapshot = ethereum_tester.take_snapshot()

        fund_accounts(web3, keys_to_fund, ethereum_tester)

        miner = Miner(web3)
        miner.start()

        yield web3

        miner.stop.set()
        miner.join()
        ethereum_tester.revert_to_snapshot(snapshot)

    else:
        raise ValueError(f'unknwon blockchain_type {blockchain_type}')
Esempio n. 16
0
    def _cleanup():
        for app in raiden_apps:
            app.stop()

        # kill all leftover tasklets
        cleanup_tasks()
Esempio n. 17
0
    def _cleanup():
        for app in hydrachain_apps:
            app.stop()

        cleanup_tasks()
Esempio n. 18
0
    def _cleanup():
        for process in geth_processes:
            process.terminate()

        cleanup_tasks()
Esempio n. 19
0
def web3(
    blockchain_p2p_ports,
    blockchain_private_keys,
    blockchain_rpc_ports,
    blockchain_type,
    blockchain_extra_config,
    deploy_key,
    private_keys,
    random_marker,
    request,
    tmpdir,
    chain_id,
):
    """ Starts a private chain with accounts funded. """
    # include the deploy key in the list of funded accounts
    keys_to_fund = set(private_keys)
    keys_to_fund.add(deploy_key)
    keys_to_fund = sorted(keys_to_fund)

    if blockchain_type not in {client.value for client in EthClient}:
        raise ValueError(f'unknown blockchain_type {blockchain_type}')

    host = '127.0.0.1'
    rpc_port = blockchain_rpc_ports[0]
    endpoint = f'http://{host}:{rpc_port}'
    web3 = Web3(HTTPProvider(endpoint))

    assert len(blockchain_private_keys) == len(blockchain_rpc_ports)
    assert len(blockchain_private_keys) == len(blockchain_p2p_ports)

    eth_nodes = [
        EthNodeDescription(
            private_key=key,
            rpc_port=rpc,
            p2p_port=p2p,
            miner=(pos == 0),
            extra_config=blockchain_extra_config,
            blockchain_type=blockchain_type,
        ) for pos, (key, rpc, p2p) in enumerate(
            zip(
                blockchain_private_keys,
                blockchain_rpc_ports,
                blockchain_p2p_ports,
            ), )
    ]

    accounts_to_fund = [privatekey_to_address(key) for key in keys_to_fund]

    base_datadir = str(tmpdir)

    if _ETH_LOGDIR:
        base_logdir = os.path.join(_ETH_LOGDIR, blockchain_type,
                                   request.node.name)
    else:
        base_logdir = os.path.join(base_datadir, 'logs')

    genesis_description = GenesisDescription(
        prefunded_accounts=accounts_to_fund,
        chain_id=chain_id,
        random_marker=random_marker,
    )
    eth_node_runner = run_private_blockchain(
        web3=web3,
        eth_nodes=eth_nodes,
        base_datadir=base_datadir,
        log_dir=base_logdir,
        verbosity='info',
        genesis_description=genesis_description,
    )
    with eth_node_runner:
        yield web3

    cleanup_tasks()