def test_odd_bits(remote_connection):
    if not isinstance(remote_connection._client._message_serializer,
                      GraphSONSerializersV2d0):
        g = Graph().traversal().withRemote(remote_connection)
        char_lower = str.__new__(SingleChar, chr(78))
        resp = g.addV('test_vertex').property('char_lower',
                                              char_lower).toList()
        vid = resp[0].id
        try:
            v = g.V(vid).values('char_lower').toList()[0]
            assert v == char_lower
        finally:
            g.V(vid).drop().iterate()

        char_upper = str.__new__(SingleChar, chr(57344))
        resp = g.addV('test_vertex').property('char_upper',
                                              char_upper).toList()
        vid = resp[0].id
        try:
            v = g.V(vid).values('char_upper').toList()[0]
            assert v == char_upper
        finally:
            g.V(vid).drop().iterate()

        dur = datetime.timedelta(seconds=1000, microseconds=1000)
        resp = g.addV('test_vertex').property('dur', dur).toList()
        vid = resp[0].id
        try:
            v = g.V(vid).values('dur').toList()[0]
            assert v == dur
        finally:
            g.V(vid).drop().iterate()
Beispiel #2
0
def parall(blockNumbers):
    blockNumbers = blockNumbers.tolist()
    g = Graph().traversal().withRemote(
        DriverRemoteConnection(gremlin_connection, traversal_source))
    for blockNumber in blockNumbers:
        # blockE = web3.eth.getBlock(blockNumber, True)
        block = web3._requestManager.request_blocking(
            "trace_block", [web3.fromDecimal(blockNumber)])

        count = len(block)
        if count > 0:
            blockEx = g.V().hasLabel("block").has('number',
                                                  blockNumber).toList()

            if len(blockEx) == 0:
                blockV = g.addV('block').property('number', blockNumber).next()
            else:
                blockV = blockEx[0]

            # Add transactions
            subtraces = 0
            prevTx = None
            for index in range(len(block)):
                tx = block[index]

                if 'error' in tx:
                    error = True
                else:
                    error = False

                # Internal transaction
                if subtraces > 0:
                    subtraces -= 1
                    temp = g.addV('intx').property(
                        'hash',
                        tx['transactionHash']).property('type', tx['type'])
                    if error:
                        temp.property('error', True)
                    edge = g.V().hasId(prevTx).addE('internal').to(
                        temp).toList()

                else:
                    temp = g.addV('tx').property(
                        'hash',
                        tx['transactionHash']).property('type', tx['type'])
                    if error:
                        temp.property('error', tx['error'])
                    edge = g.V().hasId(
                        blockV.id).addE('include').to(temp).toList()

                decide_on_action(g, tx, edge[0].inV.id, error)

                if tx['subtraces'] > 0:
                    subtraces = tx['subtraces']
                    prevTx = edge[0].inV.id
Beispiel #3
0
 def test_uuid(self, remote_connection):
     g = Graph().traversal().withRemote(remote_connection)
     uid = uuid.UUID("41d2e28a-20a4-4ab0-b379-d810dede3786")
     resp = g.addV('test_vertex').property('uuid', uid).toList()
     vid = resp[0].id
     try:
         uid_prop = g.V(vid).properties('uuid').toList()[0]
         assert isinstance(uid_prop.value, uuid.UUID)
         assert uid_prop.value == uid
     finally:
         g.V(vid).drop().iterate()
Beispiel #4
0
 def test_datetime(self, remote_connection):
     g = Graph().traversal().withRemote(remote_connection)
     dt = datetime.datetime.fromtimestamp(1481750076295 / 1000)
     resp = g.addV('test_vertex').property('dt', dt).toList()
     vid = resp[0].id
     try:
         dt_prop = g.V(vid).properties('dt').toList()[0]
         assert isinstance(dt_prop.value, datetime.datetime)
         assert dt_prop.value == dt
     finally:
         g.V(vid).drop().iterate()
 def test_uuid(self, remote_connection_v2):
     g = Graph().traversal().withRemote(remote_connection_v2)
     uid = uuid.UUID("41d2e28a-20a4-4ab0-b379-d810dede3786")
     resp = g.addV('test_vertex').property('uuid', uid).toList()
     vid = resp[0].id
     try:
         uid_prop = g.V(vid).properties('uuid').toList()[0]
         assert isinstance(uid_prop.value, uuid.UUID)
         assert uid_prop.value == uid
     finally:
         g.V(vid).drop().iterate()
 def test_datetime(self, remote_connection_v2):
     g = Graph().traversal().withRemote(remote_connection_v2)
     dt = datetime.datetime.fromtimestamp(1481750076295 / 1000)
     resp = g.addV('test_vertex').property('dt', dt).toList()
     vid = resp[0].id
     try:
         dt_prop = g.V(vid).properties('dt').toList()[0]
         assert isinstance(dt_prop.value, datetime.datetime)
         assert dt_prop.value == dt
     finally:
         g.V(vid).drop().iterate()
Beispiel #7
0
 def test_timestamp(self, remote_connection):
     g = Graph().traversal().withRemote(remote_connection)
     ts = timestamp(1481750076295 / 1000)
     resp = g.addV('test_vertex').property('ts', ts)
     resp = resp.toList()
     vid = resp[0].id
     try:
         ts_prop = g.V(vid).properties('ts').toList()[0]
         assert isinstance(ts_prop.value, timestamp)
         assert ts_prop.value == ts
     finally:
         g.V(vid).drop().iterate()
 def test_timestamp(self, remote_connection_v2):
     g = Graph().traversal().withRemote(remote_connection_v2)
     ts = timestamp(1481750076295 / 1000)
     resp = g.addV('test_vertex').property('ts', ts)
     resp = resp.toList()
     vid = resp[0].id
     try:
         ts_prop = g.V(vid).properties('ts').toList()[0]
         assert isinstance(ts_prop.value, timestamp)
         assert ts_prop.value == ts
     finally:
         g.V(vid).drop().iterate()
Beispiel #9
0
 def test_datetime(self, remote_connection_graphsonV2):
     g = Graph().traversal().withRemote(remote_connection_graphsonV2)
     dt = datetime.datetime.utcfromtimestamp(1481750076295 / 1000)
     resp = g.addV('test_vertex').property('dt', dt).toList()
     vid = resp[0].id
     try:
         dt_prop = g.V(vid).properties('dt').toList()[0]
         assert isinstance(dt_prop.value, datetime.datetime)
         assert dt_prop.value == dt
     except OSError:
         assert False, "Error making request"
     finally:
         g.V(vid).drop().iterate()
Beispiel #10
0
    def upload(self, json_graph, source_name, verbose=True, drop_graph=True):
        def printX(obj=""):
            if clargs.verbose:
                print(obj)

        if isinstance(json_graph, str):
            input_graph = nx.readwrite.json_graph.node_link_graph(
                json.loads(json_graph))
        elif isinstance(json_graph, io.TextIOBase):
            input_graph = nx.readwrite.json_graph.node_link_graph(
                json.load(json_graph))

        printX("output Gremlin server: %s, %s" %
               (clargs.output_server, clargs.output_source))
        output_graph = Graph().traversal().withRemote(
            DriverRemoteConnection(self.server_url, self.traversal_source))

        if drop_graph:
            printX("Clearing ouput graph...")
            output_graph.V().drop().toList()
            output_graph.E().drop().toList()
            printX("done")

        for id, props in input_graph.nodes(data=True):
            printX("processing node: %s\nwith data: %s" % (id, props))
            new_node = output_graph.addV('node_link_node').next()
            output_graph.V(new_node).property('original_id', id).toList()
            output_graph.V(new_node).property('source_name',
                                              source_name).toList()
            for prop, value in props.items():
                output_graph.V(new_node).property(prop, value).toList()
            printX("added properties: %s" %
                   output_graph.V(new_node).properties().toList())

        for out_id, in_id, props in input_graph.edges(data=True):
            printX("processing edge: %s --> %s" % (out_id, in_id))
            out_node = output_graph.V().where(
                __.has('original_id', out_id).has('source_name',
                                                  source_name)).next()
            in_node = output_graph.V().where(
                __.has('original_id', in_id).has('source_name',
                                                 source_name)).next()
            new_edge = output_graph.addE('node_link_connection').from_(
                out_node).to(in_node).next()
            for prop, value in props.items():
                output_graph.E(new_edge).property(prop, value).toList()
            printX("added properties: %s" %
                   output_graph.E(new_edge).properties().toList())

        printX("total nodes added: %d" % output_graph.V().count().next())
        printX("total edges added: %d" % output_graph.E().count().next())