예제 #1
0
def geth_process(geth_binary, datadir, genesis_file, geth_command_arguments):
    init_datadir_command = (
        geth_binary,
        '--datadir', str(datadir),
        'init',
        str(genesis_file),
    )
    subprocess.check_output(
        init_datadir_command,
        stdin=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    proc = subprocess.Popen(
        geth_command_arguments,
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        bufsize=1,
    )
    try:
        yield proc
    finally:
        kill_proc_gracefully(proc)
        output, errors = proc.communicate()
        print(
            "Geth Process Exited:\n"
            "stdout:{0}\n\n"
            "stderr:{1}\n\n".format(
                to_text(output),
                to_text(errors),
            )
        )
예제 #2
0
def parity_export_blocks_process(parity_binary, datadir,
                                 chain_config_file_path, parity_port):

    run_command = (
        parity_binary,
        'export',
        'blocks',
        os.path.join(datadir, 'blocks_export.rlp'),
        '--base-path',
        datadir,
        '--no-ws',
        '--no-ui',
        '--no-warp',
        '--chain',
        chain_config_file_path,
        '--rpcapi',
        'all',
        '--rpcport',
        parity_port,
        # '--author', common.COINBASE[2:],
    )
    print(' '.join(run_command))
    try:
        proc = common.get_process(run_command)
        yield proc
    finally:
        common.kill_proc_gracefully(proc)
        output, errors = proc.communicate()
        print("Parity Process Exited:\n"
              "stdout:{0}\n\n"
              "stderr:{1}\n\n".format(
                  to_text(output),
                  to_text(errors),
              ))
예제 #3
0
def test_admin_setSolc(web3, skip_if_testrpc):
    skip_if_testrpc(web3)

    try:
        solc_path = subprocess.check_output(['which', 'solc']).strip()
    except subprocess.CalledProcessError:
        pytest.skip('solc binary not found')
    solc_version = subprocess.check_output(['solc', '--version']).strip()

    actual = web3.admin.setSolc(solc_path)
    assert to_text(solc_version) in actual
    assert to_text(solc_path) in actual
예제 #4
0
def get_geth_process(geth_binary,
                     datadir,
                     genesis_file_path,
                     ipc_path,
                     port,
                     networkid,
                     skip_init=False):
    if not skip_init:
        init_datadir_command = (
            geth_binary,
            '--datadir',
            datadir,
            'init',
            genesis_file_path,
        )
        print(' '.join(init_datadir_command))
        subprocess.check_output(
            init_datadir_command,
            stdin=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )

    run_geth_command = (
        geth_binary,
        '--datadir',
        datadir,
        '--ipcpath',
        ipc_path,
        '--nodiscover',
        '--port',
        port,
        '--networkid',
        networkid,
        '--etherbase',
        COINBASE[2:],
    )
    print(' '.join(run_geth_command))
    try:
        proc = get_process(run_geth_command)
        yield proc
    finally:
        kill_proc_gracefully(proc)
        output, errors = proc.communicate()
        print("Geth Process Exited:\n"
              "stdout:{0}\n\n"
              "stderr:{1}\n\n".format(
                  to_text(output),
                  to_text(errors),
              ))
예제 #5
0
def is_encodable(_type, value):
    try:
        base, sub, arrlist = _type
    except ValueError:
        base, sub, arrlist = process_type(_type)

    if arrlist:
        if not is_list_like(value):
            return False
        if arrlist[-1] and len(value) != arrlist[-1][0]:
            return False
        sub_type = (base, sub, arrlist[:-1])
        return all(is_encodable(sub_type, sub_value) for sub_value in value)
    elif base == 'address' and is_ens_name(value):
        # ENS names can be used anywhere an address is needed
        # Web3.py will resolve the name to an address before encoding it
        return True
    elif base == 'bytes' and isinstance(value, str):
        # Hex-encoded bytes values can be used anywhere a bytes value is needed
        if is_hex(value) and len(value) % 2 == 0:
            # Require hex-encoding of full bytes (even length)
            bytes_val = to_bytes(hexstr=value)
            return eth_abi_is_encodable(_type, bytes_val)
        else:
            return False
    elif base == 'string' and isinstance(value, bytes):
        # bytes that were encoded with utf-8 can be used anywhere a string is needed
        try:
            string_val = to_text(value)
        except UnicodeDecodeError:
            return False
        else:
            return eth_abi_is_encodable(_type, string_val)
    else:
        return eth_abi_is_encodable(_type, value)
예제 #6
0
def get_process(command_list, terminates=False):

    proc = subprocess.Popen(
        command_list,
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        bufsize=1,
    )
    if terminates:
        wait_for_popen(proc, 30)
    try:
        yield proc
    finally:
        kill_proc_gracefully(proc)
        output, errors = proc.communicate()
        print("Parity Process Exited:\n"
              "stdout:{0}\n\n"
              "stderr:{1}\n\n".format(
                  to_text(output),
                  to_text(errors),
              ))
예제 #7
0
 def decode_rpc_response(self, response):
     text_response = to_text(response)
     return FriendlyJsonSerde().json_decode(text_response)