Exemplo n.º 1
0
def main():
    tmpdir = tempfile.mkdtemp()

    geth_nodes = []
    for i in range(NUM_GETH_NODES):
        is_miner = i == 0
        node_key = sha3(f'node:{i}'.encode())
        p2p_port = START_PORT + i
        rpc_port = START_RPCPORT + i

        description = GethNodeDescription(
            node_key,
            rpc_port,
            p2p_port,
            is_miner,
        )

        geth_nodes.append(description)

    rpc_endpoint = f'http://127.0.0.1:{START_RPCPORT}'
    web3 = Web3(HTTPProvider(rpc_endpoint))

    verbosity = 0
    random_marker = remove_0x_prefix(hex(random.getrandbits(100)))
    geth_processes = geth_run_private_blockchain(  # NOQA
        web3,
        DEFAULT_ACCOUNTS,
        geth_nodes,
        tmpdir,
        RAIDENTEST_CHAINID,
        verbosity,
        random_marker,
    )

    from IPython import embed
    embed()
Exemplo n.º 2
0
def main():
    tmpdir = tempfile.mkdtemp()

    geth_nodes = []
    for i in range(NUM_GETH_NODES):
        is_miner = i == 0
        node_key = sha3(f'node:{i}'.encode())
        p2p_port = START_PORT + i
        rpc_port = START_RPCPORT + i

        description = GethNodeDescription(
            node_key,
            rpc_port,
            p2p_port,
            is_miner,
        )

        geth_nodes.append(description)

    rpc_endpoint = f'http://127.0.0.1:{START_RPCPORT}'
    web3 = Web3(HTTPProvider(rpc_endpoint))

    verbosity = 0
    random_marker = remove_0x_prefix(hex(random.getrandbits(100)))
    geth_processes = geth_run_private_blockchain(  # NOQA
        web3,
        DEFAULT_ACCOUNTS,
        geth_nodes,
        tmpdir,
        NETWORKNAME_TO_ID['smoketest'],
        verbosity,
        random_marker,
    )

    from IPython import embed
    embed()
Exemplo n.º 3
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}')
Exemplo n.º 4
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}')
Exemplo n.º 5
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}')