Exemplo n.º 1
0
def test_timeout():
    def f():
        return 3

    def g():
        gevent.sleep(5.0)
        return 4

    def h():
        return 5

    with pytest.raises(TimeoutException):
        joinall([f, g, h], timeout=0.01)
Exemplo n.º 2
0
    def get_unw_eth_events(
        self,
        event_name: str,
        user_address: str = None,
        from_block: int = 0,
        timeout: float = None,
    ) -> List[BlockchainEvent]:
        logger.debug(
            "get_unw_eth_events: event_name=%s user_address=%s from_block=%s",
            event_name,
            user_address,
            from_block,
        )
        if user_address is None:
            queries = [
                functools.partial(self.get_events,
                                  event_name,
                                  from_block=from_block)
            ]
            events = concurrency_utils.joinall(queries, timeout=timeout)
        else:
            filter1 = {from_to_types[event_name][0]: user_address}
            filter2 = {from_to_types[event_name][1]: user_address}

            queries = [
                functools.partial(self.get_events, event_name, filter1,
                                  from_block)
            ]
            if event_name == TransferEventType:
                queries.append(
                    functools.partial(self.get_events, event_name, filter2,
                                      from_block))
            results = concurrency_utils.joinall(queries, timeout=timeout)

            events = list(itertools.chain.from_iterable(results))

            for event in events:
                if isinstance(event, UnwEthEvent):
                    event.user = user_address
                else:
                    raise ValueError("Expected a UnwEthEvent")
        return sorted_events(events)
Exemplo n.º 3
0
 def get_all_user_exchange_events(
     self,
     user_address: str,
     type: str = None,
     from_block: int = 0,
     timeout: float = None,
 ) -> List[BlockchainEvent]:
     assert is_checksum_address(user_address)
     exchange_event_queries = self._get_exchange_event_queries(
         user_address, type, from_block)
     results = concurrency_utils.joinall(exchange_event_queries,
                                         timeout=timeout)
     return sorted_events(list(itertools.chain.from_iterable(results)))
Exemplo n.º 4
0
def test_success():
    def f():
        return 3

    def g():
        return 4

    def h():
        return 5

    result = joinall([f, g, h], timeout=1.0)

    assert result == [3, 4, 5]
Exemplo n.º 5
0
 def get_all_events(self,
                    filter_=None,
                    from_block: int = 0,
                    timeout: float = None) -> List[BlockchainEvent]:
     queries = [
         functools.partial(self.get_events,
                           type,
                           filter_=filter_,
                           from_block=from_block)
         for type in self.standard_event_types
     ]
     results = concurrency_utils.joinall(queries, timeout=timeout)
     return sorted_events(list(itertools.chain.from_iterable(results)))
Exemplo n.º 6
0
    def get_exchange_events(
        self,
        event_name: str,
        user_address: str = None,
        from_block: int = 0,
        timeout: float = None,
    ) -> List[BlockchainEvent]:
        logger.debug(
            "get_exchange_events: event_name=%s user_address=%s from_block=%s",
            event_name,
            user_address,
            from_block,
        )
        if user_address is None:
            queries = [
                functools.partial(self.get_events, event_name, from_block=from_block)
            ]
            events = concurrency_utils.joinall(queries, timeout=timeout)
        else:
            filter1 = {from_to_types[event_name][0]: user_address}
            # filter2 = {from_to_types[event_name][1]: user_address}

            queries = [
                functools.partial(self.get_events, event_name, filter1, from_block)
            ]
            # TODO taker attribute of LogFill is not indexed in contract yet
            # if event_name == LogFillEventType:
            #   queries.append(functools.partial(self.get_events, event_name, filter2, from_block))
            results = concurrency_utils.joinall(queries, timeout=timeout)

            events = list(itertools.chain.from_iterable(results))

            for event in events:
                if isinstance(event, ExchangeEvent):
                    event.user = user_address
                else:
                    raise ValueError("Expected a ExchangeEvent")
        return sorted_events(events)
Exemplo n.º 7
0
def test_no_timeout():
    def f():
        return 3

    def g():
        gevent.sleep(0.01)
        return 4

    def h():
        return 5

    result = joinall([f, g, h])

    assert result == [3, 4, 5]
Exemplo n.º 8
0
    def get_events(self,
                   event_name,
                   filter_=None,
                   from_block=0,
                   timeout: float = None) -> List[BlockchainEvent]:
        if event_name not in self.event_builders.keys():
            raise ValueError("Unknown eventname {}".format(event_name))

        if filter_ is None:
            filter_ = {}

        logfilter = getattr(self._proxy.events,
                            event_name).createFilter(fromBlock=from_block,
                                                     toBlock=queryBlock,
                                                     argument_filters=filter_)

        queries = [logfilter.get_all_entries]
        results = concurrency_utils.joinall(queries, timeout=timeout)
        return sorted_events(self._build_events(results[0]))