diff --git a/pyproject.toml b/pyproject.toml index fef7e42..a7cf866 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ exclude_dirs = ["sw_utils/tests/"] [tool.pylint."pre-commit-hook"] disable=["C0103", "C0114", "C0115", "C0116", "R0801", "R0903", "W0703", "W1514", "W0511"] +ignore-paths=["sw_utils/tests/.*"] [tool.pylint."BASIC"] good-names = ["i", "el", "e", "w", "f", "w3"] diff --git a/sw_utils/event_scanner.py b/sw_utils/event_scanner.py index f68f530..9b479ac 100644 --- a/sw_utils/event_scanner.py +++ b/sw_utils/event_scanner.py @@ -58,8 +58,6 @@ def __init__( self._contract_call = lambda from_block, to_block: getattr( processor.contract.events, processor.contract_event ).get_logs(argument_filters=argument_filters, fromBlock=from_block, toBlock=to_block) - # todo: remove type ignore after move Contract wrapper to sw-utils - self.provider = self.processor.contract.contract.w3.provider # type: ignore # Scan in chunks, commit between self.chunk_size = chunk_size or self.max_scan_chunk_size // 2 @@ -99,8 +97,7 @@ async def _scan_chunk( for i in range(retries): to_block = min(last_block, BlockNumber(from_block + self.chunk_size)) try: - with self.provider.disable_retries(): - return to_block, await self._contract_call(from_block, to_block) + return to_block, await self._contract_call(from_block, to_block) except Exception as e: if i < retries - 1: # Decrease the `eth_getBlocks` range diff --git a/sw_utils/tests/test_event_scanner.py b/sw_utils/tests/test_event_scanner.py new file mode 100644 index 0000000..f0a9259 --- /dev/null +++ b/sw_utils/tests/test_event_scanner.py @@ -0,0 +1,41 @@ +import pytest +from eth_typing import BlockNumber +from web3.types import EventData + +from sw_utils.event_scanner import EventProcessor, EventScanner + + +class MockedEventProcessor(EventProcessor): + @staticmethod + async def get_from_block() -> BlockNumber: + return BlockNumber(777) + + @staticmethod + async def process_events(events: list[EventData], to_block: BlockNumber) -> None: + pass + + +async def fetch_events(a, b): + return [] + + +async def fetch_events_broken(a, b): + raise ConnectionError + + +class TestExitSignatureCrud: + async def test_basic(self): + default_chunk_size = 500000 + p = MockedEventProcessor() + s = EventScanner(processor=p) + s._contract_call = fetch_events + assert s.chunk_size == default_chunk_size + + s._contract_call = fetch_events_broken + s.max_request_retries = 1 + with pytest.raises(ConnectionError): + await s.process_new_events(888) + assert s.chunk_size == default_chunk_size / 2 + + await s.process_new_events(888) + assert s.chunk_size == default_chunk_size / 4