Beispiel #1
0
def setup_testchain(eth_client: EthClient, free_port_generator: Iterator[Port],
                    base_datadir: str,
                    base_logdir: str) -> Iterator[Dict[str, Any]]:

    ensure_executable(eth_client.value)

    rpc_port = next(free_port_generator)
    p2p_port = next(free_port_generator)

    eth_rpc_endpoint = URI(f"http://127.0.0.1:{rpc_port}")
    web3 = Web3(HTTPProvider(endpoint_uri=eth_rpc_endpoint))
    web3.middleware_onion.inject(make_sane_poa_middleware, layer=0)

    eth_nodes = [
        EthNodeDescription(
            private_key=TEST_PRIVKEY,
            rpc_port=rpc_port,
            p2p_port=p2p_port,
            miner=True,
            extra_config={},
            blockchain_type=eth_client.value,
        )
    ]

    random_marker = remove_0x_prefix(HexStr(hex(random.getrandbits(100))))
    genesis_description = GenesisDescription(
        prefunded_accounts=[
            AccountDescription(TEST_ACCOUNT_ADDRESS, DEFAULT_BALANCE)
        ],
        random_marker=random_marker,
        chain_id=CHAINNAME_TO_ID["smoketest"],
    )

    datadir = eth_node_to_datadir(privatekey_to_address(TEST_PRIVKEY),
                                  base_datadir)
    if eth_client is EthClient.GETH:
        keystore = geth_keystore(datadir)
    elif eth_client is EthClient.PARITY:
        keystore = parity_keystore(datadir)

    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 as node_executors:
        yield dict(
            eth_client=eth_client,
            base_datadir=base_datadir,
            eth_rpc_endpoint=eth_rpc_endpoint,
            keystore=keystore,
            node_executors=node_executors,
            web3=web3,
        )
Beispiel #2
0
def setup_testchain(
        eth_client: EthClient, print_step: Callable,
        free_port_generator: Iterator[int]) -> ContextManager[Dict[str, Any]]:
    print_step("Starting Ethereum node")

    ensure_executable(eth_client.value)

    rpc_port = next(free_port_generator)
    p2p_port = next(free_port_generator)
    base_datadir = os.environ["RST_DATADIR"]

    eth_rpc_endpoint = f"http://127.0.0.1:{rpc_port}"
    web3 = Web3(HTTPProvider(endpoint_uri=eth_rpc_endpoint))
    web3.middleware_stack.inject(geth_poa_middleware, layer=0)

    eth_nodes = [
        EthNodeDescription(
            private_key=TEST_PRIVKEY,
            rpc_port=rpc_port,
            p2p_port=p2p_port,
            miner=True,
            extra_config={},
            blockchain_type=eth_client.value,
        )
    ]

    random_marker = remove_0x_prefix(hex(random.getrandbits(100)))
    genesis_description = GenesisDescription(
        prefunded_accounts=[TEST_ACCOUNT_ADDRESS, TEST_PARTNER_ADDRESS],
        random_marker=random_marker,
        chain_id=NETWORKNAME_TO_ID["smoketest"],
    )

    nodekeyhex = remove_0x_prefix(encode_hex(TEST_PRIVKEY))
    datadir = eth_node_to_datadir(nodekeyhex, base_datadir)
    if eth_client is EthClient.GETH:
        keystore = geth_keystore(datadir)
    elif eth_client is EthClient.PARITY:
        keystore = parity_keystore(datadir)

    eth_node_runner = run_private_blockchain(
        web3=web3,
        eth_nodes=eth_nodes,
        base_datadir=base_datadir,
        log_dir=os.path.join(base_datadir, "logs"),
        verbosity="info",
        genesis_description=genesis_description,
    )
    with eth_node_runner as node_executors:
        yield dict(
            eth_client=eth_client,
            base_datadir=base_datadir,
            eth_rpc_endpoint=eth_rpc_endpoint,
            keystore=keystore,
            node_executors=node_executors,
            web3=web3,
        )